News Examples Installation SourceForge.net project page Doxygen Pydoc Epydoc

2008-03-11-basic-timeseries

models.py

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
 
 
 
 
 

template.html

{{player_instance.win_percent_plot.to_html}}
 
 

List of examples

2008-03-22-multiple-timeseries
2008-03-11-basic-timeseries
2008-03-11-basic-scatterplot
\n\n\n
2008-03-22-multiple-timeseries
2008-03-11-basic-timeseries
2008-03-11-basic-scatterplot
Hosted by SF-Logo