From 337e0ff558db59d9773288b6d4c33573ce3f5059 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 17 Feb 2022 18:01:26 +0100 Subject: [PATCH] more oppeppers --- rowers/tasks.py | 700 +++++++++++++++++++----------------------------- 1 file changed, 272 insertions(+), 428 deletions(-) diff --git a/rowers/tasks.py b/rowers/tasks.py index 171f2b66..f39f0abe 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -39,8 +39,6 @@ from rowingdata import rowingdata as rdata from datetime import timedelta from sqlalchemy import create_engine - -#from celery import app from rowers.celery import app from celery import shared_task @@ -53,7 +51,7 @@ from json.decoder import JSONDecodeError from pytz.exceptions import UnknownTimeZoneError from matplotlib.backends.backend_agg import FigureCanvas -#from matplotlib.backends.backend_cairo import FigureCanvasCairo as FigureCanvas + import matplotlib.pyplot as plt from matplotlib import path @@ -86,10 +84,9 @@ from rowers import mytypes from rowers.dataprepnodjango import ( - update_strokedata, getsmallrowdata_db, updatecpdata_sql, update_c2id_sql, update_workout_field_sql, - update_agegroup_db, + update_agegroup_db, update_strokedata, add_c2_stroke_data_db, totaltime_sec_to_string, create_c2_stroke_data_db, update_empower, database_url_debug, database_url, dataprep, @@ -319,7 +316,7 @@ def handle_sporttracks_sync(workoutid, url, headers, data, debug=False, **kwargs id = int(m) - res = update_workout_field_sql( + _ = update_workout_field_sql( workoutid, 'uploadedtosporttracks', id, debug=debug) return 1 @@ -375,7 +372,7 @@ def handle_strava_sync(stravatoken, workoutid, filename, name, activity_type, de failed = True if not failed: - result = update_workout_field_sql( + _ = update_workout_field_sql( workoutid, 'uploadedtostrava', res.id, debug=debug) try: act = client.update_activity(res.id, activity_type=activity_type, @@ -426,7 +423,7 @@ def handle_c2_import_stroke_data(c2token, s = requests.get(url, headers=headers) if s.status_code == 200: strokedata = pd.DataFrame.from_dict(s.json()['data']) - result = add_c2_stroke_data_db( + _ = add_c2_stroke_data_db( strokedata, workoutid, starttimeunix, csvfilename, debug=debug, workouttype=workouttype ) @@ -443,30 +440,12 @@ def handle_c2_import_stroke_data(c2token, distance = workoutdata['distance'] c2id = workoutdata['id'] workouttype = workoutdata['type'] - verified = workoutdata['verified'] - startdatetime = iso8601.parse_date(workoutdata['date']) - weightclass = workoutdata['weight_class'] - weightcategory = 'hwt' - if weightclass == "L": - weightcategory = 'lwt' totaltime = workoutdata['time']/10. duration = totaltime_sec_to_string(totaltime) duration = datetime.datetime.strptime( duration, '%H:%M:%S.%f').time() - try: - timezone_str = workoutdata['timezone'] - except: - timezone_str = 'UTC' - - workoutdate = startdatetime.astimezone( - pytz.timezone(timezone_str) - ).strftime('%Y-%m-%d') - starttime = startdatetime.astimezone( - pytz.timezone(timezone_str) - ).strftime('%H:%M:%S') - - result = create_c2_stroke_data_db( + _ = create_c2_stroke_data_db( distance, duration, workouttype, workoutid, starttimeunix, csvfilename, debug=debug, @@ -499,11 +478,12 @@ def getagegrouprecord(age, sex='male', weightcategory='hwt', ages = df['age'] powers = df['power'] - #poly_coefficients = np.polyfit(ages,powers,6) - def fitfunc(pars, x): return np.abs(pars[0])*(1-x/max(120, pars[1]))-np.abs( - pars[2])*np.exp(-x/np.abs(pars[3]))+np.abs(pars[4])*(np.sin(np.pi*x/max(50, pars[5]))) + def fitfunc(pars, x): + return np.abs(pars[0])*(1-x/max(120, pars[1]))-np.abs( + pars[2])*np.exp(-x/np.abs(pars[3]))+np.abs(pars[4])*(np.sin(np.pi*x/max(50, pars[5]))) - def errfunc(pars, x, y): return fitfunc(pars, x)-y + def errfunc(pars, x, y): + return fitfunc(pars, x)-y p0 = [700, 120, 700, 10, 100, 100] @@ -512,15 +492,8 @@ def getagegrouprecord(age, sex='male', weightcategory='hwt', if success and age is not None: power = fitfunc(p1, float(age)) - - #power = np.polyval(poly_coefficients,age) - power = 0.5*(np.abs(power)+power) elif age is not None: # pragma: no cover - new_age = np.range([age]) - ww = griddata(ages.values, - powers.values, - new_age, method='linear', rescale=True) power = 0.5*(np.abs(power)+power) else: # pragma: no cover power = 0 @@ -530,9 +503,8 @@ def getagegrouprecord(age, sex='male', weightcategory='hwt', def polygon_to_path(polygon, debug=True): pid = polygon[0] - query = "SELECT id, latitude, longitude FROM rowers_geopoint WHERE polygon_id = {pid} ORDER BY order_in_poly ASC".format( - pid=pid - ) + query = "SELECT id, latitude, longitude FROM rowers_geopoint WHERE polygon_id = {pid}'\ + ' ORDER BY order_in_poly ASC".format(pid=pid) if debug: engine = create_engine(database_url_debug, echo=False) else: # pragma: no cover @@ -595,8 +567,6 @@ def handle_check_race_course(self, if 'successemail' in kwargs: successemail = kwargs['successemail'] - columns = ['time', ' latitude', ' longitude', 'cum_dist'] - try: row = rdata(csvfile=f1) except IOError: # pragma: no cover @@ -617,7 +587,7 @@ def handle_check_race_course(self, rowdata['cum_dist'] = rowdata['gps_dist_calculated'] try: - s = rowdata[' latitude'] + _ = rowdata[' latitude'] except KeyError: # pragma: no cover return 0 @@ -690,7 +660,6 @@ def handle_check_race_course(self, except InvalidTrajectoryError: # pragma: no cover entrytimes = [] - entrydistances = [] coursecompleted = False coursemeters = 0 coursetimeseconds = 0 @@ -742,19 +711,15 @@ def handle_check_race_course(self, 'endsecond': endseconds, }) - records = records[records['coursecompleted'] == True] + records = records[records['coursecompleted'] is True] if len(records): coursecompleted = True mintime = records['coursetimeseconds'].min() - coursetimeseconds = records[records['coursetimeseconds'] - == mintime]['coursetimeseconds'].min() - coursemeters = records[records['coursetimeseconds'] - == mintime]['coursemeters'].min() - startsecond = records[records['coursetimeseconds'] - == mintime]['startsecond'].min() - endsecond = records[records['coursetimeseconds'] - == mintime]['endsecond'].min() + coursetimeseconds = records[records['coursetimeseconds'] == mintime]['coursetimeseconds'].min() + coursemeters = records[records['coursetimeseconds'] == mintime]['coursemeters'].min() + startsecond = records[records['coursetimeseconds'] == mintime]['startsecond'].min() + endsecond = records[records['coursetimeseconds'] == mintime]['endsecond'].min() else: # pragma: no cover coursecompleted = False @@ -764,26 +729,30 @@ def handle_check_race_course(self, coursedistance = coursemeters velo = coursedistance/coursetimeseconds points = 100*(2.-referencespeed/velo) - query = 'UPDATE rowers_virtualraceresult SET coursecompleted = 1, duration = "{duration}", distance = {distance}, workoutid = {workoutid}, startsecond = {startsecond}, endsecond = {endsecond}, points={points} WHERE id={recordid}'.format( - recordid=recordid, - duration=totaltime_sec_to_string(coursetimeseconds), - distance=int(coursemeters), - points=points, - workoutid=workoutid, - startsecond=startsecond, - endsecond=endsecond, - ) + query = 'UPDATE rowers_virtualraceresult SET coursecompleted = 1,'\ + ' duration = "{duration}", distance = {distance},'\ + ' workoutid = {workoutid}, startsecond = {startsecond},'\ + ' endsecond = {endsecond}, points={points} WHERE id={recordid}'.format( + recordid=recordid, + duration=totaltime_sec_to_string(coursetimeseconds), + distance=int(coursemeters), + points=points, + workoutid=workoutid, + startsecond=startsecond, + endsecond=endsecond,) if mode == 'coursetest': - query = 'UPDATE rowers_coursetestresult SET coursecompleted = 1, duration = "{duration}", distance = {distance}, workoutid = {workoutid}, startsecond = {startsecond}, endsecond = {endsecond}, points={points} WHERE id={recordid}'.format( - recordid=recordid, - duration=totaltime_sec_to_string(coursetimeseconds), - distance=int(coursemeters), - points=points, - workoutid=workoutid, - startsecond=startsecond, - endsecond=endsecond, - ) + query = 'UPDATE rowers_coursetestresult SET coursecompleted = 1,'\ + ' duration = "{duration}", distance = {distance},'\ + ' workoutid = {workoutid}, startsecond = {startsecond},'\ + ' endsecond = {endsecond}, points={points} WHERE id={recordid}'.format( + recordid=recordid, + duration=totaltime_sec_to_string(coursetimeseconds), + distance=int(coursemeters), + points=points, + workoutid=workoutid, + startsecond=startsecond, + endsecond=endsecond,) with engine.connect() as conn, conn.begin(): result = conn.execute(query) @@ -828,26 +797,30 @@ def handle_check_race_course(self, return 1 else: # pragma: no cover - query = 'UPDATE rowers_virtualraceresult SET coursecompleted = 0, duration = "{duration}", distance = {distance}, workoutid = {workoutid}, startsecond = {startsecond}, endsecond = {endsecond}, points={points} WHERE id={recordid}'.format( - recordid=recordid, - duration=totaltime_sec_to_string(0), - distance=0, - points=0.0, - workoutid=workoutid, - startsecond=startsecond, - endsecond=endsecond, - ) + query = 'UPDATE rowers_virtualraceresult SET coursecompleted = 0,'\ + ' duration = "{duration}", distance = {distance},'\ + ' workoutid = {workoutid}, startsecond = {startsecond},'\ + ' endsecond = {endsecond}, points={points} WHERE id={recordid}'.format( + recordid=recordid, + duration=totaltime_sec_to_string(0), + distance=0, + points=0.0, + workoutid=workoutid, + startsecond=startsecond, + endsecond=endsecond,) if mode == 'coursetest': - query = 'UPDATE rowers_coursetestresult SET coursecompleted = 0, duration = "{duration}", distance = {distance}, workoutid = {workoutid}, startsecond = {startsecond}, endsecond = {endsecond}, points={points} WHERE id={recordid}'.format( - recordid=recordid, - duration=totaltime_sec_to_string(0), - distance=0, - points=0, - workoutid=workoutid, - startsecond=startsecond, - endsecond=endsecond, - ) + query = 'UPDATE rowers_coursetestresult SET coursecompleted = 0,'\ + ' duration = "{duration}", distance = {distance}, workoutid = {workoutid}'\ + ', startsecond = {startsecond}, endsecond = {endsecond}'\ + ', points={points} WHERE id={recordid}'.format( + recordid=recordid, + duration=totaltime_sec_to_string(0), + distance=0, + points=0, + workoutid=workoutid, + startsecond=startsecond, + endsecond=endsecond,) with engine.connect() as conn, conn.begin(): result = conn.execute(query) @@ -986,24 +959,24 @@ def handle_get_garmin_file(client_id, session = requests.session() newHeaders = {'Content-type': 'application/json', 'Accept': 'text/plain'} session.headers.update(newHeaders) - response = session.post(UPLOAD_SERVICE_URL, json=uploadoptions) + _ = session.post(UPLOAD_SERVICE_URL, json=uploadoptions) return 1 @app.task(bind=True) -def long_test_task(self, aantal, debug=False, job=None, session_key=None): # pragma: no cover - job = self.request +def long_test_task(self, aantal, debug=False, myjob=None, session_key=None): # pragma: no cover + myjob = self.request - return longtask.longtask(aantal, jobid=job.id, debug=debug, + return longtask.longtask(aantal, jobid=myjob.id, debug=debug, session_key=session_key) @app.task(bind=True) def long_test_task2(self, aantal, **kwargs): # pragma: no cover # debug=False,job=None,jobid='aap'): - job = self.request - job_id = job.id + myjob = self.request + job_id = myjob.id if 'jobkey' in kwargs: job_id = kwargs.pop('jobkey') @@ -1021,8 +994,8 @@ def handle_update_empower(self, workoutdicts, debug=False, **kwargs): # pragma: no cover - job = self.request - job_id = job.id + myjob = self.request + job_id = myjob.id if 'jobkey' in kwargs: job_id = kwargs.pop('jobkey') @@ -1052,10 +1025,10 @@ def handle_update_empower(self, havedata = 0 progressurl = SITE_URL - siteurl = SITE_URL + if debug: progressurl = SITE_URL_DEV - siteurl = SITE_URL_DEV + # siteurl = SITE_URL_DEV secret = PROGRESS_CACHE_SECRET kwargs['job_id'] = job_id @@ -1064,8 +1037,8 @@ def handle_update_empower(self, progressurl += job_id if havedata: - success = update_empower(wid, inboard, oarlength, boattype, - rowdata.df, f1, debug=debug) + _ = update_empower(wid, inboard, oarlength, boattype, + rowdata.df, f1, debug=debug) counter += 1 @@ -1076,8 +1049,7 @@ def handle_update_empower(self, "value": progress, } - s = requests.post(progressurl, data=post_data) - status_code = s.status_code + _ = requests.post(progressurl, data=post_data) subject = "Rowsandall.com Your Old Empower Oarlock data have been corrected" message = """ @@ -1094,7 +1066,7 @@ We have updated Power and Work per Stroke data according to the instructions by emailbounced = False if not emailbounced: - res = email.send() + _ = email.send() return 1 @@ -1199,18 +1171,19 @@ def handle_calctrimp(id, if hrtss > 1000: # pragma: no cover hrtss = 0 - query = 'UPDATE rowers_workout SET rscore = {tss}, normp = {normp}, trimp={trimp}, hrtss={hrtss}, normv={normv}, normw={normw} WHERE id={id}'.format( - tss=int(tss), - normp=int(normp), - trimp=int(trimp), - hrtss=int(hrtss), - normv=normv, - normw=normw, - id=id, - ) + query = 'UPDATE rowers_workout SET rscore = {tss},'\ + ' normp = {normp}, trimp={trimp}, hrtss={hrtss},'\ + ' normv={normv}, normw={normw} WHERE id={id}'.format( + tss=int(tss), + normp=int(normp), + trimp=int(trimp), + hrtss=int(hrtss), + normv=normv, + normw=normw, + id=id,) with engine.connect() as conn, conn.begin(): - result = conn.execute(query) + _ = conn.execute(query) conn.close() engine.dispose() @@ -1248,7 +1221,7 @@ def handle_updatedps(useremail, workoutids, debug=False, **kwargs): emailbounced = False if not emailbounced: - res = email.send() + _ = email.send() return 1 @@ -1275,11 +1248,6 @@ def sigdig(value, digits=3): def handle_send_email_alert( useremail, userfirstname, userlastname, rowerfirstname, alertname, stats, **kwargs): - if 'debug' in kwargs: # pragma: no cover - debug = kwargs['debug'] - else: - debug = False - if 'othertexts' in kwargs: # pragma: no cover othertexts = kwargs['othertexts'] else: @@ -1334,9 +1302,9 @@ def handle_send_email_alert( 'othertexts': othertexts, } - res = send_template_email(from_email, [useremail], subject, - 'alertemail.html', - d, **kwargs) + _ = send_template_email(from_email, [useremail], subject, + 'alertemail.html', + d, **kwargs) return 1 @@ -1345,11 +1313,6 @@ def handle_send_email_alert( def handle_send_email_transaction( username, useremail, amount, **kwargs): - if 'debug' in kwargs: # pragma: no cover - debug = kwargs['debug'] - else: - debug = True - subject = "Rowsandall Payment Confirmation" from_email = 'Rowsandall ' @@ -1360,10 +1323,10 @@ def handle_send_email_transaction( 'amount': amount, } - res = send_template_email(from_email, [useremail], - subject, - 'paymentconfirmationemail.html', - d, **kwargs) + _ = send_template_email(from_email, [useremail], + subject, + 'paymentconfirmationemail.html', + d, **kwargs) return 1 @@ -1373,11 +1336,6 @@ def handle_send_email_instantplan_notification( username, useremail, amount, planname, startdate, enddate, **kwargs ): # pragma: no cover - if 'debug' in kwargs: # pragma: no cover - debug = kwargs['debug'] - else: - debug = True - subject = "Rowsandall Instant Plan Notification" from_email = 'Rowsandall ' @@ -1391,10 +1349,10 @@ def handle_send_email_instantplan_notification( 'enddate': enddate, } - res = send_template_email(from_email, ['roosendaalsander@gmail.com'], - subject, - 'instantplansold.html', - d, **kwargs) + _ = send_template_email(from_email, ['roosendaalsander@gmail.com'], + subject, + 'instantplansold.html', + d, **kwargs) return 1 @@ -1403,11 +1361,6 @@ def handle_send_email_instantplan_notification( def handle_send_email_failed_cancel( name, email, username, id, **kwargs): - if 'debug' in kwargs: # pragma: no cover - debug = kwargs['debug'] - else: - debug = True - subject = "Rowsandall Subscription Cancellation Error" from_email = 'Rowsandall ' @@ -1420,10 +1373,10 @@ def handle_send_email_failed_cancel( 'id': id, } - res = send_template_email(from_email, ["support@rowsandall.com"], - subject, - 'cancel_subscription_fail_email.html', - d, **kwargs) + _ = send_template_email(from_email, ["support@rowsandall.com"], + subject, + 'cancel_subscription_fail_email.html', + d, **kwargs) return 1 @@ -1433,11 +1386,6 @@ def handle_send_email_subscription_update( username, useremail, planname, recurring, price, amount, end_of_billing_period, method, **kwargs): - if 'debug' in kwargs: # pragma: no cover - debug = kwargs['debug'] - else: - debug = True - from_email = 'Rowsandall ' d = { @@ -1459,15 +1407,15 @@ def handle_send_email_subscription_update( notification_template_name = 'subscription_update_notification.html' subject = "Rowsandall Payment Confirmation" - res = send_template_email(from_email, [useremail], - subject, - template_name, - d, **kwargs) + _ = send_template_email(from_email, [useremail], + subject, + template_name, + d, **kwargs) - res = send_template_email(from_email, ['info@rowsandall.com'], - 'Subscription Update Notification', - notification_template_name, - d, **kwargs) + _ = send_template_email(from_email, ['info@rowsandall.com'], + 'Subscription Update Notification', + notification_template_name, + d, **kwargs) return 1 @@ -1477,11 +1425,6 @@ def handle_send_email_subscription_create( username, useremail, planname, recurring, price, amount, end_of_billing_period, **kwargs): - if 'debug' in kwargs: # pragma: no cover - debug = kwargs['debug'] - else: - debug = True - subject = "Rowsandall Payment Confirmation" from_email = 'Rowsandall ' @@ -1496,15 +1439,15 @@ def handle_send_email_subscription_create( 'recurring': recurring, } - res = send_template_email(from_email, [useremail], - subject, - 'subscription_create_email.html', - d, **kwargs) + _ = send_template_email(from_email, [useremail], + subject, + 'subscription_create_email.html', + d, **kwargs) - res = send_template_email(from_email, ['info@rowsandall.com'], - 'Subscription Update Notification', - 'subscription_create_notification.html', - d, **kwargs) + _ = send_template_email(from_email, ['info@rowsandall.com'], + 'Subscription Update Notification', + 'subscription_create_notification.html', + d, **kwargs) return 1 @@ -1512,11 +1455,6 @@ def handle_send_email_subscription_create( def handle_sendemail_raceregistration( useremail, username, registeredname, racename, raceid, **kwargs): - if 'debug' in kwargs: # pragma: no cover - debug = kwargs['debug'] - else: - debug = True - subject = "A new competitor has registered for virtual challenge {n}".format( n=racename ) @@ -1531,21 +1469,15 @@ def handle_sendemail_raceregistration( 'raceid': raceid, } - res = send_template_email(from_email, [useremail], - subject, - 'raceregisteredemail.html', - d, **kwargs) + _ = send_template_email(from_email, [useremail], + subject, + 'raceregisteredemail.html', + d, **kwargs) return 1 -def handle_sendemail_coursesucceed( - useremail, username, logfile, workoutid, **kwargs -): # pragma: no cover - if 'debug' in kwargs: # pragma: no cover - debug = kwargs['debug'] - else: - debug = True +def handle_sendemail_coursesucceed(useremail, username, logfile, workoutid, **kwargs): # pragma: no cover subject = "The validation of your course has succeeded" @@ -1556,12 +1488,12 @@ def handle_sendemail_coursesucceed( 'workoutid': encoder.encode_hex(workoutid), } - res = send_template_email(from_email, [useremail], - subject, - 'trajectorysuccessemail.html', - d, - attach_file=logfile, - **kwargs) + _ = send_template_email(from_email, [useremail], + subject, + 'trajectorysuccessemail.html', + d, + attach_file=logfile, + **kwargs) return 1 @@ -1569,11 +1501,6 @@ def handle_sendemail_coursesucceed( def handle_sendemail_coursefail( useremail, username, logfile, **kwargs): - if 'debug' in kwargs: # pragma: no cover - debug = kwargs['debug'] - else: - debug = True - subject = "The validation of your course has failed" from_email = 'Rowsandall ' @@ -1582,13 +1509,13 @@ def handle_sendemail_coursefail( 'username': username, } - res = send_template_email(from_email, [useremail], - subject, - 'trajectoryfailemail.html', - d, - cc=['info@rowsandall.com'], - attach_file=logfile, - **kwargs) + _ = send_template_email(from_email, [useremail], + subject, + 'trajectoryfailemail.html', + d, + cc=['info@rowsandall.com'], + attach_file=logfile, + **kwargs) return 1 @@ -1597,11 +1524,6 @@ def handle_sendemail_coursefail( def handle_sendemail_optout( useremail, username, registeredname, racename, raceid, **kwargs): - if 'debug' in kwargs: # pragma: no cover - debug = kwargs['debug'] - else: - debug = True - subject = "{name} has opted out from social media posts around challenge {n}".format( n=racename, name=registeredname @@ -1617,10 +1539,10 @@ def handle_sendemail_optout( 'raceid': raceid, } - res = send_template_email(from_email, [useremail], - subject, - 'raceoptoutsocialmedia.html', - d, **kwargs) + _ = send_template_email(from_email, [useremail], + subject, + 'raceoptoutsocialmedia.html', + d, **kwargs) return 1 @@ -1629,11 +1551,6 @@ def handle_sendemail_optout( def handle_sendemail_racesubmission( useremail, username, registeredname, racename, raceid, **kwargs): - if 'debug' in kwargs: # pragma: no cover - debug = kwargs['debug'] - else: - debug = True - subject = "A new result has been submitted for virtual challenge {n}".format( n=racename ) @@ -1648,10 +1565,10 @@ def handle_sendemail_racesubmission( 'raceid': raceid, } - res = send_template_email(from_email, [useremail], - subject, - 'racesubmissionemail.html', - d, **kwargs) + _ = send_template_email(from_email, [useremail], + subject, + 'racesubmissionemail.html', + d, **kwargs) return 1 @@ -1660,11 +1577,6 @@ def handle_sendemail_racesubmission( def handle_send_disqualification_email( useremail, username, reason, message, racename, **kwargs): - if 'debug' in kwargs: # pragma: no cover - debug = kwargs['debug'] - else: - debug = True - subject = "Your result for {n} has been disqualified on rowsandall.com".format( n=racename ) @@ -1679,10 +1591,10 @@ def handle_send_disqualification_email( 'racename': racename, } - res = send_template_email(from_email, [useremail], - subject, - 'disqualificationemail.html', - d, **kwargs) + _ = send_template_email(from_email, [useremail], + subject, + 'disqualificationemail.html', + d, **kwargs) return 1 @@ -1691,11 +1603,6 @@ def handle_send_disqualification_email( def handle_send_withdraw_email( useremail, username, reason, message, racename, **kwargs): - if 'debug' in kwargs: # pragma: no cover - debug = kwargs['debug'] - else: - debug = True - subject = "Your result for {n} has been removed on rowsandall.com".format( n=racename ) @@ -1710,10 +1617,10 @@ def handle_send_withdraw_email( 'racename': racename, } - res = send_template_email(from_email, [useremail], - subject, - 'withdraw_email.html', - d, **kwargs) + _ = send_template_email(from_email, [useremail], + subject, + 'withdraw_email.html', + d, **kwargs) return 1 @@ -1721,11 +1628,6 @@ def handle_send_withdraw_email( @app.task def handle_sendemail_expired(useremail, userfirstname, userlastname, expireddate, **kwargs): - if 'debug' in kwargs: # pragma: no cover - debug = kwargs['debug'] - else: - debug = False - subject = "Your rowsandall.com paid account has expired" from_email = 'Rowsandall ' @@ -1736,9 +1638,9 @@ def handle_sendemail_expired(useremail, userfirstname, userlastname, expireddate 'expireddate': expireddate, } - res = send_template_email(from_email, [useremail], - subject, 'accountexpiredemail.html', - d, cc=['support@rowsandall.com'], **kwargs) + _ = send_template_email(from_email, [useremail], + subject, 'accountexpiredemail.html', + d, cc=['support@rowsandall.com'], **kwargs) return 1 @@ -1748,11 +1650,6 @@ def handle_sendemail_breakthrough(workoutid, useremail, btvalues=pd.DataFrame().to_json(), **kwargs): - if 'debug' in kwargs: # pragma: no cover - debug = kwargs['debug'] - else: - debug = False - btvalues = pd.read_json(btvalues) btvalues.sort_values('delta', axis=0, inplace=True) @@ -1774,9 +1671,9 @@ def handle_sendemail_breakthrough(workoutid, useremail, 'btvalues': tablevalues, } - res = send_template_email(from_email, [useremail], - subject, 'breakthroughemail.html', - d, **kwargs) + _ = send_template_email(from_email, [useremail], + subject, 'breakthroughemail.html', + d, **kwargs) return 1 @@ -1789,11 +1686,6 @@ def handle_sendemail_hard(workoutid, useremail, btvalues=pd.DataFrame().to_json(), debug=False, **kwargs): - if 'debug' in kwargs: # pragma: no cover - debug = kwargs['debug'] - else: - debug = False - btvalues = pd.read_json(btvalues) btvalues.sort_values('delta', axis=0, inplace=True) @@ -1815,8 +1707,8 @@ def handle_sendemail_hard(workoutid, useremail, 'btvalues': tablevalues, } - res = send_template_email(from_email, [useremail], - subject, 'hardemail.html', d, **kwargs) + _ = send_template_email(from_email, [useremail], + subject, 'hardemail.html', d, **kwargs) return 1 @@ -1841,7 +1733,7 @@ def handle_sendemail_userdeleted(name, email, debug=False, **kwargs): emailbounced = False if not emailbounced: - res = email.send() + _ = email.send() return 1 @@ -1856,7 +1748,8 @@ def handle_sendemail_unrecognized(unrecognizedfile, useremail, fullemail = 'roosendaalsander@gmail.com' subject = "Unrecognized file from Rowsandall.com" message = "Dear Sander,\n\n" - message += "Please find attached a file that someone tried to upload to rowsandall.com. The file was not recognized as a valid file type.\n\n" + message += "Please find attached a file that someone tried to upload to rowsandall.com." + message += " The file was not recognized as a valid file type.\n\n" message += "User Email " + useremail + "\n\n" message += "Best Regards, the Rowsandall Team" @@ -1875,7 +1768,7 @@ def handle_sendemail_unrecognized(unrecognizedfile, useremail, emailbounced = False if not emailbounced: - res = email.send() + _ = email.send() # remove tcx file try: @@ -1902,9 +1795,9 @@ def handle_sendemail_unrecognizedowner(useremail, userfirstname, from_email = 'Rowsandall ' - res = send_template_email(from_email, [fullemail], - subject, 'unrecognizedemail.html', d, - **kwargs) + _ = send_template_email(from_email, [fullemail], + subject, 'unrecognizedemail.html', d, + **kwargs) return 1 @@ -1921,9 +1814,9 @@ def handle_sendemailics(first_name, last_name, email, icsfile, **kwargs): from_email = 'Rowsandall ' - res = send_template_email(from_email, [fullemail], - subject, 'icsemail.html', d, - attach_file=icsfile, **kwargs) + _ = send_template_email(from_email, [fullemail], + subject, 'icsemail.html', d, + attach_file=icsfile, **kwargs) os.remove(icsfile) return 1 @@ -1942,9 +1835,9 @@ def handle_sendemailkml(first_name, last_name, email, kmlfile, **kwargs): from_email = 'Rowsandall ' - res = send_template_email(from_email, [fullemail], - subject, 'kmlemail.html', d, - attach_file=kmlfile, **kwargs) + _ = send_template_email(from_email, [fullemail], + subject, 'kmlemail.html', d, + attach_file=kmlfile, **kwargs) os.remove(kmlfile) return 1 @@ -1965,9 +1858,9 @@ def handle_sendemailtcx(first_name, last_name, email, tcxfile, **kwargs): from_email = 'Rowsandall ' - res = send_template_email(from_email, [fullemail], - subject, 'tcxemail.html', d, - attach_file=tcxfile, **kwargs) + _ = send_template_email(from_email, [fullemail], + subject, 'tcxemail.html', d, + attach_file=tcxfile, **kwargs) os.remove(tcxfile) return 1 @@ -1991,7 +1884,7 @@ def handle_zip_file(emailfrom, subject, file, **kwargs): # pragma: no cover if debug: print("attaching") - res = email.send() + _ = email.send() if debug: print("sent") @@ -2012,10 +1905,10 @@ def handle_sendemailsummary(first_name, last_name, email, csvfile, **kwargs): from_email = 'Rowsandall ' - res = send_template_email(from_email, [fullemail], - subject, 'summarymail.html', d, - attach_file=csvfile, - **kwargs) + _ = send_template_email(from_email, [fullemail], + subject, 'summarymail.html', d, + attach_file=csvfile, + **kwargs) try: os.remove(csvfile) @@ -2024,8 +1917,6 @@ def handle_sendemailsummary(first_name, last_name, email, csvfile, **kwargs): return 1 -#from rowers.emails import sendemail - @app.task def handle_sendemailcsv(first_name, last_name, email, csvfile, **kwargs): @@ -2040,9 +1931,9 @@ def handle_sendemailcsv(first_name, last_name, email, csvfile, **kwargs): from_email = 'Rowsandall ' - res = send_template_email(from_email, [fullemail], - subject, 'csvemail.html', d, - attach_file=csvfile, **kwargs) + _ = send_template_email(from_email, [fullemail], + subject, 'csvemail.html', d, + attach_file=csvfile, **kwargs) return 1 @@ -2060,7 +1951,7 @@ def handle_sendemail_ical(first_name, last_name, email, url, icsfile, **kwargs): siteurl = SITE_URL if debug: # pragma: no cover - progressurl = SITE_URL_DEV + # progressurl = SITE_URL_DEV siteurl = SITE_URL_DEV d = {'first_name': first_name, @@ -2070,12 +1961,12 @@ def handle_sendemail_ical(first_name, last_name, email, url, icsfile, **kwargs): from_email = 'Rowsandall ' - res = send_template_email(from_email, [fullemail], - subject, 'icsemail.html', d, - attach_file=icsfile, **kwargs) + _ = send_template_email(from_email, [fullemail], + subject, 'icsemail.html', d, + attach_file=icsfile, **kwargs) try: - os.remove(csvfile) + os.remove(icsfile) except: pass @@ -2095,9 +1986,9 @@ def handle_sendemailfile(first_name, last_name, email, csvfile, **kwargs): from_email = 'Rowsandall ' - res = send_template_email(from_email, [fullemail], - subject, 'fileemail.html', d, - attach_file=csvfile, **kwargs) + _ = send_template_email(from_email, [fullemail], + subject, 'fileemail.html', d, + attach_file=csvfile, **kwargs) if 'delete' in kwargs: # pragma: no cover dodelete = kwargs['delete'] @@ -2120,8 +2011,8 @@ def handle_otwsetpower(self, f1, boattype, boatclass, coastalbrand, weightvalue, first_name, last_name, email, workoutid, **kwargs): - job = self.request - job_id = job.id + myjob = self.request + job_id = myjob.id if 'jobkey' in kwargs: job_id = kwargs.pop('jobkey') @@ -2237,7 +2128,6 @@ def handle_otwsetpower(self, f1, boattype, boatclass, coastalbrand, weightvalue, dfgrouped = df.groupby(['workoutid']) delta, cpvalues, avgpower = datautils.getcp(dfgrouped, logarr) - #delta,cpvalues,avgpower = datautils.getsinglecp(rowdata.df) res, btvalues, res2 = utils.isbreakthrough( delta, cpvalues, ps[0], ps[1], ps[2], ps[3], ratio) if res: # pragma: no cover @@ -2256,9 +2146,9 @@ def handle_otwsetpower(self, f1, boattype, boatclass, coastalbrand, weightvalue, 'workoutid': encoder.encode_hex(workoutid), } - res = send_template_email(from_email, [fullemail], - subject, 'otwpoweremail.html', d, - **kwargs) + _ = send_template_email(from_email, [fullemail], + subject, 'otwpoweremail.html', d, + **kwargs) return 1 @@ -2418,11 +2308,11 @@ def handle_sendemail_coachrequest(email, name, code, coachname, 'siteurl': siteurl } - form_email = 'Rowsandall ' + from_email = 'Rowsandall ' - res = send_template_email(from_email, [fullemail], - subject, 'coachrequestemail.html', d, - **kwargs) + _ = send_template_email(from_email, [fullemail], + subject, 'coachrequestemail.html', d, + **kwargs) return 1 @@ -2445,10 +2335,10 @@ def handle_sendemail_coachoffer_rejected(coachemail, coachname, name, 'siteurl': siteurl, } - res = send_template_email(from_email, [fullemail], - subject, 'coachofferrejectedemail.html', - d, - **kwargs) + _ = send_template_email(from_email, [fullemail], + subject, 'coachofferrejectedemail.html', + d, + **kwargs) return 1 @@ -2470,10 +2360,10 @@ def handle_sendemail_coachrequest_rejected(email, coachname, name, 'siteurl': siteurl, } - res = send_template_email(from_email, [fullemail], - subject, 'coachrequestrejectedemail.html', - d, - **kwargs) + _ = send_template_email(from_email, [fullemail], + subject, 'coachrequestrejectedemail.html', + d, + **kwargs) return 1 @@ -2495,10 +2385,10 @@ def handle_sendemail_coachrequest_accepted(email, coachname, name, 'siteurl': siteurl, } - res = send_template_email(from_email, [fullemail], - subject, 'coachrequestacceptedemail.html', - d, - **kwargs) + _ = send_template_email(from_email, [fullemail], + subject, 'coachrequestacceptedemail.html', + d, + **kwargs) return 1 @@ -2520,10 +2410,10 @@ def handle_sendemail_coachoffer_accepted(coachemail, coachname, name, 'siteurl': siteurl, } - res = send_template_email(from_email, [fullemail], - subject, 'coachofferacceptedemail.html', - d, - **kwargs) + _ = send_template_email(from_email, [fullemail], + subject, 'coachofferacceptedemail.html', + d, + **kwargs) return 1 @@ -2546,9 +2436,9 @@ def handle_sendemail_coacheerequest(email, name, code, coachname, 'siteurl': siteurl } - res = send_template_email(from_email, [fullemail], - subject, 'coacheerequestemail.html', d, - **kwargs) + _ = send_template_email(from_email, [fullemail], + subject, 'coacheerequestemail.html', d, + **kwargs) return 1 @@ -2573,9 +2463,9 @@ def handle_sendemail_invite(email, name, code, teamname, manager, from_email = 'Rowsandall ' - res = send_template_email(from_email, [fullemail], - subject, 'teaminviteemail.html', d, - **kwargs) + _ = send_template_email(from_email, [fullemail], + subject, 'teaminviteemail.html', d, + **kwargs) return 1 @@ -2620,9 +2510,9 @@ def handle_sendemailnewresponse(first_name, last_name, 'commentlink': commentlink, } - res = send_template_email(from_email, - [fullemail], - subject, 'teamresponseemail.html', d, **kwargs) + _ = send_template_email(from_email, + [fullemail], + subject, 'teamresponseemail.html', d, **kwargs) return 1 @@ -2668,8 +2558,8 @@ def handle_sendemailnewcomment(first_name, 'commentlink': commentlink, } - res = send_template_email(from_email, [fullemail], subject, - 'teamresponseemail.html', d, **kwargs) + _ = send_template_email(from_email, [fullemail], subject, + 'teamresponseemail.html', d, **kwargs) return 1 @@ -2684,9 +2574,9 @@ def handle_send_template_email(template, email, fromemail, rowername, 'rowername': rowername, } - res = send_template_email('Rowsandall ', - ['info@rowsandall.com'], subject, - template, d, cc=[fromemail], bcc=fullemail, **kwargs) + _ = send_template_email('Rowsandall ', + ['info@rowsandall.com'], subject, + template, d, cc=[fromemail], bcc=fullemail, **kwargs) return 1 @@ -2706,8 +2596,8 @@ def handle_sendemail_message(email, fromemail, rowername, message, teamname, man 'message': message, } - res = send_template_email(from_email, [fullemail], subject, - 'teammessage.html', d, **kwargs) + _ = send_template_email(from_email, [fullemail], subject, + 'teammessage.html', d, **kwargs) return 1 @@ -2732,8 +2622,8 @@ def handle_sendemail_request(email, name, code, teamname, requestor, id, 'first_name': name, } - res = send_template_email(from_email, [fullemail], subject, - 'teamrequestemail.html', d, **kwargs) + _ = send_template_email(from_email, [fullemail], subject, + 'teamrequestemail.html', d, **kwargs) return 1 @@ -2755,8 +2645,8 @@ def handle_sendemail_request_accept(email, name, teamname, managername, 'teamname': teamname, 'siteurl': siteurl, } - res = send_template_email(from_email, [fullemail], subject, - 'teamwelcomeemail.html', d, **kwargs) + _ = send_template_email(from_email, [fullemail], subject, + 'teamwelcomeemail.html', d, **kwargs) return 1 @@ -2778,8 +2668,8 @@ def handle_sendemail_request_reject(email, name, teamname, managername, 'teamname': teamname, 'siteurl': siteurl, } - res = send_template_email(from_email, [fullemail], subject, - 'teamrejectemail.html', d, **kwargs) + _ = send_template_email(from_email, [fullemail], subject, + 'teamrejectemail.html', d, **kwargs) return 1 @@ -2801,8 +2691,8 @@ def handle_sendemail_member_dropped(email, name, teamname, managername, 'teamname': teamname, 'siteurl': siteurl, } - res = send_template_email(from_email, [fullemail], subject, - 'teamdropemail.html', d, **kwargs) + _ = send_template_email(from_email, [fullemail], subject, + 'teamdropemail.html', d, **kwargs) return 1 @@ -2825,8 +2715,8 @@ def handle_sendemail_team_removed(email, name, teamname, managername, 'teamname': teamname, 'siteurl': siteurl, } - res = send_template_email(from_email, [fullemail], subject, - 'teamremoveemail.html', d, **kwargs) + _ = send_template_email(from_email, [fullemail], subject, + 'teamremoveemail.html', d, **kwargs) return 1 @@ -2849,8 +2739,8 @@ def handle_sendemail_invite_reject(email, name, teamname, managername, 'teamname': teamname, 'siteurl': siteurl, } - res = send_template_email(from_email, [fullemail], subject, - 'teaminviterejectemail.html', d, **kwargs) + _ = send_template_email(from_email, [fullemail], subject, + 'teaminviterejectemail.html', d, **kwargs) return 1 @@ -2911,8 +2801,8 @@ def handle_sendemail_invite_accept(email, name, teamname, managername, 'teamname': teamname, 'siteurl': siteurl, } - res = send_template_email(from_email, [fullemail], subject, - 'teaminviteacceptemail.html', d, **kwargs) + _ = send_template_email(from_email, [fullemail], subject, + 'teaminviteacceptemail.html', d, **kwargs) return 1 @@ -2950,7 +2840,7 @@ def handle_update_wps(rid, types, ids, mode, debug=False, **kwargs): engine = create_engine(database_url, echo=False) with engine.connect() as conn, conn.begin(): - result = conn.execute(query) + _ = conn.execute(query) conn.close() engine.dispose() @@ -2963,17 +2853,17 @@ def handle_rp3_async_workout(userid, rp3token, rp3id, startdatetime, max_attempt headers = {'Authorization': 'Bearer ' + rp3token} get_download_link = """{ - download(workout_id: """ + str(rp3id) + """, type:csv){ - id - status - link - } + download(workout_id: """ + str(rp3id) + """, type:csv){ + id + status + link + } }""" have_link = False download_url = '' counter = 0 - #max_attempts = 20 + waittime = 3 while not have_link: response = requests.post( @@ -3092,10 +2982,6 @@ def handle_nk_async_workout(alldata, userid, nktoken, nkid, delaysec, defaulttim df = strokeDataToDf(strokeData) - # get workout data - timestampbegin = df['timestamp'].min() - timestampend = df['timestamp'].max() - csvfilename = 'media/{code}_{nkid}.csv.gz'.format( nkid=nkid, code=uuid4().hex[:16] @@ -3158,17 +3044,16 @@ def handle_c2_getworkout(userid, c2token, c2id, defaulttimezone, debug=False, ** data = s.json()['data'] alldata = {c2id: data} - splitdata = None return handle_c2_async_workout(alldata, userid, c2token, c2id, 0, defaulttimezone) def df_from_summary(data): - distance = data['distance'] - c2id = data['id'] - workouttype = data['type'] - verified = data['verified'] - weightclass = data['weight_class'] + # distance = data['distance'] + # c2id = data['id'] + # workouttype = data['type'] + # verified = data['verified'] + # weightclass = data['weight_class'] try: title = data['name'] except KeyError: # pragma: no cover @@ -3179,10 +3064,6 @@ def df_from_summary(data): except: # pragma: no cover title = '' - weightcategory = 'hwt' - if weightclass == "L": - weightcategory = 'lwt' - startdatetime, starttime, workoutdate, duration, starttimeunix, timezone = utils.get_startdatetime_from_c2data( data) @@ -3247,16 +3128,16 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim distance = data['distance'] try: # pragma: no cover rest_distance = data['rest_distance'] - rest_time = data['rest_time']/10. + # rest_time = data['rest_time']/10. except KeyError: rest_distance = 0 - rest_time = 0 + # rest_time = 0 distance = distance+rest_distance c2id = data['id'] workouttype = data['type'] - verified = data['verified'] + # verified = data['verified'] - weightclass = data['weight_class'] + # weightclass = data['weight_class'] try: has_strokedata = data['stroke_data'] @@ -3277,14 +3158,10 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim except: # pragma: no cover title = '' - weightcategory = 'hwt' - if weightclass == "L": - weightcategory = 'lwt' - # Create CSV file name and save data to CSV file csvfilename = 'media/{code}_{c2id}.csv'.format( code=uuid4().hex[:16], c2id=c2id) - + startdatetime, starttime, workoutdate, duration, starttimeunix, timezone = utils.get_startdatetime_from_c2data( data) @@ -3293,14 +3170,6 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim duration=duration) dologging('debuglog.log', s) - try: - notes = data['comments'] - name = notes[:40] - except (KeyError, TypeError): # pragma: no cover - notes = 'C2 Import Workout from {startdatetime}'.format( - startdatetime=startdatetime) - name = notes - authorizationstring = str('Bearer ' + c2token) headers = {'Authorization': authorizationstring, 'user-agent': 'sanderroosendaal', @@ -3400,9 +3269,7 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim df.sort_values(by='TimeStamp (sec)', ascending=True) - res = df.to_csv(csvfilename, index_label='index', - compression='gzip' - ) + _ = df.to_csv(csvfilename, index_label='index', compression='gzip') uploadoptions = { 'secret': UPLOAD_SERVICE_SECRET, @@ -3500,18 +3367,16 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim rowdata = rdata(csvfile=csvfilename) if rowdata: - rowdata.updateintervaldata(values, - units, types, results) + rowdata.updateintervaldata(values, units, types, results) rowdata.write_csv(csvfilename, gzip=True) - dataprepnodjango.update_strokedata(w.id, rowdata.df) + update_strokedata(workoutid, rowdata.df) return workoutid @app.task def fetch_strava_workout(stravatoken, oauth_data, stravaid, csvfilename, userid, debug=False, **kwargs): - fetchresolution = 'high' authorizationstring = str('Bearer '+stravatoken) headers = {'Authorization': authorizationstring, 'user-agent': 'sanderroosendaal', @@ -3546,11 +3411,6 @@ def fetch_strava_workout(stravatoken, oauth_data, stravaid, csvfilename, userid, except: # pragma: no cover return 0 - try: - startdatetime = workoutsummary['start_date'] - except KeyError: # pragma: no cover - startdatetime = timezone.now() - spm = get_strava_stream(None, 'cadence', stravaid, authorizationstring=authorizationstring) hr = get_strava_stream(None, 'heartrate', stravaid, @@ -3655,16 +3515,6 @@ def fetch_strava_workout(stravatoken, oauth_data, stravaid, csvfilename, userid, except KeyError: # pragma: no cover pass - try: - comments = workoutsummary['comments'] - except: - comments = ' ' - - try: - thetimezone = workoutsummary['timezone'] - except: # pragma: no cover - thetimezone = 'UTC' - try: rowdatetime = iso8601.parse_date(workoutsummary['date_utc']) except KeyError: @@ -3672,18 +3522,12 @@ def fetch_strava_workout(stravatoken, oauth_data, stravaid, csvfilename, userid, except ParseError: # pragma: no cover rowdatetime = iso8601.parse_date(workoutsummary['date']) - try: - intervaltype = workoutsummary['workout_type'] - - except KeyError: - intervaltype = '' - try: title = workoutsummary['name'] except KeyError: # pragma: no cover title = "" try: - t = data['comments'].split('\n', 1)[0] + t = workoutsummary['comments'].split('\n', 1)[0] title += t[:20] except: title = '' @@ -3767,8 +3611,8 @@ def fetch_strava_workout(stravatoken, oauth_data, stravaid, csvfilename, userid, row = rowingdata.rowingdata(df=df) row.write_csv(csvfilename, gzip=False) - summary = row.allstats() - maxdist = df['cum_dist'].max() + # summary = row.allstats() + # maxdist = df['cum_dist'].max() duration = row.duration uploadoptions = {