analytics/geckoboard_views.py
def geckoboard_line_chart(request):
    """
    Returns the data for a line chart for the specified metric.
    """

    params = get_gecko_params(request, cumulative=False, days_back=7)
    metric = Metric.objects.get(uid=params['uid'])

    start_date = datetime.now()-timedelta(days=params['days_back'])
    stats = [s for s in metric.statistics.filter(frequency=params['frequency'],
        date_time__gte=start_date).order_by('date_time')]

    if len(stats) == 0:
        raise Exception, _("No statistics for metric %(metric)s.") % {'metric': params['uid']}

    dates = [stats[0].date_time]

    # get up to 3 dates from the stats
    if len(stats) >= 3:
        mid = len(stats)/2
        if not mid:
            mid = 1
        dates.extend([stats[mid].date_time, stats[-1].date_time])
    elif len(stats) == 2:
        dates.extend([stats[-1].date_time])

    return (
        [s.count for s in stats],
        dates,
        metric.title,
    )
def geckoboard_line_chart(request):
    params = get_gecko_params(request, cumulative=False, days_back=7)
    metric = Metric.objects.get(uid=params['uid'])

    start_date = datetime.now()-timedelta(days=params['days_back'])
    stats = [s for s in metric.statistics.filter(frequency=params['frequency'],
        date_time__gte=start_date).order_by('date_time')]

    if len(stats) == 0:
        raise Exception, _("No statistics for metric %(metric)s.") % {'metric': params['uid']}

    dates = [stats[0].date_time]

    # get up to 3 dates from the stats
    if len(stats) >= 3:
        mid = len(stats)/2
        if not mid:
            mid = 1
        dates.extend([stats[mid].date_time, stats[-1].date_time])
    elif len(stats) == 2:
        dates.extend([stats[-1].date_time])

    return (
        [s.count for s in stats],
        dates,
        metric.title,
    )
def geckoboard_line_chart ( request ) : params = get_gecko_params ( request , cumulative = False , days_back = 7 ) metric = Metric . objects . get ( uid = params [ 'uid' ] ) start_date = datetime . now ( ) - timedelta ( days = params [ 'days_back' ] ) stats = [ s for s in metric . statistics . filter ( frequency = params [ 'frequency' ] , date_time__gte = start_date ) . order_by ( 'date_time' ) ] if len ( stats ) == 0 : raise Exception , _ ( "No statistics for metric %(metric)s." ) % { 'metric' : params [ 'uid' ] } dates = [ stats [ 0 ] . date_time ] # get up to 3 dates from the stats if len ( stats ) >= 3 : mid = len ( stats ) / 2 if not mid : mid = 1 dates . extend ( [ stats [ mid ] . date_time , stats [ - 1 ] . date_time ] ) elif len ( stats ) == 2 : dates . extend ( [ stats [ - 1 ] . date_time ] ) return ( [ s . count for s in stats ] , dates , metric . title , )
Returns the data for a line chart for the specified metric.
Returns the data for a line chart for the specified metric .