Exemple #1
0
# This file location doesn't work on the server (see above file path) --> be careful

# Initialize empty bulk request
bulk_rq = []

# Iterate over the rows of the dataframe, adding elements to the bulk request
for index, row in df.iterrows():

    # Append facility/instance pairs to bulk request
    if row['Temperature']:
        bulk_rq.append( { 'facility': row['Facility'], 'instance': row['Temperature'] } )
    if row['CO2']:
        bulk_rq.append( { 'facility': row['Facility'], 'instance': row['CO2'] } )

# Issue get-bulk request
bulk_rsp = get_bulk( bulk_rq )

# Extract map from get-bulk response
map = bulk_rsp['rsp_map']

# Output column headings
# print( 'Location,Temperature,Temperature Units,CO2,CO2 Units' )

# writes to a new csv file, so we can use pandas on the real-time data

# this file location ALSO DOESN'T WORK ON THE SERVER ---> add in that path /media/ea/Data/Students/jade/buildingEnergyApi/
with open(SERVER_PATH + 'ahs_air_data.csv', mode='w') as ahs_air_data:
    temp_writer = csv.writer(ahs_air_data, delimiter=";")
    # Iterate over the rows of the dataframe, displaying temperature and CO2 values extracted from map
    for index, row in df.iterrows():
Exemple #2
0
def get_bulk_request_df():
    bulk_rq = []

    # Iterate over the rows of the dataframe, adding elements to the bulk request
    for index, row in rooms_and_sensors.iterrows():

        # Append facility/instance pairs to bulk request
        if row['Temperature']:
            bulk_rq.append({
                'facility': row['Facility'],
                'instance': row['Temperature']
            })
        if row['CO2']:
            bulk_rq.append({
                'facility': row['Facility'],
                'instance': row['CO2']
            })

    # Issue get-bulk request
    try:
        bulk_rsp = get_bulk(bulk_rq)
    except requests.exceptions.ConnectionError:
        raise ConnectionError(
            "Unable to get data from. Are you connected to the right WiFi network?"
        )

    # Extract map from get-bulk response
    map = bulk_rsp['rsp_map']

    df_dictionary = {
        'room': [],
        'temperature': [],
        'temperature units': [],
        'co2': [],
        'co2 units': []
    }

    # Iterate over the rows of the DataFrame, displaying temperature and CO2 values extracted from map
    for index, row in rooms_and_sensors.iterrows():

        # Initialize empty display values
        temp_value = ''
        temp_units = ''
        co2_value = ''
        co2_units = ''

        # Get facility of current row
        facility = row['Facility']

        # Try to extract current row's temperature and CO2 values from map
        if facility in map:

            instance = str(row['Temperature'])
            if instance and (instance in map[facility]):
                rsp = map[facility][instance]
                property = rsp['property']
                temp_value = int(rsp[property]) if isinstance(
                    rsp[property], numbers.Number) else ''
                temp_units = rsp['units']

            instance = str(row['CO2'])
            if instance and (instance in map[facility]):
                rsp = map[facility][instance]
                property = rsp['property']
                co2_value = int(rsp[property]) if isinstance(
                    rsp[property], numbers.Number) else ''
                co2_units = rsp['units']

        # Output CSV format
        df_dictionary['room'].append(row['Label'])
        df_dictionary['temperature'].append(temp_value)
        df_dictionary['temperature units'].append(temp_units)
        df_dictionary['co2'].append(co2_value)
        df_dictionary['co2 units'].append(co2_units)

    return pd.DataFrame.from_dict(df_dictionary)
# Copyright 2018 Building Energy Gateway.  All rights reserved.

import time
import numbers
from building_data_requests import get_bulk
from simple_power_request import request_list

start_time = time.time()

# Issue get-bulk request
bulk_rsp = get_bulk(request_list)

# Extract map from response
response_map = bulk_rsp['rsp_map']

# Iterate through list of requests
for request in request_list:

    # Initialize empty display values
    value = ''
    units = ''

    # Get facility of current request
    facility = request['facility']
    # print( 'facility:', facility )

    # Look for facility in response map
    if facility in response_map:

        # Get instance of current request
        instance = request['instance']
# Copyright 2018 Building Energy Gateway.  All rights reserved.

from building_data_requests import get_bulk

# Build bulk request (rq) structured as a list of dictionaries
# In each dictionary,
# - 'facility' and 'instance' fields are used by get_bulk()
# - 'label' fields are used by us, when printing the response
rq = [  { 'facility': 'ahs', 'instance': '3007360', 'label': 'AHS Main Power' },
        { 'facility': 'ahs', 'instance': '3001489', 'label': 'AHS 351 Temperature' },
        { 'facility': 'ahs', 'instance': '3001477', 'label': 'AHS 351 CO2' }  ]

# Issue the request
bulk_rsp = get_bulk( rq )

# Extract the part of the response that pertains to facility 'ahs'
# It is a dictionary with instances as keys
rsp_instances = bulk_rsp['rsp_map']['ahs']

# Iterate over request; correlate each request item with response data
for rq_item in rq:

    # Get instance from current request item
    instance = rq_item['instance']

    # Extract response data corresponding to the instance
    rsp_instance = rsp_instances[instance]

    # Print label from request item, value and units from response instance
    print( '{0}: {1} {2}'.format( rq_item['label'], int( rsp_instance['presentValue'] ), rsp_instance['units'] ) )
Exemple #5
0
    # Load dataframe representing requested view
    df = pd.read_csv('csv/' + args.view + '.csv', na_filter=False, comment='#')

    # Initialize empty request
    bulk_request = []

    # Build request
    for index, row in df.iterrows():

        # Extract facility from row
        facility = row.iloc[1]

        # Traverse instances in current row
        for i in range(2, len(row)):

            instance = row.iloc[i]

            if instance:

                # Add facility/instance pair to request
                pair = {'facility': facility, 'instance': instance}
                bulk_request.append(pair)

    # Issue get-bulk request
    bulk_rsp = get_bulk(bulk_request, args.hostname, args.port)
    rsp_map = bulk_rsp['rsp_map']

# Return view
print(json.dumps(rsp_map))