Skip to content

Commit

Permalink
Importing...
Browse files Browse the repository at this point in the history
  • Loading branch information
why-not-try-calmer committed Jan 31, 2024
1 parent 0b4fef2 commit 756dfd5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
7 changes: 4 additions & 3 deletions comptages/core/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
from comptages.core.bulk_create_manager import BulkCreateManager


def simple_print_callback(progress):
print(f"Importing... {progress}%")
def simple_print_callback(progress: int):
if progress % 10 == 0:
print(f"Importing... {progress}%")


def import_file(file_path: str, count, callback_progress=simple_print_callback):
Expand Down Expand Up @@ -337,7 +338,7 @@ def _parse_file_header(file_path: str):
elif file_header["CLASS"][:5] == "FHWA ":
file_header["CLASS"] = "FHWA13"
elif file_header["CLASS"] == "CAT-Cycle_dist-empat":
file_header["CLASS"] = "SPCH-MD_5C"
file_header["CLASS"] = "SPCH-MD 5C"

return file_header

Expand Down
2 changes: 1 addition & 1 deletion comptages/core/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ def _remove_useless_sheets(count: models.Count, workbook: Workbook):

for key in to_remove_from_spreadsheet:
try:
workbook.remove_sheet(workbook[key])
workbook.remove(workbook[key])
except KeyError:
continue

Expand Down
8 changes: 6 additions & 2 deletions comptages/datamodel/management/commands/importdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def import_municipalities(self, csv_file):
Municipality.objects.bulk_create(objects)
print(f"Inserted {len(objects)} municipalities.")

def import_count(self, limit: Optional[int] = None):
def import_count(self, limit=50):
section_id = "00107695"
year = 2021
installations = Installation.objects.filter(lane__id_section=section_id)
Expand Down Expand Up @@ -444,7 +444,11 @@ def import_count(self, limit: Optional[int] = None):
files = list(path_to_files.iterdir())

path_to_files = Path("/OpenComptage/test_data/SWISS10_vbv_year")
files = list(path_to_files.iterdir())[:50]

if limit == 0:
files = list(path_to_files.iterdir())
else:
files = list(path_to_files.iterdir())[:limit]

imported = 0
for file in files:
Expand Down
13 changes: 9 additions & 4 deletions comptages/test/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,15 @@ def test_all_sections_default(self):
id_installation=installation,
)

importer.import_file(test_utils.test_data_path("00056520.V01"), count)
importer.import_file(test_utils.test_data_path("00056520.V02"), count)

report.prepare_reports("/tmp/", count)
for file in Path(test_utils.test_data_path(test_data_folder)).iterdir():
importer.import_file(test_utils.test_data_path(str(file)), count)

report.prepare_reports(self.test_outputs, count)
found_files = len(list(Path(self.test_outputs).iterdir()))
# The number of files generated is expected to be: weeks measured x sections
# so let's make sure all sections are considered in the files generation
self.assertGreater(found_files, 0)
self.assertEqual(found_files % n_sections, 0)

def test_busiest_by_season(self):
# Import test data pertaining to "mobilité douce"
Expand Down
2 changes: 1 addition & 1 deletion comptages/test/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def test_get_speed_data_empty(self):
self.assertFalse(statistics.get_speed_data(count, sections[2]).empty)

def test_get_valid_days(self):
call_command("importdata", "--only-count")
call_command("importdata", "--only-count", "--limit=0")
section_id = "00107695"
section = models.Section.objects.get(id=section_id)
# 2021 comes from the call to `importdata --only count`
Expand Down

0 comments on commit 756dfd5

Please sign in to comment.