Skip to content

Commit

Permalink
Added date filter
Browse files Browse the repository at this point in the history
  • Loading branch information
vloothuis committed Dec 6, 2023
1 parent 6a561d9 commit 6db584d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
Binary file modified public/port-0.0.0-py3-none-any.whl
Binary file not shown.
Binary file modified src/framework/processing/py/dist/port-0.0.0-py3-none-any.whl
Binary file not shown.
4 changes: 4 additions & 0 deletions src/framework/processing/py/port/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import zipfile

ExtractionResult = namedtuple("ExtractionResult", ["id", "title", "data_frame"])
filter_start_date = datetime(2017, 1, 1)


def get_in(dct, *key_path):
Expand Down Expand Up @@ -37,6 +38,9 @@ def parse_json_to_dataframe(parsed_dict):
start_timestamp_str[:-1]
) # remove the 'Z'

if start_timestamp < filter_start_date:
continue

if meters := get_in(segment, "waypointPath", "distanceMeters"):
distance_meters = meters
elif meters := get_in(segment, "simplifiedRawPath", "distanceMeters"):
Expand Down
16 changes: 16 additions & 0 deletions src/framework/processing/py/tests/script_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ def test_parse_json_to_dataframe_skips_non_walking_or_cycling():
assert "DRIVING" not in df.activityType.values


def test_parse_json_to_dataframe_skips_entries_before_filter_date():
parsed_dict= {
"timelineObjects": [
{
"activitySegment": {
"duration": {"startTimestamp": "2016-12-31T19:13:27.023Z"},
"activityType": "CYCLING",
"waypointPath": {"distanceMeters": 3600.33},
}
}
]
}
df = parse_json_to_dataframe(parsed_dict)
assert len(df) == 0


def test_aggregate_distance_by_day_activity(sample_data):
df = parse_json_to_dataframe(sample_data)
aggregated_df = aggregate_distance_by_day_activity(df)
Expand Down

0 comments on commit 6db584d

Please sign in to comment.