In [1]:
import sys
sys.path.append('../..')

import disaggregator as da
from pandas.tseries.offsets import DateOffset
import numpy as np

Create dataset adapter


In [2]:
db_url = "postgresql://USERNAME:PASSWORD@db.wiki-energy.org:5432/postgres"
psda = da.PecanStreetDatasetAdapter(db_url)

Get data ids


In [3]:
dataids = psda.get_unique_dataids("curated",2013,1,group=1)
print dataids


[5949, 2158, 5785, 9737, 7989, 2156, 9654, 2829, 6941, 5746, 9932, 5395, 8197, 9934, 9923, 1334, 1697, 9160, 6673, 7731, 4031, 9937, 8669, 1714, 936]

Choose one (say 7989), and get some data for jan, feb 2013.


In [4]:
jan_traces = psda.get_month_traces("curated",2013,1,7989,group=1)
feb_traces = psda.get_month_traces("curated",2013,2,7989,group=1)
mar_traces = psda.get_month_traces("curated",2013,3,7989,group=1)

Concatenate traces


In [5]:
all_traces = da.concatenate_traces_lists([jan_traces,feb_traces,mar_traces])
all_traces[0].series


Out[5]:
time
2013-01-01 12:00:00+00:00    0.050
2013-01-01 12:15:00+00:00    0.049
2013-01-01 12:30:00+00:00    0.045
2013-01-01 12:45:00+00:00    0.042
2013-01-01 13:00:00+00:00    0.042
2013-01-01 13:15:00+00:00    0.042
2013-01-01 13:30:00+00:00    0.042
2013-01-01 13:45:00+00:00    0.042
2013-01-01 14:00:00+00:00    0.042
2013-01-01 14:15:00+00:00    0.042
2013-01-01 14:30:00+00:00    0.042
2013-01-01 14:45:00+00:00    0.042
2013-01-01 15:00:00+00:00    0.042
2013-01-01 15:15:00+00:00    0.042
2013-01-01 15:30:00+00:00    0.042
...
2013-04-01 07:15:00+00:00    0.004
2013-04-01 07:30:00+00:00    0.004
2013-04-01 07:45:00+00:00    0.000
2013-04-01 08:00:00+00:00    0.000
2013-04-01 08:15:00+00:00    0.004
2013-04-01 08:30:00+00:00    0.000
2013-04-01 08:45:00+00:00    0.000
2013-04-01 09:00:00+00:00    0.004
2013-04-01 09:15:00+00:00    0.000
2013-04-01 09:30:00+00:00    0.000
2013-04-01 09:45:00+00:00    0.000
2013-04-01 10:00:00+00:00    0.000
2013-04-01 10:15:00+00:00    0.000
2013-04-01 10:30:00+00:00    0.006
2013-04-01 10:45:00+00:00    0.007
Name: air1, Length: 8640, dtype: object

Make instances from the traces


In [6]:
instances = [da.ApplianceInstance([trace],{"name":trace.series.name}) for trace in all_traces]

Make sets from the instances


In [7]:
set_7989 = da.ApplianceSet(instances,{"name": "full house 7989"})
set_7989.df.columns


Out[7]:
Index([u'air1', u'air2', u'air3', u'airwindowunit1', u'aquarium1', u'bathroom1', u'bathroom2', u'bedroom1', u'bedroom2', u'bedroom3', u'bedroom4', u'bedroom5', u'car1', u'clotheswasher1', u'clotheswasher_dryg1', u'diningroom1', u'diningroom2', u'dishwasher1', u'disposal1', u'drye1', u'dryg1', u'freezer1', u'furnace1', u'furnace2', u'garage1', u'garage2', u'heater1', u'housefan1', u'icemaker1', u'jacuzzi1', u'kitchen1', u'kitchen2', u'kitchenapp1', u'kitchenapp2', u'lights_plugs1', u'lights_plugs2', u'lights_plugs3', u'lights_plugs4', u'lights_plugs5', u'lights_plugs6', u'livingroom1', u'livingroom2', u'microwave1', u'office1', u'outsidelights_plugs1', u'outsidelights_plugs2', u'oven1', u'oven2', u'pool1', u'pool2', u'poollight1', u'poolpump1', u'pump1', u'range1', u'refrigerator1', u'refrigerator2', u'security1', u'shed1', u'sprinkler1', u'subpanel1', u'subpanel2', u'unknown1', u'unknown2', u'unknown3', u'unknown4', u'use', u'utilityroom1', u'venthood1', u'waterheater1', u'waterheater2', u'winecooler1'], dtype=object)

Get a set with top k appliances


In [8]:
top_5_set = set_7989.top_k_set(5)
top_5_appliance_names = [inst.traces[0].series.name for inst in top_5_set.instances]
print top_5_appliance_names


[u'use', u'pool2', u'office1', u'drye1', u'furnace1']

In [9]:
non_zero_set = set_7989.non_zero_set()
non_zero_appliance_names = [inst.traces[0].series.name for inst in non_zero_set.instances]
print non_zero_appliance_names


[u'use', u'pool2', u'office1', u'drye1', u'furnace1', u'air1', u'microwave1', u'range1', u'pool1']

In [ ]: