44from os .path import join
55from typing import Optional
66
7+ import numpy as np
78import pandas as pd
89
910def create_export_csv (
1011 df : pd .DataFrame ,
1112 export_dir : str ,
1213 geo_res : str ,
1314 sensor : str ,
15+ metric : Optional [str ] = None ,
1416 start_date : Optional [datetime ] = None ,
15- metric : Optional [str ] = None
17+ end_date : Optional [datetime ] = None
1618):
1719 """Export data in the format expected by the Delphi API.
1820
@@ -26,18 +28,24 @@ def create_export_csv(
2628 Geographic resolution to which the data has been aggregated
2729 sensor: str
2830 Sensor that has been calculated (cumulative_counts vs new_counts)
29- start_date: Optional[datetime]
30- Earliest date to export. If None, all dates are exported.
3131 metric: Optional[str]
32- Metric we are considering, if any
32+ Metric we are considering, if any.
33+ start_date: Optional[datetime]
34+ Earliest date to export or None if no minimum date restrictions should be applied.
35+ end_date: Optional[datetime]
36+ Latest date to export or None if no maximum date restrictions should be applied.
3337 """
3438 df = df .copy ()
3539
3640 df ["timestamp" ] = pd .to_datetime (df ["timestamp" ])
3741 if start_date is None :
3842 start_date = min (df ["timestamp" ])
43+ if end_date is None :
44+ end_date = max (df ["timestamp" ])
45+
3946 dates = pd .Series (
40- df [df ["timestamp" ] >= start_date ]["timestamp" ].unique ()
47+ df [np .logical_and (df ["timestamp" ] >= start_date ,
48+ df ["timestamp" ] <= end_date )]["timestamp" ].unique ()
4149 ).sort_values ()
4250
4351 for date in dates :
0 commit comments