Created
June 1, 2024 04:45
-
-
Save ahaxu/bf069ff7dd5ef5313dce571a9588e296 to your computer and use it in GitHub Desktop.
htr_mua_he_ruc_ro_2024.py
This file contains hidden or 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
def f(activities): | |
import math | |
from datetime import datetime | |
white_list_acts = [ | |
11448424729, | |
11443873790, | |
11443848827, | |
11442008938, | |
11443899397, | |
11464620113, | |
11378474145, | |
11389006081, | |
11477728529, | |
11438738301, | |
11420288515, | |
11474889245 | |
] | |
act_by_date = dict() | |
for act in activities: | |
dt_str = act.get('start_date_local') # 2021-02-12T20:40:00Z | |
dt_obj = datetime.strptime(dt_str, '%Y-%m-%dT%H:%M:%SZ') | |
# key for ac_by_date dict | |
dt_ymd = int("{}{}{}".format(dt_obj.year, dt_obj.month, dt_obj.day)) | |
km = round(act["distance"] / 1000, 2) | |
if km < 2: | |
continue | |
if act.get('id') in white_list_acts: | |
km_per_block = 1 | |
block = km / km_per_block | |
point = km | |
act["block"] = block | |
act["km"] = km | |
act["point"] = point | |
act_by_date[dt_ymd] = act | |
print("whitelist act id {} - name {}".format(act.get('id'), act.get('name'))) | |
continue | |
if act.get('type') != "Run": | |
continue | |
gap_time_in_minutes = abs( | |
act.get('elapsed_time', 0) - act.get('moving_time', 0)) / 60 | |
if gap_time_in_minutes > 30: | |
print("act_id {}: over 30 mins".format(act.get('id'))) | |
continue | |
# custom for act before 6 7 8 of may | |
# avg pace of tracklog | |
if dt_obj.month == 5 and dt_obj.day in [6, 7, 8]: | |
print('before updated new pace by km rule') | |
avg_pace = round((1000 / act.get('average_speed', 0)) / 60, 1) | |
if 3 <= avg_pace <= 15: | |
km_per_block = 1 | |
block = km / km_per_block | |
point = km | |
act["block"] = block | |
act["km"] = km | |
act["point"] = point | |
print("debug km: {}, block: {}, point: {}".format( | |
km, block, point)) | |
if dt_ymd in act_by_date: | |
if act_by_date.get(dt_ymd).get('km') < km: | |
act_by_date[dt_ymd] = act | |
else: | |
act_by_date[dt_ymd] = act | |
else: | |
print('sync acts for days not in days: 6 7 8 of May') | |
print('act id {} {} {}'.format( | |
act.get('id'), act.get('name'), dt_str)) | |
if act.get('laps') is None or len(act.get("laps")) == 0: | |
print('no laps for this act {}'.format(act.get('id'))) | |
continue | |
valid_pace_dict = dict() | |
for lap in act.get('laps'): | |
print("lap distance {}".format(round(lap.get("distance")/1000, 5))) | |
if round(lap.get("distance")/1000, 5) == 0: | |
print("act id {} - lap id: {} distance is 0".format(act.get('id'), lap.get('id'))) | |
continue | |
if round(lap.get("distance") / 1000) == 1: | |
avg_lap_pace = round((1000 / lap.get('average_speed', 0)) / 60, 2) | |
else: | |
avg_lap_pace = round((round(lap.get("distance")/1000, 1)/lap.get('average_speed', 0))/60, 5) | |
print("act_id {} - avg_lap_pace {} in minutes".format(act.get('id'), avg_lap_pace)) | |
# some watch not correct with lap distance, so we need or condition | |
if (avg_lap_pace <= 12): | |
valid_pace_dict[lap.get('id')] = True | |
print('debug act id {} - len valid_pace_dict: {} - act.get.laps.len {}'.format( | |
act.get('id'), | |
len(valid_pace_dict), | |
len(act.get('laps')))) | |
if len(valid_pace_dict) == len(act.get("laps")): | |
km_per_block = 1 | |
block = km / km_per_block | |
point = km | |
act["block"] = block | |
act["km"] = km | |
act["point"] = point | |
print("debug km: {}, block: {}, point: {}".format( | |
km, block, point)) | |
if dt_ymd in act_by_date: | |
if act_by_date.get(dt_ymd).get('km') < km: | |
act_by_date[dt_ymd] = act | |
else: | |
act_by_date[dt_ymd] = act | |
return list(act_by_date.values()) | |
acts = f(activities) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add black list activity id