further code refactoring
This commit is contained in:
@@ -3,45 +3,15 @@
|
|||||||
# (There is still some stuff defined directly in views.py. Need to
|
# (There is still some stuff defined directly in views.py. Need to
|
||||||
# move that here.)
|
# move that here.)
|
||||||
|
|
||||||
# Python
|
from rowers.imports import *
|
||||||
import oauth2 as oauth
|
|
||||||
import cgi
|
|
||||||
import requests
|
|
||||||
import arrow
|
|
||||||
import requests.auth
|
|
||||||
import json
|
|
||||||
import iso8601
|
|
||||||
from django.utils import timezone
|
|
||||||
from datetime import datetime
|
|
||||||
from datetime import timedelta
|
|
||||||
import time
|
|
||||||
from time import strftime
|
|
||||||
|
|
||||||
# Django
|
|
||||||
from django.shortcuts import render_to_response
|
|
||||||
from django.http import HttpResponseRedirect, HttpResponse,JsonResponse
|
|
||||||
from django.conf import settings
|
|
||||||
from django.contrib.auth import authenticate, login, logout
|
|
||||||
from django.contrib.auth.models import User
|
|
||||||
from django.contrib.auth.decorators import login_required
|
|
||||||
import dataprep
|
|
||||||
import pytz
|
|
||||||
from rowingdata import rowingdata, make_cumvalues
|
|
||||||
import pandas as pd
|
|
||||||
import numpy as np
|
|
||||||
from rowers.models import Rower,Workout
|
|
||||||
from rowers.models import checkworkoutuser
|
|
||||||
import sys
|
|
||||||
import urllib
|
|
||||||
from requests import Request, Session
|
from requests import Request, Session
|
||||||
|
|
||||||
from utils import myqueue,uniqify,isprorower, custom_exception_handler, NoTokenError
|
|
||||||
|
|
||||||
from uuid import uuid4
|
|
||||||
|
|
||||||
from rowers.types import otwtypes
|
from rowers.types import otwtypes
|
||||||
|
|
||||||
from rowsandall_app.settings import C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET
|
from rowsandall_app.settings import (
|
||||||
|
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET
|
||||||
|
)
|
||||||
|
|
||||||
from rowers.tasks import handle_c2_import_stroke_data
|
from rowers.tasks import handle_c2_import_stroke_data
|
||||||
import django_rq
|
import django_rq
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ from django.contrib.auth.decorators import login_required
|
|||||||
|
|
||||||
# Project
|
# Project
|
||||||
# from .models import Profile
|
# from .models import Profile
|
||||||
from rowingdata import rowingdata
|
from rowingdata import rowingdata, make_cumvalues
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from rowers.models import Rower,Workout,checkworkoutuser
|
from rowers.models import Rower,Workout,checkworkoutuser
|
||||||
from rowers import types
|
from rowers import types
|
||||||
|
|||||||
@@ -1,47 +1,12 @@
|
|||||||
# All the functionality needed to connect to Runkeeper
|
# All the functionality needed to connect to Runkeeper
|
||||||
|
from rowers.imports import *
|
||||||
|
|
||||||
# Python
|
|
||||||
import oauth2 as oauth
|
|
||||||
import pytz
|
|
||||||
import cgi
|
|
||||||
import requests
|
|
||||||
import requests.auth
|
|
||||||
import json
|
|
||||||
from django.utils import timezone
|
|
||||||
from datetime import datetime
|
|
||||||
import numpy as np
|
|
||||||
from dateutil import parser
|
|
||||||
import time
|
|
||||||
import dateutil
|
|
||||||
from time import strftime
|
|
||||||
import math
|
|
||||||
from math import sin,cos,atan2,sqrt
|
|
||||||
import os,sys
|
|
||||||
|
|
||||||
# Django
|
|
||||||
from django.shortcuts import render_to_response
|
|
||||||
from django.http import HttpResponseRedirect, HttpResponse,JsonResponse
|
|
||||||
from django.conf import settings
|
|
||||||
from django.contrib.auth import authenticate, login, logout
|
|
||||||
from django.contrib.auth.models import User
|
|
||||||
from django.contrib.auth.decorators import login_required
|
|
||||||
|
|
||||||
# Project
|
|
||||||
# from .models import Profile
|
|
||||||
from rowingdata import rowingdata
|
|
||||||
import pandas as pd
|
|
||||||
from rowers.models import Rower,Workout,checkworkoutuser
|
|
||||||
from uuid import uuid4
|
|
||||||
import iso8601
|
|
||||||
import arrow
|
|
||||||
from rowers import types
|
|
||||||
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,
|
||||||
STRAVA_CLIENT_ID, STRAVA_REDIRECT_URI, STRAVA_CLIENT_SECRET,
|
STRAVA_CLIENT_ID, STRAVA_REDIRECT_URI, STRAVA_CLIENT_SECRET,
|
||||||
RUNKEEPER_CLIENT_ID, RUNKEEPER_CLIENT_SECRET,RUNKEEPER_REDIRECT_URI,
|
RUNKEEPER_CLIENT_ID, RUNKEEPER_CLIENT_SECRET,RUNKEEPER_REDIRECT_URI,
|
||||||
)
|
)
|
||||||
|
|
||||||
from utils import geo_distance,ewmovingaverage,NoTokenError, custom_exception_handler
|
|
||||||
|
|
||||||
def splitrunkeeperlatlongdata(lijst,tname,latname,lonname):
|
def splitrunkeeperlatlongdata(lijst,tname,latname,lonname):
|
||||||
t = []
|
t = []
|
||||||
@@ -63,7 +28,6 @@ def splitrunkeeperdata(lijst,xname,yname):
|
|||||||
|
|
||||||
return [np.array(x),np.array(y)]
|
return [np.array(x),np.array(y)]
|
||||||
|
|
||||||
import dataprep
|
|
||||||
|
|
||||||
# Checks if user has SportTracks token, renews them if they are expired
|
# Checks if user has SportTracks token, renews them if they are expired
|
||||||
def runkeeper_open(user):
|
def runkeeper_open(user):
|
||||||
@@ -390,7 +354,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
|
|||||||
rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
|
rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
try:
|
try:
|
||||||
rowdatetime = dateutil.parser.parse(data['start_time'])
|
rowdatetime = parser.parse(data['start_time'])
|
||||||
#rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
|
#rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
|
||||||
except:
|
except:
|
||||||
rowdatetime = datetime.strptime(data['date'],"%Y-%m-%d %H:%M:%S")
|
rowdatetime = datetime.strptime(data['date'],"%Y-%m-%d %H:%M:%S")
|
||||||
|
|||||||
@@ -1,58 +1,12 @@
|
|||||||
# All the functionality to connect to SportTracks
|
# All the functionality to connect to SportTracks
|
||||||
|
|
||||||
# Python
|
from rowers.imports import *
|
||||||
import oauth2 as oauth
|
|
||||||
import cgi
|
|
||||||
import requests
|
|
||||||
import requests.auth
|
|
||||||
import json
|
|
||||||
from django.utils import timezone
|
|
||||||
from datetime import datetime
|
|
||||||
import numpy as np
|
|
||||||
from dateutil import parser
|
|
||||||
import time
|
|
||||||
import math
|
|
||||||
from math import sin,cos,atan2,sqrt
|
|
||||||
|
|
||||||
import urllib
|
from rowsandall_app.settings import (
|
||||||
import c2stuff
|
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET,
|
||||||
import pytz
|
STRAVA_CLIENT_ID, STRAVA_REDIRECT_URI, STRAVA_CLIENT_SECRET,
|
||||||
import iso8601
|
SPORTTRACKS_CLIENT_SECRET, SPORTTRACKS_CLIENT_ID, SPORTTRACKS_REDIRECT_URI
|
||||||
from uuid import uuid4
|
)
|
||||||
import arrow
|
|
||||||
# Django
|
|
||||||
from django.shortcuts import render_to_response
|
|
||||||
from django.http import HttpResponseRedirect, HttpResponse,JsonResponse
|
|
||||||
from django.conf import settings
|
|
||||||
from django.contrib.auth import authenticate, login, logout
|
|
||||||
from django.contrib.auth.models import User
|
|
||||||
from django.contrib.auth.decorators import login_required
|
|
||||||
|
|
||||||
# Project
|
|
||||||
# from .models import Profile
|
|
||||||
from rowingdata import rowingdata
|
|
||||||
import pandas as pd
|
|
||||||
from rowers.models import Rower,Workout,checkworkoutuser
|
|
||||||
from rowers import types
|
|
||||||
from rowsandall_app.settings import C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET, STRAVA_CLIENT_ID, STRAVA_REDIRECT_URI, STRAVA_CLIENT_SECRET, SPORTTRACKS_CLIENT_SECRET, SPORTTRACKS_CLIENT_ID, SPORTTRACKS_REDIRECT_URI
|
|
||||||
|
|
||||||
from utils import NoTokenError, custom_exception_handler, ewmovingaverage
|
|
||||||
|
|
||||||
from time import strftime
|
|
||||||
import dataprep
|
|
||||||
|
|
||||||
# Splits SportTracks data which is one long sequence of
|
|
||||||
# [t,[lat,lon],t2,[lat2,lon2] ...]
|
|
||||||
# to [t,t2,t3, ...], [[lat,long],[lat2,long2],...
|
|
||||||
def splitstdata(lijst):
|
|
||||||
t = []
|
|
||||||
latlong = []
|
|
||||||
while len(lijst)>=2:
|
|
||||||
t.append(lijst[0])
|
|
||||||
latlong.append(lijst[1])
|
|
||||||
lijst = lijst[2:]
|
|
||||||
|
|
||||||
return [np.array(t),np.array(latlong)]
|
|
||||||
|
|
||||||
|
|
||||||
# Checks if user has SportTracks token, renews them if they are expired
|
# Checks if user has SportTracks token, renews them if they are expired
|
||||||
|
|||||||
@@ -1,71 +1,30 @@
|
|||||||
# All the functionality needed to connect to Strava
|
|
||||||
|
|
||||||
# Python
|
|
||||||
import oauth2 as oauth
|
|
||||||
import cgi
|
|
||||||
import requests
|
|
||||||
import requests.auth
|
|
||||||
import json
|
|
||||||
from django.utils import timezone
|
|
||||||
from datetime import datetime
|
|
||||||
import numpy as np
|
|
||||||
from dateutil import parser
|
|
||||||
import time
|
|
||||||
from time import strftime,strptime
|
|
||||||
import math
|
|
||||||
from math import sin,cos,atan2,sqrt
|
|
||||||
import os,sys
|
|
||||||
import gzip
|
|
||||||
|
|
||||||
from pytz import timezone as tz,utc
|
|
||||||
|
|
||||||
# Django
|
|
||||||
from django.shortcuts import render_to_response
|
|
||||||
from django.http import HttpResponseRedirect, HttpResponse,JsonResponse
|
|
||||||
from django.conf import settings
|
|
||||||
from django.contrib.auth import authenticate, login, logout
|
|
||||||
from django.contrib.auth.models import User
|
|
||||||
from django.contrib.auth.decorators import login_required
|
|
||||||
|
|
||||||
import django_rq
|
import django_rq
|
||||||
queue = django_rq.get_queue('default')
|
queue = django_rq.get_queue('default')
|
||||||
queuelow = django_rq.get_queue('low')
|
queuelow = django_rq.get_queue('low')
|
||||||
queuehigh = django_rq.get_queue('low')
|
queuehigh = django_rq.get_queue('low')
|
||||||
|
|
||||||
|
|
||||||
# Project
|
|
||||||
# from .models import Profile
|
|
||||||
from rowingdata import rowingdata
|
|
||||||
from rowingdata import make_cumvalues
|
|
||||||
import pandas as pd
|
|
||||||
from rowers.models import Rower,Workout
|
|
||||||
from rowers.models import checkworkoutuser
|
|
||||||
import dataprep
|
|
||||||
from dataprep import columndict
|
from dataprep import columndict
|
||||||
from utils import uniqify,isprorower,myqueue,NoTokenError, custom_exception_handler
|
|
||||||
from uuid import uuid4
|
|
||||||
import stravalib
|
import stravalib
|
||||||
from stravalib.exc import ActivityUploadFailed,TimeoutExceeded
|
from stravalib.exc import ActivityUploadFailed,TimeoutExceeded
|
||||||
import iso8601
|
|
||||||
from iso8601 import ParseError
|
from iso8601 import ParseError
|
||||||
|
|
||||||
import pytz
|
|
||||||
import arrow
|
|
||||||
|
|
||||||
from rowers.tasks import handle_strava_import_stroke_data
|
from rowers.tasks import handle_strava_import_stroke_data
|
||||||
|
|
||||||
from rowsandall_app.settings import C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET, STRAVA_CLIENT_ID, STRAVA_REDIRECT_URI, STRAVA_CLIENT_SECRET
|
from rowsandall_app.settings import (
|
||||||
|
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET,
|
||||||
|
STRAVA_CLIENT_ID, STRAVA_REDIRECT_URI, STRAVA_CLIENT_SECRET
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from json.decoder import JSONDecodeError
|
from json.decoder import JSONDecodeError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
JSONDecodeError = ValueError
|
JSONDecodeError = ValueError
|
||||||
|
|
||||||
|
from rowers.imports import *
|
||||||
from utils import geo_distance,ewmovingaverage
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Exchange access code for long-lived access token
|
# Exchange access code for long-lived access token
|
||||||
def get_token(code):
|
def get_token(code):
|
||||||
|
|||||||
@@ -376,13 +376,12 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
|
rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
|
||||||
except:
|
except:
|
||||||
try:
|
try:
|
||||||
rowdatetime = dateutil.parser.parse(data['start_datetime'])
|
rowdatetime = parser.parse(data['start_datetime'])
|
||||||
rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
|
rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
|
||||||
except:
|
except:
|
||||||
rowdatetime = datetime.strptime(data['date'],"%Y-%m-%d %H:%M:%S")
|
rowdatetime = datetime.strptime(data['date'],"%Y-%m-%d %H:%M:%S")
|
||||||
rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
|
rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
|
||||||
starttimeunix = arrow.get(rowdatetime).timestamp
|
starttimeunix = arrow.get(rowdatetime).timestamp
|
||||||
#starttimeunix = mktime(rowdatetime.utctimetuple())
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user