def format_json(days_in_past, totals):
    sum_all = 0
    key = None

    source_vals = {}

    if (days_in_past):
        key = "Last %d day(s)" % days_in_past
    else:
        key = "All time"
    for total in totals:
        source_vals[total['_id']] = total['totalItems']
        sum_all = sum_all + total['totalItems']

    source_vals['TOTAL'] = sum_all

    return key, source_vals
dataset/ETHPy150Open fictivekin/openrecipes/scripts/mongo_stats.py/format_json/original