Beispiel #1
0
def energy_table_mode(request,scope):
    '''
    Generates a data table with the ability to set 'scope'
    Scope refers either to Academic Buildings, Residential Buildings, or All
    Table reports averages over last minute, week, month.
    '''
    data.increase_count(DYNAMIC_TABLE)

    (startTime, junk) = \
        data._generate_start_data( DYNAMIC_START_TIME )

    if SHOW_ACADEMIC:
        snrgrp = data.SENSOR_GROUPS
        if str(scope) == 'academic':
            snrgrp = data.ACADEMIC_SENSORGROUPS
        elif str(scope) == 'residential':
            snrgrp = data.RESIDENTIAL_SENSORGROUPS
        return render_to_response('graph/table_all.html',
                        {'sensor_groups': snrgrp,
                         'data_url': reverse(
                             'energyweb.graph.views.statistics_table_data'
                             ) + '?junk=' + junk,
                         'scope': scope,
                         'dynamic_graph_url': reverse(
                             'energyweb.graph.views.dynamic_graph_mode',
                             kwargs={'scope':scope}),
                         'energy_table_url':reverse(
                             'energyweb.graph.views.energy_table_mode',
                             kwargs={'scope':scope})
                         },
                    context_instance=RequestContext(request))
    else:
        return energy_table(request)    
Beispiel #2
0
def dynamic_graph_mode(request,scope):
    '''
    Generates a dynamic graph with the ability to set 'scope'
    Scope refers either to Academic Buildings, Residential Buildings, or All
    '''
    data.increase_count(DYNAMIC_GRAPH)

    # Get all data from last two hours until now
    (start_date, junk) = \
        data._generate_start_data( DYNAMIC_START_TIME )

    if SHOW_ACADEMIC:        
        return render_to_response('graph/dynamic_all.html',
                {'sensor_groups': data.ACADEMIC_SENSORGROUPS,
                 'data_url': reverse('energyweb.graph.views.dynamic_graph_data',
                                     kwargs={'input_data': start_date}
                                     ) + '?junk=' + junk,
                 'scope':scope,
                 'dynamic_graph_url': reverse(
                    'energyweb.graph.views.dynamic_graph_mode', 
                    kwargs={'scope':scope}),
                 'energy_table_url':reverse(
                    'energyweb.graph.views.energy_table_mode',
                    kwargs={'scope':scope})
                 },
                                  context_instance=RequestContext(request))
    else:
        return dynamic_graph(request)
Beispiel #3
0
def detail_graph(request, building, mode, res):
    '''
    A view returning the HTML for the Detailed Building graph.
    (This graph represents the last three hours and updates
    automatically.)
    '''
    # Increase the viewCount for today
    data.increase_count(DETAILED_VIEW)

    # Get the current date.
    (start_data, junk) = data._generate_start_data( datetime.timedelta(0,0,0) )

    d = {'data_url': reverse('energyweb.graph.views.detail_graph_data', 
                             kwargs={'building': building,
                                     'resolution':res,
                                     'start_time':start_data}) +\
         '?junk=' + junk,
         'table_url': reverse('energyweb.graph.views.detail_table_data', 
                             kwargs={'building': building,
                                     'resolution':res,
                                     'start_time':start_data}) +\
         '?junk=' + junk,
         'building': building.capitalize(),
         'mode': mode,
         'res': res,
         'timedelta_ms': data._dt_to_sec(RESOLUTION_DELTAS[res])*1000,
        }

    # Set the URLs for changing time periods.
    for time_period in ['day','week','month','year']:
        d[time_period+'_url'] = reverse('energyweb.graph.views.detail_graph',
                                        kwargs={'building':building,
                                                'mode':mode,
                                                'res':time_period})
    # Set the URLs for changing modes
    for mode_setting in ['cycle','diagnostic']:
        d[mode_setting+'_url'] = reverse('energyweb.graph.views.detail_graph',
                                        kwargs={'building':building,
                                                'mode':mode_setting,
                                                'res':res})
    # Change Building URLs
    for building in ['south','north','west','east',\
                         'sontag','atwood','case','linde']:
        d[building+'_url'] = reverse('energyweb.graph.views.detail_graph' ,
                                     kwargs={'building':building,
                                             'mode':mode,'res':res})

    return render_to_response('graph/detail_graphs.html',d,
        context_instance=RequestContext(request))
Beispiel #4
0
def energy_table(request):
    '''
    A view returning the HTML for the dynamic table.
    This table holds curr. use (minute avg) and avg of past week/month.
    '''
    data.increase_count(DYNAMIC_TABLE)

    # Get data from three hours ago until now.
    (startTime, junk) = \
                data._generate_start_data( DYNAMIC_START_TIME )

    return render_to_response('graph/energy_table.html', 
        {'sensor_groups': data.SENSOR_GROUPS,
         'data_url': reverse('energyweb.graph.views.statistics_table_data'
                             ) + '?junk=' + junk,
         'scope': 'residential'},
        context_instance=RequestContext(request))
Beispiel #5
0
def dynamic_graph(request):
    '''
    A view returning the HTML for the dynamic (home-page) graph.
    (This graph represents the last two hours and updates
    automatically.)
    '''
    data.increase_count(DYNAMIC_GRAPH)

    # Get all data from last two hours until now
    (start_date, junk) = \
        data._generate_start_data( DYNAMIC_START_TIME )

    return render_to_response('graph/dynamic_graph.html', 
        {'sensor_groups': data.SENSOR_GROUPS,
         'data_url': reverse('energyweb.graph.views.dynamic_graph_data', 
                             kwargs={'input_data': start_date}) +\
             '?junk=' + junk,
         'scope':'residential'},
        context_instance=RequestContext(request))