Esempio n. 1
0
def c_chart_view(request):

    #setup
    symbol=request.GET.get('symbol','BTC_ETH')
    i = 0
    charts = []
    chartnames = []
    metas = []
    symbols = Price.objects.values('symbol').distinct().order_by('symbol').values_list('symbol',flat=True)

    #get data
    pts, symbols_that_exist = get_data(request,symbol,'history_classifiertest',ClassifierTest)

    if len(pts) == 0:
      return render_to_response('notfound.html')

    trainer_last_seen = None
    try:
        last_pt = ClassifierTest.objects.filter(type='mock').order_by('-created_on').first()
        is_trainer_running = last_pt.created_on > (get_time() - datetime.timedelta(minutes=int(15)))
        trainer_last_seen = (last_pt.created_on- datetime.timedelta(hours=int(7))).strftime('%a %H:%M')
    except Exception:
        is_trainer_running = False


    meta = {
      'count' : int(round(pts.count(),0)),
      'avg' : round(pts.aggregate(Avg('percent_correct'))['percent_correct__avg'],0),
      'median' : round(median_value(pts,'percent_correct'),0),
      'max' : round(pts.aggregate(Max('percent_correct'))['percent_correct__max'],0),
      'min' : round(pts.aggregate(Min('percent_correct'))['percent_correct__min'],0),
    }

    #get global chart information
    for parameter in ['percent_correct' ,'score']:
      i = i + 1
      cht = get_line_chart(pts,symbol,parameter)
      charts.append(cht)
      options = []
      chartnames.append("container"+str(i))
      metas.append({
        'name' : parameter,
        'container_class' : 'show',
        'class' : "container"+str(i),
        'options' : options,
        })

    # get parameter distribution charts 
    parameters = ['name','datasetinputs','granularity','minutes_back','timedelta_back_in_granularity_increments','time','prediction_size']
    for x_axis in parameters:
        i = i + 1
        cht = get_scatter_chart(pts,x_axis,symbol)
        charts.append(cht)
        options_dict = pts.values(x_axis).annotate(Avg('percent_correct')).annotate(Count('pk'))
        options = [ (x_axis, obj[x_axis], int(round(obj['percent_correct__avg'],0)), int(round(obj['pk__count'],0)) ) for obj in options_dict ]
        options.sort(key=lambda x: x[1])
        the_max = max([option[2] for option in options])
        for k in range(len(options)):
            options[k] = options[k] + (("max" if options[k][2] == the_max else "notmax") + " " + ("warning" if options[k][3] < 5 else "nowarning"),)
        chartnames.append("container"+str(i))
        metas.append({
          'name' : x_axis,
          'container_class' : 'show' if len(options) > 1 else 'noshow',
          'class' : "container"+str(i),
          'options' : options,
          })


    #Step 3: Send the chart object to the template.
    return render_to_response('c_chart.html',{ 
        'pts' : pts.order_by('percent_correct'),
        'ticker' : symbol,
        'symbols' : symbols,
        'meta' : meta, 
        'days_ago' : [1,2,3,4,5,10,15,30], 
        'hours_ago' : [1,2,3,6,12,24], 
        'getparams' : getify(request.GET), 
        'charts': charts, 
        'metas' : metas, 
        'chartnames' : chartnames, 
        'chartnamesstr' : ",".join(chartnames),
        'is_trainer_running' : is_trainer_running, 
        'trainer_last_seen' : trainer_last_seen,
        'symbols_that_exist' : symbols_that_exist,
    })
Esempio n. 2
0
def c_chart_view(request):

    #setup
    symbol = request.GET.get('symbol', 'BTC_ETH')
    i = 0
    charts = []
    chartnames = []
    metas = []
    symbols = Price.objects.values('symbol').distinct().order_by(
        'symbol').values_list('symbol', flat=True)

    #get data
    pts, symbols_that_exist = get_data(request, symbol,
                                       'history_classifiertest',
                                       ClassifierTest)

    if len(pts) == 0:
        return render_to_response('notfound.html')

    trainer_last_seen = None
    try:
        last_pt = ClassifierTest.objects.filter(
            type='mock').order_by('-created_on').first()
        is_trainer_running = last_pt.created_on > (
            get_time() - datetime.timedelta(minutes=int(15)))
        trainer_last_seen = (
            last_pt.created_on -
            datetime.timedelta(hours=int(7))).strftime('%a %H:%M')
    except Exception:
        is_trainer_running = False

    meta = {
        'count':
        int(round(pts.count(), 0)),
        'avg':
        round(
            pts.aggregate(Avg('percent_correct'))['percent_correct__avg'], 0),
        'median':
        round(median_value(pts, 'percent_correct'), 0),
        'max':
        round(
            pts.aggregate(Max('percent_correct'))['percent_correct__max'], 0),
        'min':
        round(
            pts.aggregate(Min('percent_correct'))['percent_correct__min'], 0),
    }

    #get global chart information
    for parameter in ['percent_correct', 'score']:
        i = i + 1
        cht = get_line_chart(pts, symbol, parameter)
        charts.append(cht)
        options = []
        chartnames.append("container" + str(i))
        metas.append({
            'name': parameter,
            'container_class': 'show',
            'class': "container" + str(i),
            'options': options,
        })

    # get parameter distribution charts
    parameters = [
        'name', 'datasetinputs', 'granularity', 'minutes_back',
        'timedelta_back_in_granularity_increments', 'time', 'prediction_size'
    ]
    for x_axis in parameters:
        i = i + 1
        cht = get_scatter_chart(pts, x_axis, symbol)
        charts.append(cht)
        options_dict = pts.values(x_axis).annotate(
            Avg('percent_correct')).annotate(Count('pk'))
        options = [(x_axis, obj[x_axis],
                    int(round(obj['percent_correct__avg'],
                              0)), int(round(obj['pk__count'], 0)))
                   for obj in options_dict]
        options.sort(key=lambda x: x[1])
        the_max = max([option[2] for option in options])
        for k in range(len(options)):
            options[k] = options[k] + (
                ("max" if options[k][2] == the_max else "notmax") + " " +
                ("warning" if options[k][3] < 5 else "nowarning"), )
        chartnames.append("container" + str(i))
        metas.append({
            'name': x_axis,
            'container_class': 'show' if len(options) > 1 else 'noshow',
            'class': "container" + str(i),
            'options': options,
        })

    #Step 3: Send the chart object to the template.
    return render_to_response(
        'c_chart.html', {
            'pts': pts.order_by('percent_correct'),
            'ticker': symbol,
            'symbols': symbols,
            'meta': meta,
            'days_ago': [1, 2, 3, 4, 5, 10, 15, 30],
            'hours_ago': [1, 2, 3, 6, 12, 24],
            'getparams': getify(request.GET),
            'charts': charts,
            'metas': metas,
            'chartnames': chartnames,
            'chartnamesstr': ",".join(chartnames),
            'is_trainer_running': is_trainer_running,
            'trainer_last_seen': trainer_last_seen,
            'symbols_that_exist': symbols_that_exist,
        })