Created
June 8, 2024 02:22
-
-
Save ahaxu/59abe25aa56df746fe2cd61e82f153a1 to your computer and use it in GitHub Desktop.
chien-binh-sparta-goya-bao-duong-cung-goya-speed-2024
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
# https://nghienchaybo.com/event/chien-binh-sparta-goya-bao-duong-cung-goya-speed-2024 | |
def f(activities): | |
import math | |
from datetime import datetime | |
act_by_date = dict() | |
for act in activities: | |
start_dt_str = act.get('start_date_local') # 2021-02-12T20:40:00Z | |
end_dt_ts = datetime.strptime(start_dt_str, '%Y-%m-%dT%H:%M:%SZ').timestamp() + act.get('elapsed_time') | |
dt_obj = datetime.fromtimestamp(end_dt_ts) | |
# 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 | |
if km == 0: | |
continue | |
avg_pace = round((1000/act.get('average_speed', 1))/60, 1) | |
gap_time_in_minutes = abs( | |
act.get('elapsed_time', 0) - act.get('moving_time', 0))/60 | |
if act.get('type') == "Run" \ | |
and (4 <= avg_pace <= 10) \ | |
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): | |
a = act_by_date.get(d) | |
print("debug act by date {}: {} {}".format(d, a.get('km'), a.get('id'))) | |
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') >= 1: | |
valid_acts.append(a) | |
return valid_acts | |
acts = f(activities) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated with white list enabled for event with accidentally wrong type.