From ad336aadc43ef5884f08f7181690103649cd8f7d Mon Sep 17 00:00:00 2001 From: why-not-try-calmer Date: Wed, 31 Jan 2024 16:41:12 +0100 Subject: [PATCH] --- --- comptages/core/importer.py | 9 ++++----- comptages/core/report.py | 1 + comptages/core/statistics.py | 1 + comptages/test/test_report.py | 18 ++++++------------ 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/comptages/core/importer.py b/comptages/core/importer.py index 0ae5f96..f73ddcc 100644 --- a/comptages/core/importer.py +++ b/comptages/core/importer.py @@ -1,4 +1,4 @@ -from typing import Callable, Dict, Iterator, List, Optional +from typing import Callable, Iterator, Optional import pytz import os from datetime import datetime, timedelta @@ -61,7 +61,6 @@ def _parse_and_write( with open(file_path, encoding=get_file_encoding(file_path)) as f: for i, line in enumerate(f): rows = line_parser(line, **kwargs) - print("i=", i) if not rows: continue @@ -107,7 +106,7 @@ def _parse_and_write( bulk_mgr.done() -def _parse_line_vbv1(line: str, **kwargs) -> Optional[List[Dict]]: +def _parse_line_vbv1(line: str, **kwargs) -> Optional[list[dict]]: if line.startswith("* "): return None @@ -156,7 +155,7 @@ def _parse_line_vbv1(line: str, **kwargs) -> Optional[List[Dict]]: return [parsed_line] -def _parse_line_mc(line: str, **kwargs) -> Optional[List[Dict]]: +def _parse_line_mc(line: str, **kwargs) -> Optional[list[dict]]: if not line.startswith("20"): return None @@ -193,7 +192,7 @@ def _parse_line_mc(line: str, **kwargs) -> Optional[List[Dict]]: return [parsed_line] -def _parse_line_int2(line, **kwargs) -> Iterator[Optional[Dict]]: +def _parse_line_int2(line, **kwargs) -> Iterator[Optional[dict]]: if line.startswith("* "): return None diff --git a/comptages/core/report.py b/comptages/core/report.py index 2dc3bd7..9a1b4b2 100644 --- a/comptages/core/report.py +++ b/comptages/core/report.py @@ -5,6 +5,7 @@ from datetime import timedelta, datetime from typing import Optional from openpyxl import load_workbook, Workbook +from qgis.core import QgsMessageLog from comptages.core import statistics from comptages.datamodel import models diff --git a/comptages/core/statistics.py b/comptages/core/statistics.py index ed01a8b..d3be379 100644 --- a/comptages/core/statistics.py +++ b/comptages/core/statistics.py @@ -1,5 +1,6 @@ from typing import Any import pandas as pd +from functools import reduce from datetime import timedelta, datetime from django.db.models import F, CharField, Value, Q, Sum, QuerySet diff --git a/comptages/test/test_report.py b/comptages/test/test_report.py index 3044ddf..2baf259 100644 --- a/comptages/test/test_report.py +++ b/comptages/test/test_report.py @@ -100,7 +100,7 @@ def test_busiest_by_season(self): id_installation=installation, ) - path_to_file = Path("/OpenComptage/comptages/test/test_data").joinpath( + path_to_file = Path("/test_data").joinpath( "64540060_Latenium_PS2021_ChMixte.txt" ) importer.import_file(str(path_to_file), count) @@ -121,9 +121,7 @@ def inspect_leaves(d, res) -> list[int]: # Prepare workbook path_to_inputs = Path("comptages/report").joinpath("template_yearly_bike.xlsx") - path_to_outputs = Path("/OpenComptage/test_outputs").joinpath( - "yearly_bike.xlsx" - ) + path_to_outputs = Path("/test_outputs").joinpath("yearly_bike.xlsx") wb = load_workbook(path_to_inputs) # Write data & save @@ -161,7 +159,7 @@ def test_busiest_by_day_month(self): id_installation=installation, ) - path_to_file = Path("/OpenComptage/comptages/test/test_data").joinpath( + path_to_file = Path("/test_data").joinpath( "64540060_Latenium_PS2021_ChMixte.txt" ) importer.import_file(str(path_to_file), count) @@ -172,9 +170,7 @@ def test_busiest_by_day_month(self): # Prepare workbook path_to_inputs = Path("comptages/report").joinpath("template_yearly_bike.xlsx") - path_to_outputs = Path("/OpenComptage/test_outputs").joinpath( - "yearly_bike.xlsx" - ) + path_to_outputs = Path("/test_outputs").joinpath("yearly_bike.xlsx") wb = load_workbook(path_to_inputs) # Write data & save @@ -209,7 +205,7 @@ def test_busiest_by_various_criteria(self): id_installation=installation, ) - path_to_file = Path("/OpenComptage/comptages/test/test_data").joinpath( + path_to_file = Path("/test_data").joinpath( "64540060_Latenium_PS2021_ChMixte.txt" ) importer.import_file(str(path_to_file), count) @@ -220,9 +216,7 @@ def test_busiest_by_various_criteria(self): # Prepare workbook path_to_inputs = Path("comptages/report").joinpath("template_yearly_bike.xlsx") - path_to_outputs = Path("/OpenComptage/test_outputs").joinpath( - "yearly_bike.xlsx" - ) + path_to_outputs = Path("/test_outputs").joinpath("yearly_bike.xlsx") wb = load_workbook(path_to_inputs) # Write data & save