Private
Public Access
1
0

fixes in rp3, performance chart

This commit is contained in:
Sander Roosendaal
2023-01-18 19:43:32 +01:00
parent 22385d606f
commit b5d1090f6a
5 changed files with 47 additions and 13 deletions

View File

@@ -1214,7 +1214,12 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
delta = datetime.timedelta(
seconds=totaltime)
workoutenddatetime = workoutstartdatetime+delta
try:
workoutenddatetime = workoutstartdatetime+delta
except AttributeError as e:
workoutstartdatetime = pendulum.parse(str(workoutstartdatetime))
workoutenddatetime = workoutstartdatetime+delta
# check for duplicate start times and duration
duplicate = checkduplicates(

View File

@@ -67,6 +67,7 @@ from rowers.models import (
)
import pytz
from pytz.exceptions import UnknownTimeZoneError
import collections
import pendulum
from rowingdata import rowingdata as rrdata
@@ -915,6 +916,12 @@ parsers = {
def get_startdate_time_zone(r, row, startdatetime=None):
if isinstance(startdatetime, str):
try:
startdatetime = pendulum.parse(startdatetime)
except:
dologging('debuglog.log','Could not parse start date time '+startdatetime)
if startdatetime is not None and startdatetime != '':
try:
timezone_str = pendulum.instance(startdatetime).timezone.name
@@ -969,7 +976,10 @@ def get_startdate_time_zone(r, row, startdatetime=None):
else:
timezone_str = str(startdatetime.tzinfo)
startdatetime = startdatetime.astimezone(pytz.timezone(timezone_str))
try:
startdatetime = startdatetime.astimezone(pytz.timezone(timezone_str))
except UnknownTimeZoneError:
startdatetime = startdatetime.astimezone(pytz.utc)
startdate = startdatetime.strftime('%Y-%m-%d')
starttime = startdatetime.strftime('%H:%M:%S')

View File

@@ -1524,16 +1524,16 @@ def getfatigues(
for w in ws:
if getattr(w, metricchoice) > 0:
weight += getattr(w, metricchoice)
if getattr(w, metricchoice) <= 0:
if getattr(w, metricchoice) == 0:
if metricchoice == 'rscore' and w.hrtss > 0: # pragma: no cover
weight += w.hrtss
else:
trimp, hrtss = dataprep.workout_trimp(w)
rscore, normp = dataprep.workout_rscore(w)
if w.rpe and w.rpe > 0: # pragma: no cover
dd = 3600*w.duration.hour+60*w.duration.minute+w.duration.second
dd = dd/3600
weight += rpetotss[w.rpe]*dd
if getattr(w, metricchoice) < 0:
trimp, hrtss = dataprep.workout_trimp(w)
rscore, normp = dataprep.workout_rscore(w)
if w.rpe and w.rpe > 0: # pragma: no cover
dd = 3600*w.duration.hour+60*w.duration.minute+w.duration.second
dd = dd/3600
weight += rpetotss[w.rpe]*dd
impulses.append(weight)

View File

@@ -9,13 +9,15 @@ from rowsandall_app.settings import (
RP3_CLIENT_ID, RP3_CLIENT_KEY, RP3_REDIRECT_URI, RP3_CLIENT_SECRET,
UPLOAD_SERVICE_URL, UPLOAD_SERVICE_SECRET
)
from rowers.utils import myqueue
from rowers.utils import myqueue, NoTokenError
# All the functionality needed to connect to Runkeeper
from rowers.imports import *
# Python
import gzip
from datetime import timedelta
import base64
from io import BytesIO
@@ -48,6 +50,11 @@ graphql_url = "https://rp3rowing-app.com/graphql"
# Checks if user has UnderArmour token, renews them if they are expired
def rp3_open(user):
tokenexpirydate = user.rower.rp3tokenexpirydate
if timezone.now()-timedelta(days=120)>tokenexpirydate:
user.rower.rp3tokenexpirydate = timezone.now()-timedelta(days=1)
user.rower.save()
raise NoTokenError
return imports_open(user, oauth_data)
# Refresh ST token using refresh token
@@ -137,8 +144,12 @@ def get_rp3_workouts(rower, do_async=True): # pragma: no cover
w.uploadedtorp3 for w in Workout.objects.filter(user=rower)
])
dologging('rp3_import.log',rp3ids)
newids = [rp3id for rp3id in rp3ids if rp3id not in knownrp3ids]
dologging('rp3_import.log',newids)
for id in newids:
startdatetime = workouts_list.loc[id, 'executed_at']
dologging('rp3_import.log', startdatetime)
@@ -150,7 +161,7 @@ def get_rp3_workouts(rower, do_async=True): # pragma: no cover
auth_token,
id,
startdatetime,
10,
20,
)
return 1

View File

@@ -2967,6 +2967,7 @@ def handle_rp3_async_workout(userid, rp3token, rp3id, startdatetime, max_attempt
headers=headers,
json={'query': get_download_link}
)
dologging('rp3_import.log',response.status_code)
if response.status_code != 200: # pragma: no cover
have_link = True
@@ -2974,6 +2975,7 @@ def handle_rp3_async_workout(userid, rp3token, rp3id, startdatetime, max_attempt
try:
workout_download_details = pd.json_normalize(
response.json()['data']['download'])
dologging('rp3_import.log', response.json())
except: # pragma: no cover
return 0
@@ -2981,8 +2983,12 @@ def handle_rp3_async_workout(userid, rp3token, rp3id, startdatetime, max_attempt
download_url = workout_download_details.iat[0, 2]
have_link = True
dologging('rp3_import.log', download_url)
counter += 1
dologging('rp3_import.log', counter)
if counter > max_attempts: # pragma: no cover
have_link = True
@@ -2994,6 +3000,8 @@ def handle_rp3_async_workout(userid, rp3token, rp3id, startdatetime, max_attempt
filename = 'media/RP3Import_'+str(rp3id)+'.csv'
res = requests.get(download_url, headers=headers)
dologging('rp3_import.log','tasks.py '+str(rp3id))
dologging('rp3_import.log',startdatetime)
if not startdatetime: # pragma: no cover
startdatetime = str(timezone.now())