<s> from datetime import date , datetime , time , timedelta <EOL> import sys <EOL> from django . core . management . base import BaseCommand <EOL> from race . models import Run <EOL> from stats . models import Chart <EOL> class Command ( BaseCommand ) : <EOL> help = ( "<STR_LIT>" ) <EOL> def handle ( self , * args , ** options ) : <EOL> yesterday = date . today ( ) - timedelta ( days = <NUM_LIT:1> ) <EOL> daily_chart , created = Chart . objects . get_or_create ( slug = '<STR_LIT>' ) <EOL> overall_chart , created = Chart . objects . get_or_create ( slug = '<STR_LIT>' ) <EOL> self . stdout . write ( "<STR_LIT>" ) <EOL> try : <EOL> first_run_date = Run . objects . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> ] . created_at <EOL> first_run_date = date ( first_run_date . year , first_run_date . month , <EOL> first_run_date . day ) <EOL> except IndexError : <EOL> self . stdout . write ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> days_number = ( yesterday - first_run_date ) . days + <NUM_LIT:1> <EOL> daily_data = [ ] <EOL> overall_data = [ ] <EOL> for i in xrange ( days_number ) : <EOL> that_day = first_run_date + timedelta ( days = i ) <EOL> runs_that_day = Run . objects . filter ( created_at__range = <EOL> ( datetime . combine ( that_day , time . min ) , <EOL> datetime . combine ( that_day , time . max ) ) ) . count ( ) <EOL> runs_to_that_day = Run . objects . filter ( created_at__lte = <EOL> that_day ) . count ( ) <EOL> daily_data . append ( ( that_day , runs_that_day ) ) <EOL> overall_data . append ( ( that_day , runs_to_that_day ) ) <EOL> daily_chart . data = daily_data <EOL> daily_chart . save ( ) <EOL> overall_chart . data = overall_data <EOL> overall_chart . save ( ) <EOL> self . stdout . write ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:0> ) </s>
