def update_total_stats_for_report(report_id):
    r = Report.get(Key(report_id))
    stats = StatsStore.get_for_report(report_id)
    if stats:
        s = stats.table_accum(tables_map['Legal Amazon'])
        logging.info("stats for %s" % s)
        if s:
            r.degradation = s['deg']
            r.deforestation = s['def']
            r.put()
    else:
        logging.error("can't find stats for %s" % report_id)
def update_total_stats_for_report(report_id):
    r = Report.get(Key(report_id))
    stats = StatsStore.get_for_report(report_id)
    if stats:
        s = stats.table_accum(tables_map['Legal Amazon'])
        logging.info("stats for %s" % s)
        if s:
            r.degradation = s['deg']
            r.deforestation = s['def']
            r.put()
    else:
        logging.error("can't find stats for %s" % report_id)
def update_report_stats(report_id):
    r = Report.get(Key(report_id))
    stats = {'id': report_id, 'stats': {}}
    for desc, table, name in tables:
        stats['stats'].update(stats_for(str(r.key().id()), r.assetid, table))
        # sleep for some time to avoid problems with FT
        time.sleep(4)

    data = json.dumps(stats)
    s = StatsStore.get_for_report(report_id)
    if s:
        s.json = data
        s.put()
    else:
        StatsStore(report_id=report_id, json=data).put()
    # wait a little bit to allow app store saves the data
    time.sleep(1.0)
    update_total_stats_for_report(report_id)
def update_report_stats(report_id):
    r = Report.get(Key(report_id))
    stats = {
        'id': report_id,
        'stats': {}
    }
    for desc, table, name in tables:
        stats['stats'].update(stats_for(str(r.key().id()), r.assetid, table))
        # sleep for some time to avoid problems with FT 
        time.sleep(4)

    data = json.dumps(stats)
    s = StatsStore.get_for_report(report_id)
    if s:
        s.json = data
        s.put()
    else:
        StatsStore(report_id=report_id, json=data).put()
    # wait a little bit to allow app store saves the data
    time.sleep(1.0)
    update_total_stats_for_report(report_id)