def execute(self): #Called after User hits GO """ Will output the following: year, aggregated load amounts, and aggregated gas amounts. """ self.out.log("Starting application: longitudinal benchmarking.", logging.INFO) self.out.log("Querying database.", logging.INFO) # Note: Assumes all of the energy data are in a per hour basis. # TODO: The caveat above must be made stronger. Aggregating by summing # only converts, e.g., [kW] to [kWh] for hourly observations. # Similar problem for gas data. # TODO: The query here presumably groups by calendar year. Need to check # whether application actually wants a year's worth of data, looking # backward from most recent observation. # Valid calculation to sum the data by 'year'. load_by_year = self.inp.get_query_sets('load', group_by='year', group_by_aggregation=Sum, exclude={'value': None}, wrap_for_merge=True) gas_by_year = self.inp.get_query_sets('natgas', group_by='year', group_by_aggregation=Sum, exclude={'value': None}, wrap_for_merge=True) merge_load_gas = self.inp.merge(load_by_year, gas_by_year) self.out.log("Getting unit conversions.", logging.INFO) base_topic = self.inp.get_topics() meta_topics = self.inp.get_topics_meta() load_unit = meta_topics['load'][base_topic['load'][0]]['unit'] self.out.log( "Convert loads from [{}] to [kW]; integration will take to [kWh].". format(load_unit), logging.INFO) load_convertfactor = cu.getFactor_powertoKW(load_unit) natgas_unit = meta_topics['natgas'][base_topic['natgas'][0]]['unit'] self.out.log( "Convert natgas from [{}] to [kBtu/hr]; integration will take to [kBtu]." .format(natgas_unit), logging.INFO) natgas_convertfactor = cu.getFactor_powertoKBtu_hr(natgas_unit) self.out.log("Compiling the report table.", logging.INFO) for x in merge_load_gas: self.out.insert_row( 'Longitudinal_BM', { 'year': x['time'].year, 'load': x['load'][0] * load_convertfactor, 'natgas': x['natgas'][0] * natgas_convertfactor })
def execute(self): #Called after User hits GO """ Will output the following: year, aggregated load amounts, and aggregated gas amounts. """ self.out.log("Starting application: longitudinal benchmarking.", logging.INFO) self.out.log("Querying database.", logging.INFO) # Note: Assumes all of the energy data are in a per hour basis. # TODO: The caveat above must be made stronger. Aggregating by summing # only converts, e.g., [kW] to [kWh] for hourly observations. # Similar problem for gas data. # TODO: The query here presumably groups by calendar year. Need to check # whether application actually wants a year's worth of data, looking # backward from most recent observation. # Valid calculation to sum the data by 'year'. load_by_year = self.inp.get_query_sets('load', group_by='year', group_by_aggregation=Sum, exclude={'value':None}, wrap_for_merge=True) gas_by_year = self.inp.get_query_sets('natgas', group_by='year', group_by_aggregation=Sum, exclude={'value':None}, wrap_for_merge=True) merge_load_gas = self.inp.merge(load_by_year, gas_by_year) self.out.log("Getting unit conversions.", logging.INFO) base_topic = self.inp.get_topics() meta_topics = self.inp.get_topics_meta() load_unit = meta_topics['load'][base_topic['load'][0]]['unit'] self.out.log( "Convert loads from [{}] to [kW]; integration will take to [kWh].".format(load_unit), logging.INFO ) load_convertfactor = cu.getFactor_powertoKW(load_unit) natgas_unit = meta_topics['natgas'][base_topic['natgas'][0]]['unit'] self.out.log( "Convert natgas from [{}] to [kBtu/hr]; integration will take to [kBtu].".format(natgas_unit), logging.INFO ) natgas_convertfactor = cu.getFactor_powertoKBtu_hr(natgas_unit) self.out.log("Compiling the report table.", logging.INFO) for x in merge_load_gas: self.out.insert_row('Longitudinal_BM', { 'year': x['time'].year, 'load': x['load'][0]*load_convertfactor, 'natgas': x['natgas'][0]*natgas_convertfactor })
def execute(self): #Called after User hits GO """Outputs the ENERGY Star Score from Target Finder API""" #NOTE: Connection check happens after data is formatted into XML and # sent into the web service request. self.out.log("Starting application: cross-sectional benchmarking.", logging.INFO) self.out.log("Querying the database for model parameters.", logging.INFO) bldgMetaData = dict() bldgMetaData['floor-area'] = self.sq_ft bldgMetaData['year-built'] = self.building_year bldgMetaData['bldg-name'] = self.building_name bldgMetaData['function'] = self.building_function bldgMetaData['zipcode'] = self.building_zipcode self.out.log("Querying the database for most recent year of energy load.", logging.INFO) # NOTE: Hourly values are preferred to make calculations easier. # TODO: The caveat above must be made stronger. Aggregating by summing # only converts, e.g., [kW] to [kWh] for hourly observations. # Similar problem for gas data. # TODO: The query here presumably groups by calendar year. Need to check # whether application actually wants a year's worth of data, looking # backward from most recent observation. load_by_year = self.inp.get_query_sets('load', group_by='year', group_by_aggregation=Sum, exclude={'value':None}, wrap_for_merge=True) gas_by_year = self.inp.get_query_sets('natgas', group_by='year', group_by_aggregation=Sum, exclude={'value':None}, wrap_for_merge=True) merge_load_gas = self.inp.merge(load_by_year, gas_by_year) # Convert the generator to a list that can be indexed. merge_data_list = [] for item in merge_load_gas: merge_data_list.append((item['time'], item['load'][0], item['natgas'][0])) recent_record = merge_data_list[len(merge_data_list)-1] self.out.log("Getting unit conversions.", logging.INFO) base_topic = self.inp.get_topics() meta_topics = self.inp.get_topics_meta() load_unit = meta_topics['load'][base_topic['load'][0]]['unit'] self.out.log( "Convert loads from [{}] to [kW]; integration will take to [kWh].".format(load_unit), logging.INFO ) load_convertfactor = cu.getFactor_powertoKW(load_unit) natgas_unit = meta_topics['natgas'][base_topic['natgas'][0]]['unit'] self.out.log( "Convert natgas from [{}] to [kBtu/hr]; integration will take to [kBtu].".format(natgas_unit), logging.INFO ) natgas_convertfactor = cu.getFactor_powertoKBtu_hr(natgas_unit) #TODO: Convert values to units that are PM Manager valid values. energyUseList = [['Electric','kWh (thousand Watt-hours)',int(recent_record[1]*load_convertfactor)], ['Natural Gas','kBtu (thousand Btu)',int(recent_record[2]*natgas_convertfactor)]] self.out.log("Generate XML-formatted data to pass data to the webservice.", logging.INFO) targetFinder_xml = gen_xml_targetFinder(bldgMetaData,energyUseList,'z_targetFinder_xml') self.out.log("Function that sends a URL Request with ENERGY STAR web server.", logging.INFO) PMMetrics = retrieveScore(targetFinder_xml) self.out.log("Compile report table.", logging.INFO) if PMMetrics['status'] == 'success': self.out.log('Analysis successful', logging.INFO) self.out.insert_row('CrossSectional_BM', { 'Metric Name': 'Target Finder Score', 'Value': str(PMMetrics['designScore'][0]) }) else: self.out.log(str(PMMetrics['status'])+'\nReason:\t'+str(PMMetrics['reason']), logging.WARNING) self.out.insert_row('CrossSectional_BM', { 'Metric Name': 'Target Finder Score', 'Value': 'Check log for error.' })
def execute(self): #Called after User hits GO """Outputs the ENERGY Star Score from Target Finder API""" #NOTE: Connection check happens after data is formatted into XML and # sent into the web service request. self.out.log("Starting application: cross-sectional benchmarking.", logging.INFO) self.out.log("Querying the database for model parameters.", logging.INFO) bldgMetaData = dict() bldgMetaData['floor-area'] = self.sq_ft bldgMetaData['year-built'] = self.building_year bldgMetaData['bldg-name'] = self.building_name bldgMetaData['function'] = self.building_function bldgMetaData['zipcode'] = self.building_zipcode self.out.log( "Querying the database for most recent year of energy load.", logging.INFO) # NOTE: Hourly values are preferred to make calculations easier. # TODO: The caveat above must be made stronger. Aggregating by summing # only converts, e.g., [kW] to [kWh] for hourly observations. # Similar problem for gas data. # TODO: The query here presumably groups by calendar year. Need to check # whether application actually wants a year's worth of data, looking # backward from most recent observation. load_by_year = self.inp.get_query_sets('load', group_by='year', group_by_aggregation=Sum, exclude={'value': None}, wrap_for_merge=True) gas_by_year = self.inp.get_query_sets('natgas', group_by='year', group_by_aggregation=Sum, exclude={'value': None}, wrap_for_merge=True) merge_load_gas = self.inp.merge(load_by_year, gas_by_year) # Convert the generator to a list that can be indexed. merge_data_list = [] for item in merge_load_gas: merge_data_list.append( (item['time'], item['load'][0], item['natgas'][0])) recent_record = merge_data_list[len(merge_data_list) - 1] self.out.log("Getting unit conversions.", logging.INFO) base_topic = self.inp.get_topics() meta_topics = self.inp.get_topics_meta() load_unit = meta_topics['load'][base_topic['load'][0]]['unit'] self.out.log( "Convert loads from [{}] to [kW]; integration will take to [kWh].". format(load_unit), logging.INFO) load_convertfactor = cu.getFactor_powertoKW(load_unit) natgas_unit = meta_topics['natgas'][base_topic['natgas'][0]]['unit'] self.out.log( "Convert natgas from [{}] to [kBtu/hr]; integration will take to [kBtu]." .format(natgas_unit), logging.INFO) natgas_convertfactor = cu.getFactor_powertoKBtu_hr(natgas_unit) #TODO: Convert values to units that are PM Manager valid values. energyUseList = [[ 'Electric', 'kWh (thousand Watt-hours)', int(recent_record[1] * load_convertfactor) ], [ 'Natural Gas', 'kBtu (thousand Btu)', int(recent_record[2] * natgas_convertfactor) ]] self.out.log( "Generate XML-formatted data to pass data to the webservice.", logging.INFO) targetFinder_xml = gen_xml_targetFinder(bldgMetaData, energyUseList, 'z_targetFinder_xml') self.out.log( "Function that sends a URL Request with ENERGY STAR web server.", logging.INFO) PMMetrics = retrieveScore(targetFinder_xml) self.out.log("Compile report table.", logging.INFO) if PMMetrics['status'] == 'success': self.out.log('Analysis successful', logging.INFO) self.out.insert_row( 'CrossSectional_BM', { 'Metric Name': 'Target Finder Score', 'Value': str(PMMetrics['designScore'][0]) }) else: self.out.log( str(PMMetrics['status']) + '\nReason:\t' + str(PMMetrics['reason']), logging.WARNING) self.out.insert_row( 'CrossSectional_BM', { 'Metric Name': 'Target Finder Score', 'Value': 'Check log for error.' })