Private
Public Access
1
0

defined basic models and some low level functions

This commit is contained in:
Sander Roosendaal
2018-01-26 11:03:00 +01:00
parent bb48cfb96b
commit 92d69087cf
3 changed files with 234 additions and 2 deletions

View File

@@ -643,6 +643,113 @@ timezones = (
(x,x) for x in pytz.common_timezones
)
# models related to geo data (points, polygon, courses)
class GeoCourse(models.Model):
manager = models.ForeignKey(Rower)
name = models.CharField(max_length=150,blank=True)
class GeoPolygon(models.Model):
course = models.ForeignKey(GeoCourse, blank=True)
order_in_course = models.IntegerField(default=0)
# Need error checking to insert new polygons into existing course (all later polygons
# increase there order_in_course number
class GeoPoint(models.Model):
latitude = models.FloatField(default=0)
longitude = models.FloatField(default=0)
polygon = models.ForeignKey(GeoPolygon,blank=True)
order_in_poly = models.IntegerField(default=0)
# need error checking to "insert" new point into existing polygon? This affects order_in_poly
# of multiple GeoPoint instances
# models related to training planning - draft
# Do we need a separate class TestTarget?
class TrainingTarget(models.Model):
rower = models.ForeignKey(Rower)
name = models.CharField(max_length=150,blank=True)
date = models.DateField(
default=timezone.now()+datetime.timedelta(days=182))
notes = models.TextField(max_length=300,blank=True)
# SportTracks has a TrainingGoal like this
#class TrainingGoal(models.Model):
# rower = models.ForeignKey(Rower)
# name = models.CharField(max_length=150,blank=True)
# startdate = models.DateField(default=timezone.now)
# enddate = models.DateField(
# default=timezone.now()+datetime.timedelta(days=28))
# goalmetric = models.CharField(max_length=150,default='rower',
# choices = modechoices)
# value = models.IntegerValue(default=1)
# I think we can use PlannedSession for that (in challenge mode)
# although such a TrainingGoal could have automatically calculated
# values without needing the user to assign
class TrainingPlan(models.Model):
rower = models.ForeignKey(Rower)
name = models.CharField(max_length=150,blank=True)
target = models.ForeignKey(TrainingTarget,blank=True)
startdate = models.DateField(default=timezone.now)
enddate = models.DateField(
default=timezone.now()+datetime.timedelta(days=182))
cycletypechoices = (
('filler','System Defined'),
('userdefined','User Defined')
)
class TrainingMacroCycle(models.Model):
plan = models.ForeignKey(TrainingPlan)
name = models.CharField(max_length=150,blank=True)
startdate = models.DateField(default=timezone.now)
enddate = models.DateField(
default=timezone.now()+datetime.timedelta(days=182))
notes = models.TextField(max_length=300,blank=True)
type = models.CharField(default='filler',
choices=cycletypechoices,
max_length=150)
class TrainingMesoCycle(models.Model):
plan = models.ForeignKey(TrainingMacroCycle)
name = models.CharField(max_length=150,blank=True)
startdate = models.DateField(default=timezone.now)
enddate = models.DateField(
default=timezone.now()+datetime.timedelta(days=182))
notes = models.TextField(max_length=300,blank=True)
type = models.CharField(default='filler',
choices=cycletypechoices,
max_length=150)
class TrainingMicroCycle(models.Model):
plan = models.ForeignKey(TrainingMesoCycle)
name = models.CharField(max_length=150,blank=True)
startdate = models.DateField(default=timezone.now)
enddate = models.DateField(
default=timezone.now()+datetime.timedelta(days=182))
notes = models.TextField(max_length=300,blank=True)
type = models.CharField(default='filler',
choices=cycletypechoices,
max_length=150)
# Needs some error checking
# - Microcycles should not overlap with other microcycles, same for MesoCycles, MacroCycles
# - When a TrainingPlan is created, it should create 1 "collector" Macro, Meso & MicroCycle - this is invisible for users who choose to not use cycles
# - When a new Microcycle is inserted, the "collector" cycle is automatically adjusted to "go out of the way" of the new MicroCycle - and similar for Macro & Meso
# - If the entire MesoCycle is filled with user defined MicroCycles - there are no "filler" MicroCycles
# - Sessions are automatically linked to the correct Cycles based on their start/end date - no need for a hard link
# Cycle error checking goes in forms
# model for Planned Session (Workout, Challenge, Test)
class PlannedSession(models.Model):
@@ -721,7 +828,7 @@ class PlannedSession(models.Model):
max_length=150)
hasranking = models.BooleanField(default=False)
class PlannedSessionForm(ModelForm):
class Meta:
model = PlannedSession
@@ -737,6 +844,19 @@ class PlannedSessionForm(ModelForm):
timezone.now().year-1,timezone.now().year+1)),
}
def __unicode__(self):
name = self.name
startdate = self.startdate
enddate = self.enddate
stri = u'{n} {s} - {e}'.format(
s = startdate.strftime('%Y-%m-%d'),
e = enddate.strftime('%Y-%m-%d'),
n = name,
)
return stri
# Workout
class Workout(models.Model):
@@ -1438,7 +1558,7 @@ class RowerForm(ModelForm):
# optionally sends a tweet to our twitter account
class SiteAnnouncement(models.Model):
created = models.DateField(default=timezone.now)
announcement = models.TextField(max_length=140)
announcement = models.TextField(max_length=280)
expires = models.DateField(default=timezone.now)
modified = models.DateField(default=timezone.now)
dotweet = models.BooleanField(default=False)