<s> import datetime <EOL> import os <EOL> import sys <EOL> try : <EOL> import ujson as json <EOL> except ImportError : <EOL> try : <EOL> import simplejson as json <EOL> except ImportError : <EOL> import json <EOL> POSSIBLE_TOPDIR = os . path . normpath ( os . path . join ( os . path . abspath ( sys . argv [ <NUM_LIT:0> ] ) , <EOL> os . pardir , os . pardir ) ) <EOL> if os . path . exists ( os . path . join ( POSSIBLE_TOPDIR , '<STR_LIT>' ) ) : <EOL> sys . path . insert ( <NUM_LIT:0> , POSSIBLE_TOPDIR ) <EOL> from stacktach import models <EOL> from stacktach import views <EOL> if __name__ != '<STR_LIT:__main__>' : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> REBUILD_START = '<STR_LIT>' <EOL> REBUILD_END = '<STR_LIT>' <EOL> def add_past_usage ( raws ) : <EOL> count = raws . count ( ) <EOL> processed = <NUM_LIT:0> <EOL> print "<STR_LIT>" % count <EOL> last_update = datetime . datetime . utcnow ( ) <EOL> for raw in raws : <EOL> json_dict = json . loads ( raw . json ) <EOL> views . aggregate_usage ( raw , json_dict [ <NUM_LIT:1> ] ) <EOL> processed += <NUM_LIT:1> <EOL> if processed % <NUM_LIT:50> == <NUM_LIT:0> : <EOL> next_update = last_update + datetime . timedelta ( seconds = <NUM_LIT:30> ) <EOL> if datetime . datetime . utcnow ( ) > next_update : <EOL> m = ( processed , count - processed , <EOL> ( float ( processed ) / count ) * <NUM_LIT:100> ) <EOL> print "<STR_LIT>" % m <EOL> last_update = datetime . datetime . utcnow ( ) <EOL> print "<STR_LIT>" % count <EOL> start_raws = models . RawData . objects . filter ( event = REBUILD_START ) <EOL> add_past_usage ( start_raws ) <EOL> end_raws = models . RawData . objects . filter ( event = REBUILD_END ) <EOL> add_past_usage ( end_raws ) </s>
