def load_uuid_data(): from building_depot import DataService, BDError # load config config = json.load( open('config/data-params.json')) # '../data-params.json' cse_dataservice_url = config["cse_dataservice_url"] bd_username = config["bd_username"] bd_api_key = config["bd_api_key"] remote_sensors = config["remote_sensors"] etl_config = json.load( open('config/etl-params.json')) # '../data-params.json' source_repo = etl_config["source_repo"] repo_name = etl_config["repo_name"] api_fp = etl_config["api_fp"] data_fp = etl_config["data_fp"] #Connect with BuildingDepot ds = DataService(cse_dataservice_url, bd_api_key, bd_username) data = {} for room in list(config["target_rooms_setpoint_values"].keys()) + list( config["uncontrolled_rooms"].keys()): query = {'room': room} resp = ds.list_sensors(query) uuids = { sensor['template']: sensor['uuid'] for sensor in resp['sensors'] if sensor['template'] in remote_sensors } data[room] = uuids print(data)
def load_ion_data_old(): with open('config/bd2_ion_secret.json', 'r') as fp: config = json.load(fp) ds = DataService(config['hostname'], config['apikey'], config['user']) with open('metadata/ebu3b_ion.json', 'r') as fp: ion_srcids = json.load(fp) for srcid, bd_srcid in ion_srcids.items(): uuid = ds.list_sensors({'source_identifier': bd_srcid})['sensors'][0]['uuid'] raw_data = ds.get_timeseries_datapoints(uuid, 'PresentValue', begin_time, end_time) store_data(raw_data, './data/{0}.csv'.format(srcid))
def load_building_data(): with open('config/bd2_secret.json', 'r') as fp: config = json.load(fp) ds = DataService(config['hostname'], config['apikey'], config['user']) with open('metadata/ebu3b_bacnet.json', 'r') as fp: naes = json.load(fp) srcids = [] for nae_num, nae in naes.items(): objs = nae['objs'][1:] srcids += [ '{0}_{1}_{2}'.format(nae_num, obj['props']['type'], obj['props']['instance']) for obj in objs if obj['props']['type'] in [0, 1, 2, 3, 4, 5, 13, 14, 19] ] srcid = '506_0_3000485' nonexisting_srcids = [] for srcid in srcids: uuid = ds.list_sensors({'source_identifier': srcid})['sensors'][0]['uuid'] #end_time = arrow.get(arrow.get().datetime, 'US/Pacific').datetime try: raw_data = ds.get_timeseries_datapoints(uuid, 'PresentValue', begin_time, end_time) except: print('{0} is not found in ds.'.format(srcid)) nonexisting_srcids.append(srcid) continue #data = reduce(updater, raw_data['timeseries'], {}) #series = pd.Series(index=data.keys(), data=list(data.values())) #series.to_csv('./data/{0}.csv'.format(srcid)) store_data(raw_data, './data/{0}.csv'.format(srcid)) with open('nonexisting_srcids.json', 'w') as fp: json.dump(nonexisting_srcids, fp, indent=2)
from datetime import timedelta from building_depot import DataService from pprint import pprint TRYLIMIT = 2 # number of times to attempt actuation on room ACTUATE_SENSOR = 'Actual Sup Flow SP' # sensor to actuate on OBSERVE_SENSOR = 'Actual Supply Flow' # sensor to check for correct response to change in ACTUATE_SENSOR MARGIN_OF_ERROR = 0.95 # minimum (actual/setpoint) value that is considered successful WAIT_TIME = 5 # maximum time in minutes between actuate and observe times to determine that room is successful or failed PT = 'US/Pacific' bd_username = "******" bd_api_key = "313b0b78-7981-45ee-81d4-0fbe87963110" dataservice_url = "https://bd-datas1.ucsd.edu" ds = DataService(dataservice_url, bd_api_key, bd_username) uuids = {} # hold sensor uuids for each room time_actuated = {} # records when each room was actuated # types of sensors being observed templates = { OBSERVE_SENSOR, ACTUATE_SENSOR, } time_format = 'YYYY-MM-DD HH:mm:ss' # preparation of the experiment to obtain the sensor list def obtain_uuid_list(room_list):
def __init__(self): self.bdDS = DataService(authdata.srcUrlBase, authdata.bdApiKey, authdata.bdUserName)
# Logger configuration logger = logging.getLogger("data_collection_log") logger.setLevel(logging.INFO) log_handler = logging.FileHandler('log/data_collection.log') formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') logger.addHandler(log_handler) # BD2-1 Initialization with open("config/bd2-1config.json", "r") as fp: hostname = json.load(fp)['hostname'] with open("config/bd2-1secrets.json", "r") as fp: secrets = json.load(fp) username = secrets['username'] apikey = secrets['apikey'] bd2_1ds = DataService(hostname, apikey, username) # BD2-2 Initialization with open("config/bd2-2config.json", "r") as fp: hostname = json.load(fp)['hostname'] with open("config/bd2-2secrets.json", "r") as fp: secrets = json.load(fp) username = secrets['username'] apikey = secrets['apikey'] bd2_2ds = DataService(hostname, apikey, username) # BD3 Initialization with open("config/bd3config.json", "r") as fp: hostname = json.load(fp)['hostname'] with open("config/bd3secrets.json", "r") as fp: secrets = json.load(fp)