Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete all HERE IML features when refreshing data #92

Merged
merged 4 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions API/swagger_client/models/summary_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Strava API # noqa: E501

OpenAPI spec version: 3.0.0

Generated by: https://github.com/swagger-api/swagger-codegen.git
"""

Expand Down Expand Up @@ -189,7 +189,7 @@ def activity_type(self, activity_type):
:param activity_type: The activity_type of this SummarySegment. # noqa: E501
:type: str
"""
allowed_values = ["Ride", "Run", "Hike", "AlpineSki"] # noqa: E501
allowed_values = ["Ride", "Run", "Hike", "AlpineSki", "VirtualRide", "WaterSport"] # noqa: E501
if activity_type not in allowed_values:
raise ValueError(
"Invalid value for `activity_type` ({0}), must be one of {1}" # noqa: E501
Expand Down
31 changes: 28 additions & 3 deletions here_xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

# Standard library
import geojson
import json
import pathlib
import sys

Expand All @@ -22,6 +21,7 @@

HERE_CATALOG_ID = "strava-analysis-tool"
HERE_LAYER_ID = "strava-activity-data"
HERE_FEATURE_IDS_CHUNK_SIZE = 100


def _get_here_iml(here_creds_file_path: pathlib.Path) -> IML:
Expand Down Expand Up @@ -83,7 +83,8 @@ def _get_here_iml(here_creds_file_path: pathlib.Path) -> IML:
return iml


def upload_geo_data(geo_data_file_path: pathlib.Path, here_creds_file_path: pathlib.Path):
def upload_geo_data(geo_data_file_path: pathlib.Path, here_creds_file_path: pathlib.Path,
refresh: bool):
"""
Upload the geospatial activity data to an interactive mapping layer (IML)
on the HERE platform. This layer can be used by the map created in HERE
Expand All @@ -94,15 +95,39 @@ def upload_geo_data(geo_data_file_path: pathlib.Path, here_creds_file_path: path
data in GeoJSON format.
here_creds_file_path - Path of the file containing the HERE platform
credentials.
refresh - Delete the existing activity data from the IML and upload a fresh
copy.
"""

# Get a HERE IML object for the Strava Analysis Tool layer
iml = _get_here_iml(here_creds_file_path=here_creds_file_path)

if refresh:
# Get a list of all uploaded activities (features) in the IML
feature_collection = iml.layer.search_features(params={"id=gte": "0"}).to_geojson()

# Create a list of feature IDs and split it into chunks
feature_ids = []
for feature in feature_collection['features']:
feature_ids.append(feature['id'])

feature_ids_chunks = ([feature_ids[i:i + HERE_FEATURE_IDS_CHUNK_SIZE] for i in
range(0, len(feature_ids), HERE_FEATURE_IDS_CHUNK_SIZE)])

print("[HERE] Deleting all existing activities from the HERE "
"interactive map layer")

for chunk in feature_ids_chunks:
# Delete the uploaded activities in the IML in chunks
iml.layer.delete_features(chunk)

# Read the contents of the geo data file
with geo_data_file_path.open('r', encoding='utf-8') as geo_data_file:
geo_data = geojson.load(geo_data_file)

if geo_data:
# Upload all the data
print(f"[HERE] Uploading activities from '{geo_data_file_path}' to "
"the HERE interactive map layer")

# Upload all the activities in the file
iml.layer.write_features(features=geo_data)
3 changes: 2 additions & 1 deletion strava_analysis_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def main():
# Upload the geospatial data to HERE
here_xyz.upload_geo_data(
geo_data_file_path=pathlib.Path(config['paths']['geo_data_file']),
here_creds_file_path=pathlib.Path(config['paths']['here_creds_file'])
here_creds_file_path=pathlib.Path(config['paths']['here_creds_file']),
refresh=args.refresh_data
)

if args.activity_count_plot:
Expand Down