Private
Public Access
1
0

further code refactoring

This commit is contained in:
Sander Roosendaal
2018-06-26 21:43:57 +02:00
parent cff1626603
commit e0dd903d68
6 changed files with 21 additions and 175 deletions

View File

@@ -3,45 +3,15 @@
# (There is still some stuff defined directly in views.py. Need to
# move that here.)
# Python
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
from rowers.imports import *
# 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 utils import myqueue,uniqify,isprorower, custom_exception_handler, NoTokenError
from uuid import uuid4
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
import django_rq

View File

@@ -33,7 +33,7 @@ from django.contrib.auth.decorators import login_required
# Project
# from .models import Profile
from rowingdata import rowingdata
from rowingdata import rowingdata, make_cumvalues
import pandas as pd
from rowers.models import Rower,Workout,checkworkoutuser
from rowers import types

View File

@@ -1,47 +1,12 @@
# 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 (
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET,
STRAVA_CLIENT_ID, STRAVA_REDIRECT_URI, STRAVA_CLIENT_SECRET,
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):
t = []
@@ -63,7 +28,6 @@ def splitrunkeeperdata(lijst,xname,yname):
return [np.array(x),np.array(y)]
import dataprep
# Checks if user has SportTracks token, renews them if they are expired
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)
except ValueError:
try:
rowdatetime = dateutil.parser.parse(data['start_time'])
rowdatetime = parser.parse(data['start_time'])
#rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
except:
rowdatetime = datetime.strptime(data['date'],"%Y-%m-%d %H:%M:%S")

View File

@@ -1,58 +1,12 @@
# All the functionality to connect to SportTracks
# 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
import math
from math import sin,cos,atan2,sqrt
from rowers.imports import *
import urllib
import c2stuff
import pytz
import iso8601
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)]
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
)
# Checks if user has SportTracks token, renews them if they are expired

View File

@@ -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
queue = django_rq.get_queue('default')
queuelow = 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 utils import uniqify,isprorower,myqueue,NoTokenError, custom_exception_handler
from uuid import uuid4
import stravalib
from stravalib.exc import ActivityUploadFailed,TimeoutExceeded
import iso8601
from iso8601 import ParseError
import pytz
import arrow
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:
from json.decoder import JSONDecodeError
except ImportError:
JSONDecodeError = ValueError
from utils import geo_distance,ewmovingaverage
from rowers.imports import *
# Exchange access code for long-lived access token
def get_token(code):

View File

@@ -376,13 +376,12 @@ def add_workout_from_data(user,importid,data,strokedata,
rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
except:
try:
rowdatetime = dateutil.parser.parse(data['start_datetime'])
rowdatetime = parser.parse(data['start_datetime'])
rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
except:
rowdatetime = datetime.strptime(data['date'],"%Y-%m-%d %H:%M:%S")
rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
starttimeunix = arrow.get(rowdatetime).timestamp
#starttimeunix = mktime(rowdatetime.utctimetuple())
try: