def get_test_data(num_houses): devices_types_unsampled={} ids_for_devices={} db_url='postgresql://*****:*****@db.wiki-energy.org:5432/postgres' psda.set_url(db_url) schema = 'shared' tables= psda.get_table_names(schema) print tables table=tables[3] ids_device_name='air1' ids_for_devices[ids_device_name]=psda.get_dataids_with_real_values(schema,table,ids_device_name) device_name='air1' devices_types_unsampled[device_name]=psda.generate_type_for_appliance_by_dataids(schema,table,device_name,ids_for_devices[ids_device_name][:num_houses]) device_name='use' devices_types_unsampled[device_name]=psda.generate_type_for_appliance_by_dataids(schema,table,device_name,ids_for_devices[ids_device_name][:num_houses]) #Resamples the data devices_types={} devices_types_unsplit={} sample_rate='1T' length='D' for key in devices_types_unsampled: devices_types_unsplit[key]=devices_types_unsampled[key].resample(sample_rate) #devices_types[key]=devices_types_unsplit[key].split_by(length) devices_types[key]=devices_types_unsplit[key] print "Resampled " + str(key) return devices_types
def get_type_from_dataset(device_name,schema,table_num,limit=0): ''' Given the device name ''' devices_types={} devices_types_unsampled={} db_url='postgresql://*****:*****@db.wiki-energy.org:5432/postgres' psda.set_url(db_url) table='group1_disaggregated_2013_0'+str(table_num) ids_for_device=psda.get_dataids_with_real_values(schema,table,device_name) if(limit>len(ids_for_device) or limit==0): limit=len(ids_for_device) device_type_orig=psda.generate_type_for_appliance_by_dataids(schema, table,device_name,ids_for_device[:limit]) return device_type_orig
def get_type_from_dataset(device_name, table_num, limit=0): """ Given the device name """ devices_types = {} devices_types_unsampled = {} db_url = "postgresql://*****:*****@db.wiki-energy.org:5432/postgres" psda.set_url(db_url) schema = "shared" table = "validated_0" + str(table_num) + "_2014" ids_for_device = psda.get_dataids_with_real_values(schema, table, device_name) if limit > len(ids_for_device) or limit == 0: limit = len(ids_for_device) device_type_orig = psda.generate_type_for_appliance_by_dataids(schema, table, device_name, ids_for_device[:limit]) return device_type_orig
def get_type_from_dataset(device_name, schema, table_num, limit=0): ''' Given the device name ''' devices_types = {} devices_types_unsampled = {} db_url = 'postgresql://*****:*****@db.wiki-energy.org:5432/postgres' psda.set_url(db_url) table = 'group1_disaggregated_2013_0' + str(table_num) ids_for_device = psda.get_dataids_with_real_values(schema, table, device_name) if (limit > len(ids_for_device) or limit == 0): limit = len(ids_for_device) device_type_orig = psda.generate_type_for_appliance_by_dataids( schema, table, device_name, ids_for_device[:limit]) return device_type_orig
def get_test_data(num_houses): devices_types_unsampled = {} ids_for_devices = {} db_url = 'postgresql://*****:*****@db.wiki-energy.org:5432/postgres' psda.set_url(db_url) schema = 'shared' tables = psda.get_table_names(schema) print tables table = tables[3] ids_device_name = 'air1' ids_for_devices[ids_device_name] = psda.get_dataids_with_real_values( schema, table, ids_device_name) device_name = 'air1' devices_types_unsampled[ device_name] = psda.generate_type_for_appliance_by_dataids( schema, table, device_name, ids_for_devices[ids_device_name][:num_houses]) device_name = 'use' devices_types_unsampled[ device_name] = psda.generate_type_for_appliance_by_dataids( schema, table, device_name, ids_for_devices[ids_device_name][:num_houses]) #Resamples the data devices_types = {} devices_types_unsplit = {} sample_rate = '1T' length = 'D' for key in devices_types_unsampled: devices_types_unsplit[key] = devices_types_unsampled[key].resample( sample_rate) #devices_types[key]=devices_types_unsplit[key].split_by(length) devices_types[key] = devices_types_unsplit[key] print "Resampled " + str(key) return devices_types
tables = [u'validated_01_2014', u'validated_02_2014', u'validated_03_2014', u'validated_04_2014', u'validated_05_2014',] db_url = "postgresql://*****:*****@db.wiki-energy.org:5432/postgres" psda.set_url(db_url) window_length = 10 window_stride = 1 prediction_index = 6 all_ids = [] for month in range(5): air1_ids = psda.get_dataids_with_real_values(schema,tables[month],'air1') furnace1_ids = psda.get_dataids_with_real_values(schema,tables[month],'furnace1') all_ids.append(air1_ids) all_ids.append(furnace1_ids) common_ids = da.utils.get_common_ids(all_ids) n = len(common_ids) n_train = n/2 n_valid = n/4 n_test = n - (n/2 + n/4) train_ids = common_ids[:n_train] valid_ids = common_ids[n_train:n_train+n_valid] test_ids = common_ids[n_train+n_valid:n_train+n_valid+n_test] for ids,which in zip([train_ids,valid_ids,test_ids],["train","test","valid"]): create_dataset(schema,tables[:5],ids,20,which)
import sys import os.path sys.path.append(os.path.join(os.pardir,os.pardir)) import disaggregator as da import disaggregator.PecanStreetDatasetAdapter as psda import argparse parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('appliance') args = parser.parse_args() db_url = "postgresql://*****:*****@db.wiki-energy.org:5432/postgres" psda.set_url(db_url) schema = 'shared' tables = [u'validated_01_2014', u'validated_02_2014', u'validated_03_2014', u'validated_04_2014', u'validated_05_2014',] ids = [] for table in tables: ids.append(psda.get_dataids_with_real_values(schema,table,args.appliance)) print sorted(da.utils.get_common_ids(ids))
u'validated_02_2014', u'validated_03_2014', u'validated_04_2014', u'validated_05_2014', ] db_url = "postgresql:/USERNAME:[email protected]:5432/postgres" psda.set_url(db_url) window_length = 10 window_stride = 1 prediction_index = 6 all_ids = [] for month in range(5): air1_ids = psda.get_dataids_with_real_values(schema, tables[month], 'air1') furnace1_ids = psda.get_dataids_with_real_values( schema, tables[month], 'furnace1') all_ids.append(air1_ids) all_ids.append(furnace1_ids) common_ids = da.utils.get_common_ids(all_ids) #n = len(common_ids) n = 4 n_train = n / 2 n_valid = n / 4 n_test = n - (n / 2 + n / 4) train_ids = common_ids[:n_train] valid_ids = common_ids[n_train:n_train + n_valid] test_ids = common_ids[n_train + n_valid:n_train + n_valid + n_test] n_classes = 10
print '''You can now get trace information per house. You can also see the trace of a particular appliance. However this is the point where you are informed that "seeing" is actually a step that comes after pickling. Do you want to pickle a house? If not you will be asked shortly to pickle a type? Enter yes or no''' boo = raw_input() if str(boo) == 'yes': #house = raw_input('Enter a home id\n') #appliance = raw_input('Enter an appliance name (this is not actually necessary at\this point):') #query = 'select * from {0}.{1} where dataid={2}'.format(schema_names[schema], month,house) #df = p.get_dataframe(query).fillna(0) # temp = p.clean_dataframe(df,schema,[]) # test = p.get_month_traces_per_dataid(schema,month,house) print 'you now have a bunch of appliance traces, one trace for each appliance in a house' print 'here is some information about the first trace ' elif str(boo) == 'no': print 'ok what appliance do you want?' app = str(raw_input()) print 'this step takes quite a while' pecan.set_url(db_url) dataids = pecan.get_dataids_with_real_values(schema, month, app) type = pecan.generate_traces_for_appliance_by_dataids( schema, month, app, dataids) utils.pickle_object(type, '{}_{}'.format(app, month)) else: print 'what was that?'
sys.path.append(os.path.join(os.pardir, os.pardir)) import disaggregator as da import disaggregator.PecanStreetDatasetAdapter as psda import argparse parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('appliance') args = parser.parse_args() db_url = "postgresql://*****:*****@db.wiki-energy.org:5432/postgres" psda.set_url(db_url) schema = 'shared' tables = [ u'validated_01_2014', u'validated_02_2014', u'validated_03_2014', u'validated_04_2014', u'validated_05_2014', ] ids = [] for table in tables: ids.append(psda.get_dataids_with_real_values(schema, table, args.appliance)) print sorted(da.utils.get_common_ids(ids))
#house = raw_input('Enter a home id\n') #appliance = raw_input('Enter an appliance name (this is not actually necessary at\this point):') #query = 'select * from {0}.{1} where dataid={2}'.format(schema_names[schema], month,house) #df = p.get_dataframe(query).fillna(0) # temp = p.clean_dataframe(df,schema,[]) # test = p.get_month_traces_per_dataid(schema,month,house) print 'you now have a bunch of appliance traces, one trace for each appliance in a house' print 'here is some information about the first trace ' elif str(boo)=='no': print 'ok what appliance do you want?' app = str(raw_input()) print 'this step takes quite a while' pecan.set_url(db_url) dataids = pecan.get_dataids_with_real_values(schema,month,app) type = pecan.generate_traces_for_appliance_by_dataids(schema, month,app,dataids) utils.pickle_object(type, '{}_{}'.format(app,month)) else: print 'what was that?'