Exemplo n.º 1
0
def get_laps(activity_id):
    global calls
    calls += 1
    for lap in client.get_activity_laps(activity_id):
        distance = str(lap.distance).split()[0]
        lap.distance_miles = dec(convert_distance(dec(distance), 'metre', 'mile'))
        lap.distance_km = dec(convert_distance(dec(distance), 'metre', 'km'))
        yield lap
Exemplo n.º 2
0
def get_activities(afterdate, beforedate):
    global calls
    calls += 1
    for activity in client.get_activities(after=afterdate, before=beforedate):
        distance = str(activity.distance).split()[0]
        activity.distance_miles = dec(convert_distance(dec(distance), 'metre', 'mile'))
        activity.distance_km = dec(convert_distance(dec(distance), 'metre', 'km'))
        activity.gear_name = activity_gear(activity.gear_id)
        yield activity
Exemplo n.º 3
0
 def get_laps(self, activity_id):
     for lap in self._client.get_activity_laps(activity_id):
         distance = str(lap.distance).split()[0]
         lap.distance_miles = dec(
             convert_distance(dec(distance), 'metre', 'mile'))
         lap.distance_km = dec(
             convert_distance(dec(distance), 'metre', 'km'))
         lap.pace_mile = calculate_pace(lap.moving_time, lap.distance_miles,
                                        'mile')
         lap.pace_km = calculate_pace(lap.moving_time, lap.distance_km,
                                      'km')
         lap.speed_mile = calculate_speed(lap.distance_miles,
                                          lap.moving_time)
         lap.speed_km = calculate_speed(lap.distance_km, lap.moving_time)
         yield lap
Exemplo n.º 4
0
    def create_step(self, workout_type, run_target, run_duration_type,
                    run_duration, run_duration_unit):
        """Creates the step for a workout."""
        # Create targets
        if run_target == 'pace':
            run_pace = int(self.get_paces_att(workout_type, 'Pace'))
            target_value_low = calculate_metres_per_sec(
                datetime.timedelta(seconds=run_pace), self.units)
            target_value_high = calculate_metres_per_sec(
                datetime.timedelta(seconds=run_pace - pace_add), self.units)
            targets = self.get_pace_targets(target_value_high,
                                            target_value_low)
        elif run_target == 'hr':
            target_value_low = dec(
                (dec(self.get_paces_att(workout_type, 'HRZoneLow'), 2) *
                 dec(self.max_hr, 0)) + 100, 0, 'ROUND_FLOOR')
            target_value_high = dec(
                (dec(self.get_paces_att(workout_type, 'HRZoneHigh'), 2) *
                 dec(self.max_hr, 0)) + 100, 0, 'ROUND_CEILING')
            targets = self.get_hr_targets(target_value_high, target_value_low)
        else:  # run_target == 'none':
            targets = self.get_open_targets()

        # Create duration
        if run_duration_type == 'distance':
            if run_duration_unit != 'metre':
                run_duration = convert_distance(run_duration,
                                                run_duration_unit, 'metre')
            durations = self.get_distance_durations(run_duration)
        elif run_duration_type == 'time':
            durations = self.get_time_durations(run_duration)
        else:  # run_duration_type == 'none':
            durations = self.get_open_durations()

        return WorkOutStep('Run', durations, targets, 0)
Exemplo n.º 5
0
 def get_activities(self, before=None, after=None):
     for activity in self._client.get_activities(after=after,
                                                 before=before):
         distance = str(activity.distance).split()[0]
         activity.distance_miles = dec(
             convert_distance(dec(distance), 'metre', 'mile'))
         activity.distance_km = dec(
             convert_distance(dec(distance), 'metre', 'km'))
         activity.pace_mile = calculate_pace(activity.moving_time,
                                             activity.distance_miles,
                                             'mile')
         activity.pace_km = calculate_pace(activity.moving_time,
                                           activity.distance_km, 'km')
         activity.speed_mile = calculate_speed(activity.distance_miles,
                                               activity.moving_time)
         activity.speed_km = calculate_speed(activity.distance_km,
                                             activity.moving_time)
         yield activity
Exemplo n.º 6
0
 def format_duration(self, duration):
     """Formats the duration of workout."""
     if type(duration) == list:  # List is for distance based
         duration_type = 'distance'
         duration_value = dec(duration[0], 2)
         duration_unit = duration[1]
         if duration_unit != 'metre' and duration_unit != self.units:
             duration_value = convert_distance(duration_value,
                                               duration_unit, self.units)
     elif duration:
         duration_type = 'time'
         duration_value = convert_to_time(duration).total_seconds()
         duration_unit = None
     else:
         duration_type = 'none'
         duration_value = None
         duration_unit = None
     return duration_type, duration_value, duration_unit
Exemplo n.º 7
0
from collections import OrderedDict
from settings.converters import convert_to_time, calculate_pace, time_to_string, convert_distance, dec


distances = {
    '1,500': [dec('1.5', 1), convert_distance(dec('1.5', 1), 'km', 'mile')],
    'Mile': [convert_distance(dec('1', 0), 'mile', 'km'), dec('1', 0)],
    '3,000': [dec('3', 0), convert_distance(dec('3', 0), 'km', 'mile')],
    '2mile': [convert_distance(dec('2', 0), 'mile', 'km'), dec('2', 0)],
    '5,000': [dec('5', 0), convert_distance(dec('5', 0), 'km', 'mile')],
    '10K': [dec('10', 0), convert_distance(dec('10', 0), 'km', 'mile')],
    '15K': [dec('15', 0), convert_distance(dec('15', 0), 'km', 'mile')],
    '10Mile': [convert_distance(dec('10', 2), 'mile', 'km'), dec('10', 0)],
    'HalfMarathon': [convert_distance(dec('13.11', 2), 'mile', 'km'), dec('13.11', 2)],
    'Marathon': [convert_distance(dec('26.22', 2), 'mile', 'km'), dec('26.22', 2)]
}

def get_vdot_race_paces(file):
    """Extracts the race paces from the VDOT Races file."""
    vdot = OrderedDict()
    headers = []
    with open(file, 'r') as VDOT_file:
        for line in VDOT_file.readlines():
            cells = line.split()  # Ignore last column as this is repeated.
            if cells[0] == 'VDOT':
                headers += cells[1:]
            else:
                cell_times = [x for x in cells[1:]]
                vdot[int(cells[0])] = dict(zip(headers, cell_times))

    return vdot
Exemplo n.º 8
0
threshold_time = convert_to_time('00:18:00')
threshold_pace = convert_to_time('00:07:00')

rest_time = convert_to_time('00:08:00')
rest_pace = convert_to_time('00:09:00')

rest_distance = dec(rest_time.total_seconds() / rest_pace.total_seconds(), 2)

distance = dec(threshold_time.total_seconds() / threshold_pace.total_seconds(),
               2)

print(distance)
print(rest_distance)

intervals = (1500 * 3) + (1200 * 3)  #+ (800)
metres = convert_distance(intervals, 'metre', 'mile')
miles = dec('1.5', 1)
miles += dec('1.5', 1)

print(distance + miles + rest_distance)

settings.WORKOUT_PLANS = 'template\\plans\\'
settings.WORKOUT_TEMPLATES = 'template\\workout templates.json'

plan = settings.db.get_plan_schedule('Half Marathon 47 Miles')
templates = settings.db.get_workouts()

#for k, v in sorted([(int(k),v) for k,v in plan.items()]):
#    print(k, v)

print(len(templates.index.values))