-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import json | ||
import logging | ||
|
||
import dateutil.parser | ||
|
||
from garminexport.garminexport.garminclient import GarminClient | ||
|
||
logging.basicConfig(level=logging.DEBUG, format="%(asctime)-15s [%(levelname)s] %(message)s") | ||
log = logging.getLogger(__name__) | ||
|
||
#with GarminClient('[email protected]', 'password') as client: | ||
# activities = client.get_activities() | ||
with open('../../data/activities.json') as f: | ||
activities = json.loads(f.read()) | ||
log.info("Loading %d activities", len(activities)) | ||
|
||
swim = [] | ||
for activity in activities: | ||
if activity["activityType"]["typeKey"] == 'lap_swimming': | ||
log.info("Found swim activity {}".format(dateutil.parser.parse(activity["startTimeGMT"]).date())) | ||
swim.append(activity) | ||
|
||
log.info(f"Found {len(swim)} swim activities") | ||
|
||
swim_candidates = [] | ||
for activity in activities: | ||
if activity['movingDuration'] is not None and 2400 > activity['movingDuration'] > 1000 and activity[ | ||
'distance'] is not None and 500 < activity['distance'] < 1500: | ||
swim_candidates.append(activity) | ||
log.info(f"Found {len(swim_candidates)} swim candidates") | ||
|
||
mistyped = [] | ||
for activity in swim_candidates: | ||
if activity['activityType']['typeKey'] != 'lap_swimming': | ||
log.info("Found a mistyped swimming activity : {}".format( | ||
dateutil.parser.parse(activity["startTimeGMT"]).date())) | ||
mistyped.append(activity) | ||
|
||
for activity in mistyped: | ||
if activity['activityType']['typeKey'] == 'other': | ||
client.update_activity(activity['activityId'], 'activityTypeDTO', {"typeKey": "lap_swimming"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import json | ||
import logging | ||
from datetime import date | ||
|
||
import dateutil.parser | ||
|
||
logging.basicConfig(level=logging.DEBUG, format="%(asctime)-15s [%(levelname)s] %(message)s") | ||
log = logging.getLogger(__name__) | ||
|
||
# with GarminClient('[email protected]', 'password') as client: | ||
# activities = client.get_activities() | ||
with open('../../data/activities.json') as f: | ||
activities = json.loads(f.read()) | ||
log.info("Loading %d activities", len(activities)) | ||
|
||
duplicates = [] | ||
i: int = 0 | ||
while i < len(activities): | ||
activity_i = activities[i] | ||
activity_i_date: date = dateutil.parser.parse(activity_i["startTimeGMT"]).date() | ||
activity_i_type = activity_i['activityType']['typeKey'] | ||
j: int = len(activities) - 1 | ||
while j > i: | ||
activity_j = activities[j] | ||
activity_j_date: date = dateutil.parser.parse(activity_j["startTimeGMT"]).date() | ||
activity_j_type = activity_j['activityType']['typeKey'] | ||
# Evaluate by date (ignoring hours) | ||
if activity_i_date == activity_j_date and ( | ||
activity_i_type == 'lap_swimming' or activity_j_type == 'lap_swimming'): | ||
duplicates.append([activity_i, activity_j]) | ||
j -= 1 | ||
i += 1 | ||
|
||
log.info(f"Found %d swim duplicates", len(duplicates)) | ||
for activity in duplicates: | ||
log.info("Duplicate at {}".format(dateutil.parser.parse(activity[0]["startTimeGMT"]).date())) |