News Examples Installation SourceForge.net project page Doxygen Pydoc Epydoc

2008-03-22-multiple-timeseries

models.py

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
 
 

views.py

from django.shortcuts import render_to_response
from dataplot.soccer import models
 
def plots(request):
    return render_to_response(
        'soccer/plots.html',{'plot':models.Player.objects.multi_time_series})
 

template.html

{{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