Example #1
0
File: app.py Project: cvan/mula
def _generate_csv(precision):
    columns = ['timestamp'] + moods
    lines = [','.join(columns)]

    # Get sorted set in descending order by date.
    runs = redis.zrevrange('runs', 0, -1, 1)

    for run_timestamp, run_key in runs:
        # This is the value of the run which we key off of
        # (e.g., 20130116233651).
        run_key = str(int(run_key))

        line = [run_timestamp]

        for mood in moods:
            try:
                # Get the string of the mood count.
                count = redis.get('runs:%s:moods:%s:%s'
                                  % (run_key, precision, mood))
            except:
                pass
            count = count or 0
            line.append(str(count))

        lines.append(','.join(line))

    return '\n'.join(lines)
Example #2
0
File: app.py Project: cvan/mula
def _generate_html(precision):
    runs = []

    # Get sorted set in descending order by date.
    stored_runs = redis.zrevrange('runs', 0, -1, 1)

    for run_timestamp, run_key in stored_runs:
        # This is the value of the run which we key off of (e.g., 20130116233651).
        run_key = str(int(run_key))

        run = {'timestamp': run_timestamp, 'counts': []}

        for mood in moods:
            try:
                # Get the string of the mood count.
                count = redis.get('runs:%s:moods:%s:%s'
                                  % (run_key, precision, mood))
            except:
                # Maybe this key is not a set - or some other error occurred.
                pass
            count = count or 0
            run['counts'].append(int(count))

        for total in totals:
            try:
                # Get the string of the tally count.
                count = redis.get('runs:%s:totals:%s:%s'
                                  % (run_key, precision, total))
            except:
                # Maybe this key is not a set - or some other error occurred.
                pass
            count = count or 0
            run['counts'].append(int(count))

        runs.append(run)

    return {
        'precision': precision,
        'moods': moods,
        'totals': totals,
        'runs': runs
    }