Merge branch 'hotfix/v7.11'
This commit is contained in:
@@ -135,15 +135,6 @@ def rdata(file,rower=rrower()):
|
|||||||
|
|
||||||
from utils import totaltime_sec_to_string
|
from utils import totaltime_sec_to_string
|
||||||
|
|
||||||
def create_strava_stroke_data_db(workoutid,df,csvfilename,debug=False):
|
|
||||||
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
|
||||||
|
|
||||||
res = df.to_csv(csvfilename+'.gz',index_label='index',compression='gzip')
|
|
||||||
|
|
||||||
row = rrdata(csvfile=csvfilename+'.gz')
|
|
||||||
data = dataprep(row.df,id=workoutid,bands=False,debug=debug)
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
# Creates C2 stroke data
|
# Creates C2 stroke data
|
||||||
def create_c2_stroke_data_db(
|
def create_c2_stroke_data_db(
|
||||||
|
|||||||
@@ -119,28 +119,6 @@ def get_strava_workout_list(user):
|
|||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def add_stroke_data(user,stravaid,workoutid,startdatetime,csvfilename,debug=False):
|
|
||||||
r = Rower.objects.get(user=user)
|
|
||||||
|
|
||||||
starttimeunix = arrow.get(startdatetime).timestamp
|
|
||||||
|
|
||||||
if not debug:
|
|
||||||
job = myqueue(queue,
|
|
||||||
handle_strava_import_stroke_data,
|
|
||||||
r.stravatoken,
|
|
||||||
stravaid,
|
|
||||||
workoutid,
|
|
||||||
starttimeunix,
|
|
||||||
csvfilename)
|
|
||||||
else:
|
|
||||||
handle_strava_import_stroke_data(
|
|
||||||
r.stravatoken,
|
|
||||||
stravaid,
|
|
||||||
workoutid,
|
|
||||||
starttimeunix,
|
|
||||||
csvfilename,
|
|
||||||
debug=debug
|
|
||||||
)
|
|
||||||
|
|
||||||
# gets all new Strava workouts for a rower
|
# gets all new Strava workouts for a rower
|
||||||
def get_strava_workouts(rower):
|
def get_strava_workouts(rower):
|
||||||
@@ -165,7 +143,7 @@ def get_strava_workouts(rower):
|
|||||||
newids = [stravaid for stravaid in stravaids if not stravaid in knownstravaids]
|
newids = [stravaid for stravaid in stravaids if not stravaid in knownstravaids]
|
||||||
|
|
||||||
for stravaid in newids:
|
for stravaid in newids:
|
||||||
workoutid = create_async_workout(alldata,rower.user,stravaid)
|
result = create_async_workout(alldata,rower.user,stravaid)
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@@ -234,29 +212,38 @@ def create_async_workout(alldata,user,stravaid,debug=False):
|
|||||||
code = uuid4().hex[:16]
|
code = uuid4().hex[:16]
|
||||||
)
|
)
|
||||||
|
|
||||||
w = Workout(
|
# w = Workout(
|
||||||
user=r,
|
# user=r,
|
||||||
workouttype = workouttype,
|
# workouttype = workouttype,
|
||||||
name = title,
|
# name = title,
|
||||||
date = workoutdate,
|
# date = workoutdate,
|
||||||
starttime = starttime,
|
# starttime = starttime,
|
||||||
startdatetime = rowdatetime,
|
# startdatetime = rowdatetime,
|
||||||
timezone = thetimezone,
|
# timezone = thetimezone,
|
||||||
duration = duration,
|
# duration = duration,
|
||||||
distance=distance,
|
# distance=distance,
|
||||||
weightcategory = weightcategory,
|
# weightcategory = weightcategory,
|
||||||
uploadedtostrava = stravaid,
|
# uploadedtostrava = stravaid,
|
||||||
csvfilename = csvfilename,
|
# csvfilename = csvfilename,
|
||||||
notes = ''
|
# notes = ''
|
||||||
)
|
# )
|
||||||
|
|
||||||
w.save()
|
|
||||||
|
|
||||||
# Check if workout has stroke data, and get the stroke data
|
# Check if workout has stroke data, and get the stroke data
|
||||||
|
|
||||||
result = add_stroke_data(user,stravaid,w.id,rowdatetime,csvfilename,debug=debug)
|
starttimeunix = arrow.get(rowdatetime).timestamp
|
||||||
|
|
||||||
return w.id
|
job = myqueue(queue,
|
||||||
|
handle_strava_import_stroke_data,
|
||||||
|
title,
|
||||||
|
user.email,
|
||||||
|
r.stravatoken,
|
||||||
|
stravaid,
|
||||||
|
starttimeunix,
|
||||||
|
csvfilename,
|
||||||
|
)
|
||||||
|
|
||||||
|
return 1
|
||||||
|
|
||||||
from utils import get_strava_stream
|
from utils import get_strava_stream
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ from rowsandall_app.settings import SITE_URL
|
|||||||
from rowsandall_app.settings_dev import SITE_URL as SITE_URL_DEV
|
from rowsandall_app.settings_dev import SITE_URL as SITE_URL_DEV
|
||||||
from rowsandall_app.settings import PROGRESS_CACHE_SECRET
|
from rowsandall_app.settings import PROGRESS_CACHE_SECRET
|
||||||
from rowsandall_app.settings import SETTINGS_NAME
|
from rowsandall_app.settings import SETTINGS_NAME
|
||||||
|
from rowsandall_app.settings import workoutemailbox
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ from rowers.dataprepnodjango import (
|
|||||||
add_c2_stroke_data_db,totaltime_sec_to_string,
|
add_c2_stroke_data_db,totaltime_sec_to_string,
|
||||||
create_c2_stroke_data_db,update_empower,
|
create_c2_stroke_data_db,update_empower,
|
||||||
database_url_debug,database_url,dataprep,
|
database_url_debug,database_url,dataprep,
|
||||||
create_strava_stroke_data_db
|
# create_strava_stroke_data_db
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -83,8 +83,10 @@ def add(x, y):
|
|||||||
|
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
def handle_strava_import_stroke_data(stravatoken,
|
def handle_strava_import_stroke_data(title,
|
||||||
stravaid,workoutid,
|
useremail,
|
||||||
|
stravatoken,
|
||||||
|
stravaid,
|
||||||
starttimeunix,
|
starttimeunix,
|
||||||
csvfilename,debug=True,**kwargs):
|
csvfilename,debug=True,**kwargs):
|
||||||
# ready to fetch. Hurray
|
# ready to fetch. Hurray
|
||||||
@@ -202,10 +204,26 @@ def handle_strava_import_stroke_data(stravatoken,
|
|||||||
' Power (watts)':watts,
|
' Power (watts)':watts,
|
||||||
})
|
})
|
||||||
|
|
||||||
res = create_strava_stroke_data_db(workoutid,df,csvfilename,debug=debug)
|
|
||||||
|
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
||||||
|
|
||||||
|
res = df.to_csv(csvfilename,index_label='index')
|
||||||
|
|
||||||
|
d = {
|
||||||
|
'stravaid':stravaid
|
||||||
|
}
|
||||||
|
|
||||||
|
res = send_template_email(useremail,[workoutemailbox],
|
||||||
|
title,'workoutemail.html',
|
||||||
|
d,
|
||||||
|
attach_file=csvfilename)
|
||||||
|
|
||||||
|
|
||||||
return 1
|
time.sleep(1)
|
||||||
|
|
||||||
|
os.remove(csvfilename)
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
|
|||||||
7
rowers/templates/workoutemail.html
Normal file
7
rowers/templates/workoutemail.html
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{% extends "emailbase.html" %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
stravaid {{ stravaid }}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
@@ -98,6 +98,17 @@ def matchsync(line):
|
|||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
def getstravaid(uploadoptions,body):
|
||||||
|
stravaid = 0
|
||||||
|
tester = re.compile('^(stravaid)(.*?)(\d+)')
|
||||||
|
for line in body.splitlines():
|
||||||
|
if tester.match(line.lower()):
|
||||||
|
stravaid = tester.match(line.lower()).group(3)
|
||||||
|
|
||||||
|
uploadoptions['stravaid'] = int(stravaid)
|
||||||
|
|
||||||
|
return uploadoptions
|
||||||
|
|
||||||
def gettypeoptions_body2(uploadoptions,body):
|
def gettypeoptions_body2(uploadoptions,body):
|
||||||
tester = re.compile('^(workout)')
|
tester = re.compile('^(workout)')
|
||||||
testerb = re.compile('^(boat)')
|
testerb = re.compile('^(boat)')
|
||||||
@@ -272,6 +283,7 @@ def upload_options(body):
|
|||||||
uploadoptions = getsyncoptions_body2(uploadoptions,body)
|
uploadoptions = getsyncoptions_body2(uploadoptions,body)
|
||||||
uploadoptions = getprivateoptions_body2(uploadoptions,body)
|
uploadoptions = getprivateoptions_body2(uploadoptions,body)
|
||||||
typeoptions = gettypeoptions_body2(uploadoptions,body)
|
typeoptions = gettypeoptions_body2(uploadoptions,body)
|
||||||
|
uploadoptions = getstravaid(uploadoptions,body)
|
||||||
except IOError:
|
except IOError:
|
||||||
pm = exc.problem_mark
|
pm = exc.problem_mark
|
||||||
strpm = str(pm)
|
strpm = str(pm)
|
||||||
@@ -376,6 +388,13 @@ def make_private(w,options):
|
|||||||
from rowers.utils import isprorower
|
from rowers.utils import isprorower
|
||||||
|
|
||||||
def do_sync(w,options):
|
def do_sync(w,options):
|
||||||
|
try:
|
||||||
|
if options['stravaid'] != 0:
|
||||||
|
w.uploadedtostrava = stravaid
|
||||||
|
w.save()
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
if ('upload_to_C2' in options and options['upload_to_C2']) or (w.user.c2_auto_export and isprorower(w.user)):
|
if ('upload_to_C2' in options and options['upload_to_C2']) or (w.user.c2_auto_export and isprorower(w.user)):
|
||||||
try:
|
try:
|
||||||
message,id = c2stuff.workout_c2_upload(w.user.user,w)
|
message,id = c2stuff.workout_c2_upload(w.user.user,w)
|
||||||
|
|||||||
@@ -10263,10 +10263,7 @@ def workout_getstravaworkout_next(request):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
url = reverse(r.defaultlandingpage,
|
url = reverse(workouts_view)
|
||||||
kwargs={
|
|
||||||
'id':workoutid,
|
|
||||||
})
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -409,3 +409,9 @@ except KeyError:
|
|||||||
WARNING_MESSAGE = ''
|
WARNING_MESSAGE = ''
|
||||||
|
|
||||||
SETTINGS_NAME = 'rowsandall_app.settings'
|
SETTINGS_NAME = 'rowsandall_app.settings'
|
||||||
|
|
||||||
|
# Workout email box
|
||||||
|
try:
|
||||||
|
workoutemailbox = CFG['workoutemailbox']
|
||||||
|
except KeyError:
|
||||||
|
workoutemailbox = 'workouts@rowsandall.com'
|
||||||
|
|||||||
Reference in New Issue
Block a user