Menu

[r116]: / trunk / docs / htdocs / examples / 2008-03-11-basic-timeseries / models.py  Maximize  Restore  History

Download this file

36 lines (26 with data), 964 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from dataplot import plotmodels as models
from dataplot import R
class Player(models.Model):
DATAPLOTS=[
(R.TimeSeries,{'qs':'related_scores','attribute':'win_percent_plot',
'get_plot_args':{
'd':'game_seconds',
'y':'win_percent_until_now',
'ylab':'Win percent',
'xlab':'Game date',
'main':'Win percent change over time'
}}),
]
def related_scores(self):
return self.score_set.all()
class Score(models.Model):
player=models.ForeignKey(Player)
team=models.ForeignKey(Team)
def game_seconds(self):
return self.date.strftime("%s")
def win_percent_until_now(self):
qs=self.player.score_set.filter(
team__game__date__lte=self.team.game.date)
wins=qs.filter(team__won__exact=True).count()
games=qs.count()
return float(wins)/games
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.