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