def add_past_usage(raws):

    count = raws.count()
    processed = 0
    print "%s events to be processed" % count
    last_update = datetime.datetime.utcnow()
    for raw in raws:
        json_dict = json.loads(raw.json)
        views.aggregate_usage(raw, json_dict[1])
        processed += 1
        if processed % 50 == 0:
            next_update = last_update + datetime.timedelta(seconds=30)
            if datetime.datetime.utcnow() > next_update:
                m = (processed, count - processed,
                     (float(processed) / count)*100)
                print "%s processed, %s to go, %.2f percent done" % m
                last_update = datetime.datetime.utcnow()
    print "completed processing %s events" % count
dataset/ETHPy150Open openstack/stacktach/migrations/006_populate_rebuilds_from_rawdata.py/add_past_usage/original