ds
This commit is contained in:
@@ -25,7 +25,6 @@ import numpy as np
|
|||||||
|
|
||||||
from rowsandall_app.settings import (
|
from rowsandall_app.settings import (
|
||||||
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET,
|
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET,
|
||||||
UPLOAD_SERVICE_URL, UPLOAD_SERVICE_SECRET
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from rowers.tasks import (
|
from rowers.tasks import (
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ def is_invalid_file(file_path):
|
|||||||
return True, ""
|
return True, ""
|
||||||
|
|
||||||
|
|
||||||
def upload_handler(uploadoptions, filename):
|
def upload_handler(uploadoptions, filename, createworkout=False, debug=False, **kwargs):
|
||||||
valid, message = valid_uploadoptions(uploadoptions)
|
valid, message = valid_uploadoptions(uploadoptions)
|
||||||
if not valid: # pragma: no cover
|
if not valid: # pragma: no cover
|
||||||
return {
|
return {
|
||||||
@@ -167,12 +167,24 @@ def upload_handler(uploadoptions, filename):
|
|||||||
"message": "Your zip file is being processed. You will be notified when it is complete."
|
"message": "Your zip file is being processed. You will be notified when it is complete."
|
||||||
}
|
}
|
||||||
job_id = generate_job_id()
|
job_id = generate_job_id()
|
||||||
|
if 'id' not in uploadoptions and createworkout:
|
||||||
|
w = Workout(
|
||||||
|
user=get_rower_from_uploadoptions(uploadoptions),
|
||||||
|
duration='00:00:00'
|
||||||
|
)
|
||||||
|
w.save()
|
||||||
|
uploadoptions['id'] = w.id
|
||||||
|
|
||||||
|
if 'id' in uploadoptions:
|
||||||
|
job_id = encoder.encode_hex(uploadoptions['id'])
|
||||||
|
|
||||||
_ = myqueue(
|
_ = myqueue(
|
||||||
queuehigh,
|
queuehigh,
|
||||||
process_single_file,
|
process_single_file,
|
||||||
filename,
|
filename,
|
||||||
uploadoptions,
|
uploadoptions,
|
||||||
job_id)
|
job_id)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"status": "processing",
|
"status": "processing",
|
||||||
"job_id": job_id,
|
"job_id": job_id,
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import pytz
|
|||||||
|
|
||||||
from rowsandall_app.settings import (
|
from rowsandall_app.settings import (
|
||||||
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET,
|
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET,
|
||||||
UPLOAD_SERVICE_URL, UPLOAD_SERVICE_SECRET
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from rowers.tasks import (
|
from rowers.tasks import (
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ from rowers.opaque import encoder
|
|||||||
|
|
||||||
from rowsandall_app.settings import (
|
from rowsandall_app.settings import (
|
||||||
INTERVALS_CLIENT_ID, INTERVALS_REDIRECT_URI, INTERVALS_CLIENT_SECRET, SITE_URL,
|
INTERVALS_CLIENT_ID, INTERVALS_REDIRECT_URI, INTERVALS_CLIENT_SECRET, SITE_URL,
|
||||||
UPLOAD_SERVICE_SECRET, UPLOAD_SERVICE_URL
|
|
||||||
)
|
)
|
||||||
|
|
||||||
import django_rq
|
import django_rq
|
||||||
@@ -57,6 +56,7 @@ intervals_token_url = 'https://intervals.icu/api/oauth/token'
|
|||||||
webhookverification = 'JA9Vt6RNH10'
|
webhookverification = 'JA9Vt6RNH10'
|
||||||
|
|
||||||
class IntervalsIntegration(SyncIntegration):
|
class IntervalsIntegration(SyncIntegration):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(IntervalsIntegration, self).__init__(*args, **kwargs)
|
super(IntervalsIntegration, self).__init__(*args, **kwargs)
|
||||||
self.oauth_data = {
|
self.oauth_data = {
|
||||||
@@ -315,6 +315,7 @@ class IntervalsIntegration(SyncIntegration):
|
|||||||
return workouts
|
return workouts
|
||||||
|
|
||||||
def update_workout(self, id, *args, **kwargs) -> int:
|
def update_workout(self, id, *args, **kwargs) -> int:
|
||||||
|
from rowers.dataflow import upload_handler
|
||||||
try:
|
try:
|
||||||
_ = self.open()
|
_ = self.open()
|
||||||
except NoTokenError:
|
except NoTokenError:
|
||||||
@@ -419,7 +420,6 @@ class IntervalsIntegration(SyncIntegration):
|
|||||||
|
|
||||||
|
|
||||||
uploadoptions = {
|
uploadoptions = {
|
||||||
'secret': UPLOAD_SERVICE_SECRET,
|
|
||||||
'user': self.rower.user.id,
|
'user': self.rower.user.id,
|
||||||
'boattype': '1x',
|
'boattype': '1x',
|
||||||
'workouttype': w.workouttype,
|
'workouttype': w.workouttype,
|
||||||
@@ -427,8 +427,8 @@ class IntervalsIntegration(SyncIntegration):
|
|||||||
'intervalsid': id,
|
'intervalsid': id,
|
||||||
'id': w.id,
|
'id': w.id,
|
||||||
}
|
}
|
||||||
url = UPLOAD_SERVICE_URL
|
|
||||||
response = requests.post(url, data=uploadoptions)
|
response = upload_handler(uploadoptions, temp_filename)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return 0
|
return 0
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -443,6 +443,7 @@ class IntervalsIntegration(SyncIntegration):
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
def get_workout(self, id, *args, **kwargs) -> int:
|
def get_workout(self, id, *args, **kwargs) -> int:
|
||||||
|
from rowers.dataflow import upload_handler
|
||||||
try:
|
try:
|
||||||
_ = self.open()
|
_ = self.open()
|
||||||
except NoTokenError:
|
except NoTokenError:
|
||||||
@@ -542,8 +543,17 @@ class IntervalsIntegration(SyncIntegration):
|
|||||||
except:
|
except:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
w = Workout(
|
||||||
|
user=r,
|
||||||
|
name=title,
|
||||||
|
workoutsource='intervals.icu',
|
||||||
|
workouttype=workouttype,
|
||||||
|
duration=duration,
|
||||||
|
distance=distance,
|
||||||
|
intervalsid=id,
|
||||||
|
)
|
||||||
|
|
||||||
uploadoptions = {
|
uploadoptions = {
|
||||||
'secret': UPLOAD_SERVICE_SECRET,
|
|
||||||
'user': r.user.id,
|
'user': r.user.id,
|
||||||
'boattype': '1x',
|
'boattype': '1x',
|
||||||
'workouttype': workouttype,
|
'workouttype': workouttype,
|
||||||
@@ -555,30 +565,25 @@ class IntervalsIntegration(SyncIntegration):
|
|||||||
'offline': False,
|
'offline': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
url = UPLOAD_SERVICE_URL
|
response = upload_handler(uploadoptions, fit_filename)
|
||||||
handle_request_post(url, uploadoptions)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pair_id = data['paired_event_id']
|
pair_id = data['paired_event_id']
|
||||||
pss = PlannedSession.objects.filter(intervals_icu_id=pair_id, rower=r)
|
pss = PlannedSession.objects.filter(intervals_icu_id=pair_id, rower=r)
|
||||||
ws = Workout.objects.filter(uploadedtointervals=id)
|
|
||||||
for w in ws:
|
w.sub_type = subtype
|
||||||
w.sub_type = subtype
|
w.save()
|
||||||
w.save()
|
|
||||||
if is_commute:
|
if is_commute:
|
||||||
for w in ws:
|
w.is_commute = True
|
||||||
w.is_commute = True
|
w.sub_type = "Commute"
|
||||||
w.sub_type = "Commute"
|
w.save()
|
||||||
w.save()
|
|
||||||
if is_race:
|
if is_race:
|
||||||
for w in ws:
|
w.is_race = True
|
||||||
w.is_race = True
|
w.save()
|
||||||
w.save()
|
|
||||||
if pss.count() > 0:
|
if pss.count() > 0:
|
||||||
for ps in pss:
|
for ps in pss:
|
||||||
for w in ws:
|
w.plannedsession = ps
|
||||||
w.plannedsession = ps
|
w.save()
|
||||||
w.save()
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
except PlannedSession.DoesNotExist:
|
except PlannedSession.DoesNotExist:
|
||||||
|
|||||||
@@ -103,6 +103,8 @@ class PolarIntegration(SyncIntegration):
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
def get_polar_workouts(self, user):
|
def get_polar_workouts(self, user):
|
||||||
|
from rowers.dataflow import upload_handler
|
||||||
|
|
||||||
r = Rower.objects.get(user=user)
|
r = Rower.objects.get(user=user)
|
||||||
|
|
||||||
exercise_list = []
|
exercise_list = []
|
||||||
@@ -191,28 +193,9 @@ class PolarIntegration(SyncIntegration):
|
|||||||
'title': '',
|
'title': '',
|
||||||
}
|
}
|
||||||
|
|
||||||
url = settings.UPLOAD_SERVICE_URL
|
response = upload_handler(uploadoptions, filename)
|
||||||
|
if response['status'] != 'processing':
|
||||||
dologging('polar.log', uploadoptions)
|
return 0
|
||||||
dologging('polar.log', url)
|
|
||||||
|
|
||||||
_ = myqueue(
|
|
||||||
queuehigh,
|
|
||||||
handle_request_post,
|
|
||||||
url,
|
|
||||||
uploadoptions
|
|
||||||
)
|
|
||||||
|
|
||||||
dologging('polar.log', response.status_code)
|
|
||||||
if response.status_code != 200: # pragma: no cover
|
|
||||||
try:
|
|
||||||
dologging('polar.log', response.text)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
dologging('polar.log', response.json())
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
exercise_dict['filename'] = filename
|
exercise_dict['filename'] = filename
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ from rowers.models import User, Rower, Workout, TombStone
|
|||||||
from rowers.upload_tasks import handle_rp3_async_workout
|
from rowers.upload_tasks import handle_rp3_async_workout
|
||||||
from rowsandall_app.settings import (
|
from rowsandall_app.settings import (
|
||||||
RP3_CLIENT_ID, RP3_CLIENT_KEY, RP3_REDIRECT_URI, RP3_CLIENT_SECRET,
|
RP3_CLIENT_ID, RP3_CLIENT_KEY, RP3_REDIRECT_URI, RP3_CLIENT_SECRET,
|
||||||
UPLOAD_SERVICE_URL, UPLOAD_SERVICE_SECRET
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from rowers.utils import myqueue, NoTokenError, dologging, uniqify
|
from rowers.utils import myqueue, NoTokenError, dologging, uniqify
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ from datetime import timedelta
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from rowsandall_app.settings import UPLOAD_SERVICE_SECRET, UPLOAD_SERVICE_URL
|
|
||||||
from rowsandall_app.settings import NK_API_LOCATION
|
from rowsandall_app.settings import NK_API_LOCATION
|
||||||
|
|
||||||
from rowers.utils import dologging
|
from rowers.utils import dologging
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ from datetime import timedelta
|
|||||||
from rowsandall_app.settings import (
|
from rowsandall_app.settings import (
|
||||||
ROJABO_CLIENT_ID, ROJABO_REDIRECT_URI, ROJABO_CLIENT_SECRET,
|
ROJABO_CLIENT_ID, ROJABO_REDIRECT_URI, ROJABO_CLIENT_SECRET,
|
||||||
SITE_URL, ROJABO_OAUTH_LOCATION,
|
SITE_URL, ROJABO_OAUTH_LOCATION,
|
||||||
UPLOAD_SERVICE_URL, UPLOAD_SERVICE_SECRET,
|
|
||||||
)
|
)
|
||||||
import gzip
|
import gzip
|
||||||
import rowers.mytypes as mytypes
|
import rowers.mytypes as mytypes
|
||||||
|
|||||||
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
Binary file not shown.
@@ -15,6 +15,7 @@ from rest_framework.decorators import parser_classes
|
|||||||
from rest_framework.parsers import BaseParser
|
from rest_framework.parsers import BaseParser
|
||||||
|
|
||||||
from rowers.utils import geo_distance
|
from rowers.utils import geo_distance
|
||||||
|
from rowers.dataflow import upload_handler
|
||||||
|
|
||||||
from datetime import datetime as dt
|
from datetime import datetime as dt
|
||||||
|
|
||||||
@@ -467,7 +468,6 @@ def strokedata_rowingdata(request):
|
|||||||
filename, completefilename = handle_uploaded_file(f)
|
filename, completefilename = handle_uploaded_file(f)
|
||||||
|
|
||||||
uploadoptions = {
|
uploadoptions = {
|
||||||
'secret': settings.UPLOAD_SERVICE_SECRET,
|
|
||||||
'user': r.user.id,
|
'user': r.user.id,
|
||||||
'file': completefilename,
|
'file': completefilename,
|
||||||
'workouttype': form.cleaned_data['workouttype'],
|
'workouttype': form.cleaned_data['workouttype'],
|
||||||
@@ -477,17 +477,21 @@ def strokedata_rowingdata(request):
|
|||||||
'notes': form.cleaned_data['notes']
|
'notes': form.cleaned_data['notes']
|
||||||
}
|
}
|
||||||
|
|
||||||
url = settings.UPLOAD_SERVICE_URL
|
result = upload_handler(uploadoptions, completefilename, createworkout=True)
|
||||||
|
if result['status'] != 'processing':
|
||||||
|
dologging('apilog.log','Error in strokedata_rowingdata:')
|
||||||
|
dologging('apilog.log',result)
|
||||||
|
return JsonResponse(
|
||||||
|
result,
|
||||||
|
status=500
|
||||||
|
)
|
||||||
|
|
||||||
_ = myqueue(queuehigh,
|
workoutid = result.get('job_id',0)
|
||||||
handle_request_post,
|
|
||||||
url,
|
|
||||||
uploadoptions)
|
|
||||||
response = JsonResponse(
|
response = JsonResponse(
|
||||||
{
|
{"workout public id": workoutid,
|
||||||
"status": "success",
|
"status": "success",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
response.status_code = 201
|
response.status_code = 201
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@@ -518,7 +522,6 @@ def strokedata_rowingdata_apikey(request):
|
|||||||
filename, completefilename = handle_uploaded_file(f)
|
filename, completefilename = handle_uploaded_file(f)
|
||||||
|
|
||||||
uploadoptions = {
|
uploadoptions = {
|
||||||
'secret': settings.UPLOAD_SERVICE_SECRET,
|
|
||||||
'user': r.user.id,
|
'user': r.user.id,
|
||||||
'file': completefilename,
|
'file': completefilename,
|
||||||
'workouttype': form.cleaned_data['workouttype'],
|
'workouttype': form.cleaned_data['workouttype'],
|
||||||
@@ -528,17 +531,22 @@ def strokedata_rowingdata_apikey(request):
|
|||||||
'notes': form.cleaned_data['notes']
|
'notes': form.cleaned_data['notes']
|
||||||
}
|
}
|
||||||
|
|
||||||
url = settings.UPLOAD_SERVICE_URL
|
result = upload_handler(uploadoptions, completefilename, createworkout=True)
|
||||||
|
|
||||||
_ = myqueue(queuehigh,
|
if result['status'] != 'processing':
|
||||||
handle_request_post,
|
dologging('apilog.log','Error in strokedata_rowingdata_apikey:')
|
||||||
url,
|
dologging('apilog.log',result)
|
||||||
uploadoptions)
|
return JsonResponse(
|
||||||
|
result,
|
||||||
|
status=500
|
||||||
|
)
|
||||||
|
workoutid = result.get('job_id',0)
|
||||||
response = JsonResponse(
|
response = JsonResponse(
|
||||||
{
|
{"workout public id": workoutid,
|
||||||
"status": "success",
|
"status": "success",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
response.status_code = 201
|
response.status_code = 201
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@@ -614,7 +622,6 @@ def strokedata_fit(request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
uploadoptions = {
|
uploadoptions = {
|
||||||
'secret': UPLOAD_SERVICE_SECRET,
|
|
||||||
'user': request.user.id,
|
'user': request.user.id,
|
||||||
'file': fit_filename,
|
'file': fit_filename,
|
||||||
'boattype': '1x',
|
'boattype': '1x',
|
||||||
@@ -626,20 +633,18 @@ def strokedata_fit(request):
|
|||||||
'offline': False,
|
'offline': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
url = UPLOAD_SERVICE_URL
|
result = upload_handler(uploadoptions, fit_filename)
|
||||||
|
|
||||||
_ = myqueue(queuehigh,
|
|
||||||
handle_request_post,
|
|
||||||
url,
|
|
||||||
uploadoptions)
|
|
||||||
|
|
||||||
dologging('apilog.log','FIT file uploaded, returning response')
|
dologging('apilog.log','FIT file uploaded, returning response')
|
||||||
returndict = {
|
if result.get('status','') != 'processing':
|
||||||
"status": "success",
|
return JsonResponse(result, status=500)
|
||||||
"workout public id": encoder.encode_hex(w.id),
|
|
||||||
"workout id": w.id,
|
workoutid = result.get('job_id',0)
|
||||||
}
|
return JsonResponse(
|
||||||
return JsonResponse(returndict, status=201)
|
{"workout public id": workoutid,
|
||||||
|
"status": "success",
|
||||||
|
})
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
dologging('apilog.log','FIT API endpoint')
|
dologging('apilog.log','FIT API endpoint')
|
||||||
dologging('apilog.log',e)
|
dologging('apilog.log',e)
|
||||||
@@ -736,7 +741,6 @@ def strokedata_tcx(request):
|
|||||||
# need workouttype, duration
|
# need workouttype, duration
|
||||||
|
|
||||||
uploadoptions = {
|
uploadoptions = {
|
||||||
'secret': UPLOAD_SERVICE_SECRET,
|
|
||||||
'user': request.user.id,
|
'user': request.user.id,
|
||||||
'file': tcxfilename,
|
'file': tcxfilename,
|
||||||
'id': w.id,
|
'id': w.id,
|
||||||
@@ -747,17 +751,15 @@ def strokedata_tcx(request):
|
|||||||
'notes': '',
|
'notes': '',
|
||||||
'offline': False,
|
'offline': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_ = myqueue(queuehigh,
|
|
||||||
handle_post_workout_api,
|
|
||||||
uploadoptions)
|
|
||||||
|
|
||||||
workoutid = w.id
|
result = upload_handler(uploadoptions, tcxfilename)
|
||||||
|
if result.get('status','') != 'processing':
|
||||||
|
return JsonResponse(result, status=500)
|
||||||
|
|
||||||
|
workoutid = result.get('job_id',0)
|
||||||
|
|
||||||
return JsonResponse(
|
return JsonResponse(
|
||||||
{"workout public id": encoder.encode_hex(workoutid),
|
{"workout public id": workoutid,
|
||||||
"workout id": workoutid,
|
|
||||||
"status": "success",
|
"status": "success",
|
||||||
})
|
})
|
||||||
except Exception as e: # pragma: no cover
|
except Exception as e: # pragma: no cover
|
||||||
@@ -884,7 +886,6 @@ def strokedatajson_v3(request):
|
|||||||
w.save()
|
w.save()
|
||||||
|
|
||||||
uploadoptions = {
|
uploadoptions = {
|
||||||
'secret': UPLOAD_SERVICE_SECRET,
|
|
||||||
'user': request.user.id,
|
'user': request.user.id,
|
||||||
'file': csvfilename,
|
'file': csvfilename,
|
||||||
'title': title,
|
'title': title,
|
||||||
@@ -898,10 +899,9 @@ def strokedatajson_v3(request):
|
|||||||
'id': w.id,
|
'id': w.id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = upload_handler(uploadoptions, csvfilename)
|
||||||
_ = myqueue(queuehigh,
|
if result.get('status','') != 'processing':
|
||||||
handle_post_workout_api,
|
return JsonResponse(result, status=500)
|
||||||
uploadoptions)
|
|
||||||
|
|
||||||
workoutid = w.id
|
workoutid = w.id
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user