Menu

[r193]: / trunk / docs / htdocs / examples / 2008-03-22-multiple-timeseries / models.py  Maximize  Restore  History

Download this file

44 lines (35 with data), 1.3 kB

 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
35
36
37
38
39
40
41
42
43
class PlayerManager(models.Manager):
def get_ts_data(self):
return [
dict(P.win_percent_plot_args(),name=P.name)
for P in self.plotable()]
class Player(models.Model):
name=models.CharField(
max_length=100,null=False,blank=True,default='',unique=True)
objects=PlayerManager()
MANAGER_DATAPLOTS=[
(R.multi_time_series,{'get_plot_args':{
'x':'get_ts_data',
'main':"Win percent over time",
'ylab':"Win percent",
'xlab':"Game date",
},'init_args':{'h':9,'w':6.5}}),
]
DATAPLOTS=[
(R.TimeSeries,{'qs':'scores_ordered','attribute':'win_percent_plot',
'get_plot_args':{
'd':'game_seconds',
'y':'win_percent_until_now',
}}),
]
class Score(models.Model):
player=models.ForeignKey(Player)
team=models.ForeignKey(Team)
def game_seconds(self):
return self.team.game.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.