Last active
June 30, 2023 18:17
-
-
Save rpachos/f44879c274b2abebf626e3ecf0c6852e to your computer and use it in GitHub Desktop.
Cobbling Together Challenge Healing Operations to Observe Calculation
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
from challenge.utils import workout_time_rounding_up | |
from challenge.progress.workout_time.progress import WorkoutTimeProgressFactory | |
from engagement.challenge.challenge_progress_service_client import ChallengeProgressServiceClient | |
from engagement.challenge.challenge_service import ChallengeService | |
from challenge.progress.workout_time.progress_service import WorkoutTimeProgressService | |
from engagement.user.peloton_user import PelotonUserFactory | |
from lib.orm.model import Model | |
challenge_id = '0f858d53-f9e3-4d77-b3d5-5c243abcd38f' | |
user_id = 'cb618556-1487-4e70-8246-5c0bf6ea30f0' | |
# get user and challenge | |
challenge = ChallengeService.get_challenge_by_id(challenge_id) | |
user_model = Model.User.get(user_id) | |
user = PelotonUserFactory.from_record(user_model) | |
# pull out workout events for member/challenge | |
events = ChallengeProgressServiceClient._get_finished_workout_events_during_challenge( | |
challenge, | |
user | |
) | |
# prepare to process workout data | |
metric_type = challenge.metric_type | |
challenge_progress_service = ChallengeProgressServiceClient.get_challenge_progress_service(metric_type) | |
new_progress = WorkoutTimeProgressFactory.create(challenge.id, user.id) | |
new_progress.uncounted = 0 | |
print(f'matching workouts {len(events)}') | |
uncounted_time = 0 | |
# extract WorkoutTimeProgressService method for debugging | |
def local_calculate_add_progress_update(event, progress): | |
if event.end_time and event.start_time: | |
# restrict max watch-time to length of class for non-freestyle rides | |
if event.ride_length: | |
duration = workout_time_rounding_up(event.end_time - event.start_time) | |
time_delta = min(duration, event.ride_length) | |
if duration > event.ride_length: | |
uncounted = (duration - event.ride_length) | |
print(f'restrict max watch-time to length of class for non-freestyle rides {uncounted}') | |
progress.uncounted += uncounted | |
else: | |
time_delta = workout_time_rounding_up(event.end_time - event.start_time) | |
progress.add_workout_time(event.source_id, time_delta) | |
else: | |
print('no start or end time') | |
non_relevant_events = 0 | |
# process workouts | |
for event in events: | |
if not WorkoutTimeProgressService.is_event_relevant(challenge, event): | |
non_relevant_events += 1 | |
continue | |
if event.type == WorkoutTimeProgressService.ADD_PROGRESS_EVENT_TYPE: | |
# WorkoutTimeProgressService._calculate_add_progress_update(event, new_progress) | |
local_calculate_add_progress_update(event, new_progress) | |
elif event.type == WorkoutTimeProgressService.REMOVE_PROGRESS_EVENT_TYPE: | |
print('skipping removal event type') | |
print(f'uncounted time {new_progress.uncounted}') | |
print(f'non_relevant_events {non_relevant_events}') | |
print(f'counted time {new_progress.metric_value}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment