-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblemareascron.py
More file actions
84 lines (65 loc) · 3.01 KB
/
problemareascron.py
File metadata and controls
84 lines (65 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Copyright 2018 Building Energy Gateway. All rights reserved.
import time
import pandas as pd
from building_data_requests import get_bulk
import numbers
import csv
from crontab import CronTab
start_time = time.time()
# Sets values for reference later -- these are the boundaries to identify whether a room is a "problem area"
# Read spreadsheet into a dataframe.
# Each row contains the following:
# - Label
# - Facility
# - Instance ID of CO2 sensor
# - Instance ID of temperature sensor
df = pd.read_csv('/media/ea/Data/Students/jade/buildingEnergyApi/ahs_air.csv', na_filter=False, comment='#' )
# This file location ONLY WORKS ON THE SERVER --> 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 ONLY WORKS ON THE SERVER --->
with open('/media/ea/Data/Students/jade/buildingEnergyApi/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():
# 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
# print(time.asctime())
current_time = time.asctime()
temp_writer.writerow( ['{0},{1},{2},{3},{4},{5}'.format( current_time, row['Label'], temp_value, temp_units, co2_value, co2_units ) ])
#instead of printing, uses writerow method to enter into the csv file
ahs_air_data.close()