Private
Public Access
1
0
This commit is contained in:
Sander Roosendaal
2022-02-17 15:16:27 +01:00
parent e9c13d3fe7
commit a547e851be
16 changed files with 133 additions and 166 deletions

View File

@@ -16,14 +16,11 @@ import datetime
import json
import time
from fitparse import FitFile
from django.conf import settings
from django.http import HttpResponse
import requests
from django.http import HttpResponse
import humanize
from pytz.exceptions import UnknownTimeZoneError
import pytz
@@ -189,7 +186,6 @@ palettes = {
'gold_sunset': (47, -31, .26, -0.12, 0.94, -0.5),
'blue_red': (207, -200, .85, 0, .74, -.24),
'blue_green': (207, -120, .85, 0, .75, .25),
'cyan_green': (192, -50, .08, .65, .98, -.34),
'cyan_purple': trcolors(237, 248, 251, 136, 65, 157),
'green_blue': trcolors(240, 249, 232, 8, 104, 172),
'orange_red': trcolors(254, 240, 217, 179, 0, 0),
@@ -237,7 +233,8 @@ def str2bool(v): # pragma: no cover
def uniqify(seq, idfun=None):
# order preserving
if idfun is None:
def idfun(x): return x
def idfun(x):
return x
seen = {}
result = []
for item in seq:
@@ -465,14 +462,14 @@ def totaltime_sec_to_string(totaltime, shorten=False):
hours=hours,
minutes=minutes,
seconds=seconds,
tenths=tenths
# tenths=tenths
)
else:
duration = "{minutes}:{seconds:02d}".format(
hours=hours,
# hours=hours,
minutes=minutes,
seconds=seconds,
tenths=tenths
# tenths=tenths
)
return duration
@@ -559,12 +556,12 @@ def get_strava_stream(r, metric, stravaid, series_type='time', fetchresolution='
if metric == 'power': # pragma: no cover
metric = 'watts'
url = "https://www.strava.com/api/v3/activities/{stravaid}/streams/{metric}?resolution={fetchresolution}&series_type={series_type}".format(
stravaid=stravaid,
fetchresolution=fetchresolution,
series_type=series_type,
metric=metric
)
url = "https://www.strava.com/api/v3/activities/{stravaid}" \
"/streams/{metric}?resolution={fetchresolution}&series_type={series_type}".format(
stravaid=stravaid,
fetchresolution=fetchresolution,
series_type=series_type,
metric=metric)
s = requests.get(url, headers=headers)
@@ -574,7 +571,6 @@ def get_strava_stream(r, metric, stravaid, series_type='time', fetchresolution='
try:
for data in s.json():
y = None
try:
if data['type'] == metric:
return np.array(data['data'])
@@ -790,14 +786,14 @@ def get_step_type(step): # pragma: no cover
return t
def peel(l):
if len(l) == 0: # pragma: no cover
def peel(listToPeel):
if len(listToPeel) == 0: # pragma: no cover
return None, None
if len(l) == 1:
return l[0], None
if len(listToPeel) == 1:
return listToPeel[0], None
first = l[0]
rest = l[1:]
first = listToPeel[0]
rest = listToPeel[1:]
if first['type'] == 'Step': # pragma: no cover
return first, rest
@@ -944,7 +940,7 @@ def step_to_string(step, short=False):
repeatValue = 1
nr = 0
name = ''
intensity = ''
duration = ''
unit = ''
@@ -954,7 +950,11 @@ def step_to_string(step, short=False):
durationtype = step['durationType']
if step['durationValue'] == 0:
if durationtype not in ['RepeatUntilStepsCmplt', 'RepeatUntilHrLessThan', 'RepeatUntilHrGreaterThan']: # pragma: no cover
if durationtype not in [
'RepeatUntilStepsCmplt',
'RepeatUntilHrLessThan',
'RepeatUntilHrGreaterThan'
]: # pragma: no cover
return '', type, -1, -1, 1
if durationtype == 'Time':
@@ -963,7 +963,6 @@ def step_to_string(step, short=False):
if value/1000. >= 3600: # pragma: no cover
unit = 'h'
dd = timedelta(seconds=value/1000.)
#duration = humanize.naturaldelta(dd, minimum_unit="seconds")
duration = '{v}'.format(v=str(dd))
elif durationtype == 'Distance':
unit = 'm'
@@ -1163,7 +1162,7 @@ def step_to_string(step, short=False):
nr = step['stepId']
name = step['wkt_step_name']
# name = step['wkt_step_name']
notes = ''
try:
@@ -1178,10 +1177,10 @@ def step_to_string(step, short=False):
intensity = 0
s = '{duration} {unit} {target} {repeat} {notes}'.format(
nr=nr,
name=name,
# nr=nr,
# name=name,
unit=unit,
intensity=intensity,
# intensity=intensity,
duration=duration,
target=target,
repeat=repeat,