Skip to content

Instantly share code, notes, and snippets.

@ahaxu
Last active March 10, 2024 03:35
Show Gist options
  • Save ahaxu/194a295bd76578ef37b63e97f281227e to your computer and use it in GitHub Desktop.
Save ahaxu/194a295bd76578ef37b63e97f281227e to your computer and use it in GitHub Desktop.
HTMT tho xay challenge 2024
def f(activities, team):
import math
from datetime import datetime
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 = math.floor(act["distance"]/1000)
point = 0
block = 0
avg_pace = round((1000/act.get('average_speed', 0))/60, 1)
gap_time_in_minutes = abs(
act.get('elapsed_time', 0) - act.get('moving_time', 0))/60
if act.get('type') == "Run" \
and (3 <= avg_pace <= 11) \
and gap_time_in_minutes <= 30:
km_per_block = 1
point_per_block = 1
block = math.floor(km/km_per_block)
point = block * point_per_block
if point > 0:
act["block"] = block
act["km"] = km
act["point"] = 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
valid_acts = []
for d in sorted(act_by_date):
print("debug act by date {}".format(d))
a = act_by_date.get(d)
if len(valid_acts) == 0:
valid_acts.append(a)
else:
last_valid_act = valid_acts[-1]
if a.get('km') >= last_valid_act.get('km'):
valid_acts.append(a)
return valid_acts
acts = f(activities, team)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment