more foundation work for scoring
This commit is contained in:
@@ -11,7 +11,7 @@ from .models import (
|
|||||||
Team,TeamInvite,TeamRequest,
|
Team,TeamInvite,TeamRequest,
|
||||||
WorkoutComment,C2WorldClassAgePerformance,PlannedSession,
|
WorkoutComment,C2WorldClassAgePerformance,PlannedSession,
|
||||||
GeoCourse,GeoPolygon,GeoPoint,VirtualRace,VirtualRaceResult,
|
GeoCourse,GeoPolygon,GeoPoint,VirtualRace,VirtualRaceResult,
|
||||||
PaidPlan,IndoorVirtualRaceResult,ShareKey
|
PaidPlan,IndoorVirtualRaceResult,ShareKey, CourseStandard,StandardCollection,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Register your models here so you can use them in the Admin module
|
# Register your models here so you can use them in the Admin module
|
||||||
@@ -141,6 +141,12 @@ class IndoorVirtualRaceResultAdmin(admin.ModelAdmin):
|
|||||||
class PaidPlanAdmin(admin.ModelAdmin):
|
class PaidPlanAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name','shortname','price','paymenttype','paymentprocessor','external_id')
|
list_display = ('name','shortname','price','paymenttype','paymentprocessor','external_id')
|
||||||
|
|
||||||
|
class StandardCollectionAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ('name','manager')
|
||||||
|
|
||||||
|
class CourseStandardAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ('name','standardcollection')
|
||||||
|
|
||||||
admin.site.unregister(User)
|
admin.site.unregister(User)
|
||||||
admin.site.register(User,UserAdmin)
|
admin.site.register(User,UserAdmin)
|
||||||
admin.site.register(Workout,WorkoutAdmin)
|
admin.site.register(Workout,WorkoutAdmin)
|
||||||
@@ -160,3 +166,5 @@ admin.site.register(VirtualRaceResult, VirtualRaceResultAdmin)
|
|||||||
admin.site.register(IndoorVirtualRaceResult, IndoorVirtualRaceResultAdmin)
|
admin.site.register(IndoorVirtualRaceResult, IndoorVirtualRaceResultAdmin)
|
||||||
admin.site.register(PaidPlan,PaidPlanAdmin)
|
admin.site.register(PaidPlan,PaidPlanAdmin)
|
||||||
admin.site.register(ShareKey,ShareKeyAdmin)
|
admin.site.register(ShareKey,ShareKeyAdmin)
|
||||||
|
admin.site.register(CourseStandard,CourseStandardAdmin)
|
||||||
|
admin.site.register(StandardCollection,StandardCollectionAdmin)
|
||||||
|
|||||||
@@ -2,6 +2,11 @@ from __future__ import absolute_import
|
|||||||
from __future__ import division
|
from __future__ import division
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# low level methods
|
# low level methods
|
||||||
def coordinate_in_path(latitude,longitude, p):
|
def coordinate_in_path(latitude,longitude, p):
|
||||||
|
|
||||||
|
|||||||
@@ -2196,6 +2196,10 @@ from django.core.validators import RegexValidator,validate_email
|
|||||||
|
|
||||||
class StandardCollection(models.Model):
|
class StandardCollection(models.Model):
|
||||||
name = models.CharField(max_length=150)
|
name = models.CharField(max_length=150)
|
||||||
|
manager = models.ForeignKey(User, null=True,on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
class CourseStandard(models.Model):
|
class CourseStandard(models.Model):
|
||||||
name = models.CharField(max_length=150)
|
name = models.CharField(max_length=150)
|
||||||
@@ -2211,6 +2215,14 @@ class CourseStandard(models.Model):
|
|||||||
skillclass = models.CharField(max_length=150)
|
skillclass = models.CharField(max_length=150)
|
||||||
standardcollection = models.ForeignKey(StandardCollection,on_delete=models.CASCADE)
|
standardcollection = models.ForeignKey(StandardCollection,on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unique_together = ('name','sex','agemin',
|
||||||
|
'agemax','boatclass','boattype','weightclass','adaptiveclass',
|
||||||
|
'skillclass','standardcollection')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
registerchoices = (
|
registerchoices = (
|
||||||
('windowstart','Start of challenge Window'),
|
('windowstart','Start of challenge Window'),
|
||||||
('windowend','End of challenge Window'),
|
('windowend','End of challenge Window'),
|
||||||
|
|||||||
102
rowers/scoring.py
Normal file
102
rowers/scoring.py
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
from rowers.models import StandardCollection,CourseStandard
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
import arrow
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
def save_scoring(name,user,filename,id=0):
|
||||||
|
if id==0:
|
||||||
|
collection = StandardCollection(name=name,manager=user)
|
||||||
|
collection.save()
|
||||||
|
standards = CourseStandard.objects.filter(standardcollection=collection)
|
||||||
|
for standard in standards:
|
||||||
|
standard.delete()
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
collection = StandardCollection.objects.get(id=id)
|
||||||
|
collection.name = name
|
||||||
|
collection.save()
|
||||||
|
|
||||||
|
except StandardCollection.DoesNotExist:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
df = pd.read_csv(filename)
|
||||||
|
except:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
df = df.drop_duplicates(['Name'])
|
||||||
|
|
||||||
|
for index, row in df.iterrows():
|
||||||
|
try:
|
||||||
|
name = row['Name']
|
||||||
|
except KeyError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
coursedistance = row['CourseDistance']
|
||||||
|
coursetime = row['CourseStandard']
|
||||||
|
t = datetime.datetime.strptime(coursetime,'%M:%S.%f')
|
||||||
|
delta = datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second,microseconds=t.microsecond)
|
||||||
|
seconds = delta.total_seconds()
|
||||||
|
|
||||||
|
coursestandard = coursedistance/seconds
|
||||||
|
except KeyError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
agemin = row['MinAge']
|
||||||
|
agemax = row['MaxAge']
|
||||||
|
agemin = int(agemin)
|
||||||
|
agemax = int(agemax)
|
||||||
|
except KeyError:
|
||||||
|
agemin = 0
|
||||||
|
agemax = 120
|
||||||
|
|
||||||
|
try:
|
||||||
|
boatclass = row['BoatClass']
|
||||||
|
except KeyError:
|
||||||
|
boatclass = 'water'
|
||||||
|
|
||||||
|
try:
|
||||||
|
boattype = row['BoatType']
|
||||||
|
except KeyError:
|
||||||
|
boattype = '1x'
|
||||||
|
|
||||||
|
try:
|
||||||
|
sex = row['Gender']
|
||||||
|
except KeyError:
|
||||||
|
sex = 'F'
|
||||||
|
|
||||||
|
try:
|
||||||
|
weightclass = row['WeightClass']
|
||||||
|
except KeyError:
|
||||||
|
weightclass = 'hwt'
|
||||||
|
|
||||||
|
try:
|
||||||
|
adaptiveclass = row['AdaptiveClass']
|
||||||
|
except KeyError:
|
||||||
|
adaptiveclass = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
skillclass = row['SkillClass']
|
||||||
|
except KeyError:
|
||||||
|
skillclass = 'Open'
|
||||||
|
|
||||||
|
# some testing
|
||||||
|
standard = CourseStandard(
|
||||||
|
name=name,
|
||||||
|
coursedistance=coursedistance,
|
||||||
|
coursestandard=coursestandard,
|
||||||
|
agemin=agemin,
|
||||||
|
agemax=agemax,
|
||||||
|
boatclass=boatclass,
|
||||||
|
boattype=boattype,
|
||||||
|
sex=sex,
|
||||||
|
weightclass=weightclass,
|
||||||
|
adaptiveclass=adaptiveclass,
|
||||||
|
skillclass=skillclass,
|
||||||
|
standardcollection = collection,
|
||||||
|
)
|
||||||
|
|
||||||
|
standard.save()
|
||||||
Reference in New Issue
Block a user