Ejemplo n.º 1
0
def route_year(ts=3):
    """ A analytics screen to show information about users """

    # this is somewhat klunky
    data = []
    now = datetime.date.today() - datetime.timedelta(days=1)
    for _ in range(12 * ts):
        datestrold = _get_datestr_from_datetime(now)
        now -= datetime.timedelta(days=30)
        datestrnew = _get_datestr_from_datetime(now)
        analytics = db.session.query(Analytic).\
                        filter(Analytic.datestr < datestrold).\
                        filter(Analytic.datestr > datestrnew).\
                        all()

        # sum up all the totals for each day in that month
        cnt = 0
        for analytic in analytics:
            cnt += analytic.cnt
        data.append(int(cnt))

    return render_template('analytics-year.html',
                           category='analytics',
                           labels_months=_get_chart_labels_months(ts)[::-1],
                           data_months=data[::-1])
Ejemplo n.º 2
0
def route_show(firmware_id):
    """ Show firmware information """

    # get details about the firmware
    fw = db.session.query(Firmware).\
            filter(Firmware.firmware_id == firmware_id).\
            first()
    if not fw:
        flash('No firmware matched!', 'danger')
        return redirect(url_for('firmware.route_firmware'))

    # security check
    if not fw.check_acl('@view'):
        flash('Permission denied: Insufficient permissions to view firmware',
              'danger')
        return redirect(url_for('firmware.route_firmware'))

    # get data for the last month or year
    graph_data = []
    graph_labels = None
    if fw.check_acl('@view-analytics') and not fw.do_not_track:
        if fw.timestamp.replace(
                tzinfo=None) > datetime.datetime.today() - datetime.timedelta(
                    days=30):
            datestr = _get_datestr_from_datetime(datetime.date.today() -
                                                 datetime.timedelta(days=31))
            data = db.session.query(AnalyticFirmware.cnt).\
                        filter(AnalyticFirmware.firmware_id == fw.firmware_id).\
                        filter(AnalyticFirmware.datestr > datestr).\
                        order_by(AnalyticFirmware.datestr.desc()).all()
            graph_data = [r[0] for r in data]
            graph_data = graph_data[::-1]
            graph_labels = _get_chart_labels_days(limit=len(data))[::-1]
        else:
            datestr = _get_datestr_from_datetime(datetime.date.today() -
                                                 datetime.timedelta(days=360))
            data = db.session.query(AnalyticFirmware.cnt).\
                        filter(AnalyticFirmware.firmware_id == fw.firmware_id).\
                        filter(AnalyticFirmware.datestr > datestr).\
                        order_by(AnalyticFirmware.datestr.desc()).all()
            # put in month-sized buckets
            for _ in range(12):
                graph_data.append(0)
            cnt = 0
            for res in data:
                graph_data[int(cnt / 30)] += res[0]
                cnt += 1
            graph_data = graph_data[::-1]
            graph_labels = _get_chart_labels_months()[::-1]

    return render_template('firmware-details.html',
                           category='firmware',
                           fw=fw,
                           graph_data=graph_data,
                           graph_labels=graph_labels)