From f49ba3b36a05573016c140e2e2e9941e2d10ebb4 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 31 Mar 2022 17:39:12 +0200 Subject: [PATCH 1/4] adding link to view all sessions --- rowers/templates/trainingplan.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rowers/templates/trainingplan.html b/rowers/templates/trainingplan.html index f6a7c73d..47716e5c 100644 --- a/rowers/templates/trainingplan.html +++ b/rowers/templates/trainingplan.html @@ -33,6 +33,9 @@

Edit the plan

{% endif %}

Plan vs Actual chart

+

+ View all sessions +

Plan Macro, Meso and Micro Cycles

From 3c2813c3e3d24daf4b92cd7acb088bd533d55c16 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 7 Apr 2022 08:43:43 +0200 Subject: [PATCH 2/4] logging enabled/disabled thru config --- rowers/tasks.py | 8 +++----- rowers/utils.py | 7 +++++++ rowers/views/importviews.py | 2 +- rowsandall_app/settings.py | 5 +++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/rowers/tasks.py b/rowers/tasks.py index e7c2c299..365dab3a 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -3120,9 +3120,7 @@ def df_from_summary(data): @app.task def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttimezone, debug=False, **kwargs): time.sleep(delaysec) - with open("c2_auto_import.log", "a") as errorlog: - timestr = time.strftime("%Y%m%d-%H%M%S") - errorlog.write(timestr+' '+str(c2id)+' for userid '+str(userid)+'\r\n') + dologging('c2_import.log',str(c2id)+' for userid '+str(userid)) data = alldata[c2id] splitdata = None @@ -3146,8 +3144,8 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim has_strokedata = True s = 'User {userid}, C2 ID {c2id}'.format(userid=userid, c2id=c2id) - dologging('debuglog.log', s) - dologging('debuglog.log', json.dumps(data)) + dologging('c2_import.log', s) + dologging('c2_import.log', json.dumps(data)) try: title = data['name'] diff --git a/rowers/utils.py b/rowers/utils.py index 94b87ccf..ff86496c 100644 --- a/rowers/utils.py +++ b/rowers/utils.py @@ -28,6 +28,8 @@ import iso8601 from iso8601 import ParseError import arrow +from django.conf import settings + lbstoN = 4.44822 landingpages = ( @@ -120,6 +122,11 @@ info_calls = [ def dologging(filename, s): + do_logging = settings.MYLOGGING.get(filename,True) + + if not do_logging: + return + tstamp = time.localtime() timestamp = time.strftime('%b-%d-%Y %H:%M:%S', tstamp) with open(filename, 'a') as f: diff --git a/rowers/views/importviews.py b/rowers/views/importviews.py index 541e7041..b80126d5 100644 --- a/rowers/views/importviews.py +++ b/rowers/views/importviews.py @@ -1576,7 +1576,7 @@ def workout_c2import_view(request, page=1, userid=0, message=""): rower = getrequestrower(request, userid=userid) if rower.user != request.user: messages.error( - request, 'You can only access your own workouts on the NK Logbook, not those of your athletes') + request, 'You can only access your own workouts on the Concept2 Logbook, not those of your athletes') url = reverse('workout_c2import_view', kwargs={ 'userid': request.user.id}) return HttpResponseRedirect(url) diff --git a/rowsandall_app/settings.py b/rowsandall_app/settings.py index c0165729..f95454a1 100644 --- a/rowsandall_app/settings.py +++ b/rowsandall_app/settings.py @@ -589,3 +589,8 @@ except KeyError: # pragma: no cover GEOIP_PATH = STATIC_ROOT TAGGIT_CASE_INSENSITIVE = True + +try: + MYLOGGING = CFG['logging'] +except KeyError: + MYLOGGING = {} From 3590589eb76969883ae941d0295c9f293706ab70 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 7 Apr 2022 09:27:34 +0200 Subject: [PATCH 3/4] fix c2 import --- rowers/dataprep.py | 1 + rowers/tasks.py | 18 +++++++++++------- rowers/views/workoutviews.py | 4 ++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 66f6475f..eb2e3c46 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -2125,6 +2125,7 @@ def new_workout_from_file(r, f2, uploadoptions={'boattype': '1x', 'workouttype': 'rower'}): message = "" + try: fileformat = get_file_type(f2) except (IOError, UnicodeDecodeError): # pragma: no cover diff --git a/rowers/tasks.py b/rowers/tasks.py index 365dab3a..7886c1e3 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -3158,7 +3158,7 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim title = '' # Create CSV file name and save data to CSV file - csvfilename = 'media/{code}_{c2id}.csv'.format( + csvfilename = 'media/{code}_{c2id}.csv.gz'.format( code=uuid4().hex[:16], c2id=c2id) startdatetime, starttime, workoutdate, duration, starttimeunix, timezone = utils.get_startdatetime_from_c2data( @@ -3167,7 +3167,7 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim s = 'Time zone {timezone}, startdatetime {startdatetime}, duration {duration}'.format( timezone=timezone, startdatetime=startdatetime, duration=duration) - dologging('debuglog.log', s) + dologging('c2_import.log', s) authorizationstring = str('Bearer ' + c2token) headers = {'Authorization': authorizationstring, @@ -3180,9 +3180,9 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim return 0 if s.status_code != 200: # pragma: no cover - dologging('debuglog.log', 'No Stroke Data. Status Code {code}'.format( + dologging('c2_import.log', 'No Stroke Data. Status Code {code}'.format( code=s.status_code)) - dologging('debuglog.log', s.text) + dologging('c2_import.log', s.text) has_strokedata = False if not has_strokedata: # pragma: no cover @@ -3192,7 +3192,7 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim try: strokedata = pd.DataFrame.from_dict(s.json()['data']) except AttributeError: # pragma: no cover - dologging('debuglog.log', 'No stroke data in stroke data') + dologging('c2_import.log', 'No stroke data in stroke data') return 0 try: @@ -3200,7 +3200,7 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim cum_time = res[0] lapidx = res[1] except KeyError: # pragma: no cover - dologging('debuglog.log', 'No time values in stroke data') + dologging('c2_import.log', 'No time values in stroke data') return 0 unixtime = cum_time+starttimeunix @@ -3242,7 +3242,7 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim if workouttype == 'bike': # pragma: no cover velo = 1000./pace - dologging('debuglog.log', 'Unix Time Stamp {s}'.format(s=unixtime[0])) + dologging('c2_import.log', 'Unix Time Stamp {s}'.format(s=unixtime[0])) # dologging('debuglog.log',json.dumps(s.json())) df = pd.DataFrame({'TimeStamp (sec)': unixtime, @@ -3270,6 +3270,7 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim _ = df.to_csv(csvfilename, index_label='index', compression='gzip') + uploadoptions = { 'secret': UPLOAD_SERVICE_SECRET, 'user': userid, @@ -3289,6 +3290,9 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim response = session.post(UPLOAD_SERVICE_URL, json=uploadoptions) if response.status_code != 200: # pragma: no cover + dologging('c2_import.log', + 'Upload API returned status code {code}'.format( + code=response.status_code)) return 0 workoutid = response.json()['id'] diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 2cc2cb83..3da4b04f 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -4593,6 +4593,7 @@ def workout_upload_api(request): message = {'status': 'false', 'message': 'invalid credentials'} return JSONResponse(status=403, data=message) + form = DocumentsForm(post_data) optionsform = TeamUploadOptionsForm(post_data) rowerform = TeamInviteForm(post_data) @@ -4613,6 +4614,7 @@ def workout_upload_api(request): message = {'status': 'false', 'message': 'could not find file'} return JSONResponse(status=400, data=message) + # sync related IDs c2id = post_data.get('c2id', '') @@ -4635,6 +4637,7 @@ def workout_upload_api(request): dologging('debuglog.log', s) + r = None if form.is_valid(): t = form.cleaned_data['title'] @@ -4768,6 +4771,7 @@ def workout_upload_api(request): message = form.errors return JSONResponse(status=400, data=message) + message = {'status': 'true', 'id': w.id} statuscode = 200 if fstr: From 2109fe50101373fb015a27feafd686087551b64c Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 7 Apr 2022 09:34:03 +0200 Subject: [PATCH 4/4] n --- rowers/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rowers/utils.py b/rowers/utils.py index ff86496c..4f70f43b 100644 --- a/rowers/utils.py +++ b/rowers/utils.py @@ -123,7 +123,7 @@ info_calls = [ def dologging(filename, s): do_logging = settings.MYLOGGING.get(filename,True) - + if not do_logging: return