diff --git a/rowers/admin.py b/rowers/admin.py index 1cbc67be..b658fcd0 100644 --- a/rowers/admin.py +++ b/rowers/admin.py @@ -5,7 +5,7 @@ from django.contrib.auth.models import User from .models import ( Rower, Workout,GraphImage,FavoriteChart,SiteAnnouncement, Team,TeamInvite,TeamRequest, - WorkoutComment, + WorkoutComment,C2WorldClassAgePerformance, ) # Register your models here so you can use them in the Admin module @@ -26,6 +26,9 @@ class WorkoutAdmin(admin.ModelAdmin): class FavoriteChartAdmin(admin.ModelAdmin): list_display = ('user','xparam','yparam1','yparam2','plottype','workouttype','reststrokes') +class C2WorldClassAgePerformanceAdmin(admin.ModelAdmin): + list_display = ('sex','weightcategory','agemin','agemax','distance','power','name','season') + class SiteAnnouncementAdmin(admin.ModelAdmin): list_display = ('announcement','created','modified','expires','dotweet') @@ -51,3 +54,5 @@ admin.site.register(SiteAnnouncement,SiteAnnouncementAdmin) admin.site.register(TeamInvite,TeamInviteAdmin) admin.site.register(TeamRequest,TeamRequestAdmin) admin.site.register(WorkoutComment,WorkoutCommentAdmin) +admin.site.register(C2WorldClassAgePerformance, + C2WorldClassAgePerformanceAdmin) diff --git a/rowers/models.py b/rowers/models.py index 2fa222f5..2fa57a5c 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -21,6 +21,8 @@ from sqlalchemy import create_engine import sqlalchemy as sa from sqlite3 import OperationalError from django.utils import timezone +import pandas as pd +from dateutil import parser import datetime from django.core.exceptions import ValidationError from rowers.rows import validate_file_extension @@ -149,6 +151,75 @@ class PowerZonesField(models.TextField): value = self._get_val_from_obj(obj) return self.get_deb_prep_value(value) +# Age records +def save_agegroup(df,weightcategory,sex): + for id,row in df.iterrows(): + agemin = int(row['Age2']) + agemax = int(row['Age3']) + duration = row['Time'] + power = int(row['Power']) + season = int(row['Season']) + name = row['Name'] + record = C2WorldClassAgePerformance( + agemin = agemin, + agemax = agemax, + weightcategory = weightcategory, + sex=sex, + distance = 2000, + duration = duration, + power = power, + season = season, + name = name, + ) + record.save() + print record + +def make_records(readfile): + xls = pd.ExcelFile(readfile) + female_df = xls.parse('Female') + female_lw_df = xls.parse('Female LW') + male_df = xls.parse('Male') + male_lw_df = xls.parse('Male LW') + save_agegroup(female_df,'hwt','female') + save_agegroup(male_df,'hwt','male') + save_agegroup(female_lw_df,'lwt','female') + save_agegroup(female_lw_df,'lwt','male') + + +class C2WorldClassAgePerformance(models.Model): + weightcategories = ( + ('hwt','heavy-weight'), + ('lwt','light-weight'), + ) + + sexcategories = ( + ('male','male'), + ('female','female'), + ) + + weightcategory = models.CharField(default="hwt", + max_length=30, + choices=weightcategories) + + sex = models.CharField(default="female", + max_length=30, + choices=sexcategories) + + agemin = models.IntegerField(default=19,verbose_name="Minimum Age") + agemax = models.IntegerField(default=29,verbose_name="Maximum Age") + + distance = models.IntegerField(default=2000) + name = models.CharField(max_length=200,blank=True) + duration = models.TimeField(default=1,blank=True) + season = models.IntegerField(default=2013) + power = models.IntegerField(default=200) + + class Meta: + unique_together = ('agemin','agemax','sex','weightcategory','distance') + + def __unicode__(self): + return self.name+':'+str(self.agemin)+'-'+str(self.agemax)+' ('+str(self.season)+')' + # For future Team functionality class Team(models.Model): choices = (