Skip to content

Commit 9af0d37

Browse files
authored
fix: publication year data (#2890)
1 parent 3677339 commit 9af0d37

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

packages/api/egapro/constants.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
}
1313

1414
# Always let the comment for us to switch between enabled read current year or not
15-
PUBLIC_YEARS = YEARS
16-
# PUBLIC_YEARS = [2018, 2019, 2020, 2021, 2022]
17-
PUBLIC_YEARS_REPEQ = YEARS_REPEQ
18-
# PUBLIC_YEARS_REPEQ = [2021, 2022]
15+
# PUBLIC_YEARS = YEARS
16+
PUBLIC_YEARS = [2018, 2019, 2020, 2021, 2022, 2023, 2024]
17+
# PUBLIC_YEARS_REPEQ = YEARS_REPEQ
18+
PUBLIC_YEARS_REPEQ = [2021, 2022, 2023, 2024]
1919

2020
REGIONS = {
2121
"01": "Guadeloupe",

packages/api/egapro/csv_representation.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE
99
from progressist import ProgressBar
1010

11-
from egapro import config, constants, db
11+
from egapro import config, constants, db, sql
1212
from egapro.utils import flatten, remove_one_year
1313

1414

@@ -55,7 +55,10 @@ async def as_xlsx(max_rows=None, debug=False):
5555
:debug: Turn on debug to be able to read the generated Workbook
5656
"""
5757
print("Reading from DB")
58-
records = await db.representation_equilibree.all()
58+
records = await db.representation_equilibree.fetch(
59+
f"SELECT * FROM {db.representation_equilibree.table_name} WHERE year = ANY($1::int[])",
60+
constants.PUBLIC_YEARS_REPEQ
61+
)
5962
print("Flattening JSON")
6063
if max_rows:
6164
records = records[:max_rows]

packages/api/egapro/exporter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def public_data(path: Path):
3636
:path: chemin vers le fichier d'export
3737
"""
3838

39-
records = await db.declaration.fetch(sql.public_declarations)
39+
records = await db.declaration.fetch(sql.public_declarations, constants.PUBLIC_YEARS)
4040
writer = csv.writer(path, delimiter=";")
4141
writer.writerow(
4242
[
@@ -141,7 +141,7 @@ async def public_data_as_xlsx(debug=False):
141141
"""
142142

143143
print("Reading from DB")
144-
records = await db.declaration.fetch(sql.public_declarations)
144+
records = await db.declaration.fetch(sql.public_declarations, constants.PUBLIC_YEARS)
145145
workbook = Workbook(write_only=not debug)
146146
sheet: Union[WriteOnlyWorksheet, Worksheet] = workbook.create_sheet()
147147
sheet.title = "Données publiques Index Egapro"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SELECT data FROM declaration JOIN search ON declaration.siren=search.siren AND declaration.year=search.year
1+
SELECT data FROM declaration JOIN search ON declaration.siren=search.siren AND declaration.year=search.year WHERE declaration.year = ANY($1::int[])

0 commit comments

Comments
 (0)