In [207]:
import sys
sys.path.append('../../')
import disaggregator
import disaggregator.OakParkDatasetAdapter as opdsa
import disaggregator.appliance as app
import disaggregator.utils as utils
from datetime import datetime
import calendar
In [232]:
reload(disaggregator.appliance)
reload(disaggregator.utils)
reload(disaggregator.OakParkDatasetAdapter)
reload(app)
Out[232]:
In [233]:
reload(opdsa)
Out[233]:
In [106]:
app_set = opdsa.generate_set_by_year_month(2013,4)
In [109]:
app_set.metadata
Out[109]:
In [121]:
db = opdsa.get_db_connection()
homes = opdsa.get_homes(db)
dataids = homes.keys()
In [223]:
homes_traces = opdsa.homes_to_traces(homes)
In [226]:
trace_list = homes_traces.values()
In [231]:
(trace_list[0].series.index.summary())==(trace_list[1].series.index.summary())
Out[231]:
In [234]:
utils.traces_aligned(trace_list)
Out[234]:
In [128]:
complete_homes = opdsa.get_list_of_homes_with_certain_year_month(homes_traces,2013,4)
In [158]:
homes_traces.keys['']
Out[158]:
In [219]:
year = 2013
month = 4
new_dict = {}
for h in complete_homes:
homes_traces[h].series=opdsa.get_home_series_by_year_month(homes_traces[h],year,month)
#print homes_traces[h].series.index.summary()
#print homes_traces[h].series.index[0]
new_dict[h]=homes_traces[h]
instances = [app.ApplianceInstance([t],t.metadata) for t in new_dict.values()]
metadata_set= {'source':'OakPark','dataids':complete_homes}
for i in instances:
print i.traces[0].series.index[0]
app_set = app.ApplianceSet(instances,metadata_set)
In [236]:
t_list = new_dict.values()
In [239]:
utils.traces_aligned(t_list)
Out[239]:
In [3]:
home= homes[dataids[0]]
In [6]:
trace = opdsa.generate_trace_by_dataid(homes,dataids[0])
In [10]:
dt_index = trace.series.index
In [29]:
trace.series.index.searchsorted(datetime(2013, 1, 2))
Out[29]:
In [44]:
year = 2013
month = 1
day = 1
dt_start = datetime(year,month,day)
dt_end = datetime(year,month,calendar.monthrange(year,month)[1])
In [60]:
index_start = trace.series.index.searchsorted(dt_start)
index_end = trace.series.index.searchsorted(dt_end)
print index_end-index_start
In [52]:
test = trace.series[index_start:index_end]
In [56]:
def get_home_series_by_year_month(year,month,trace):
'''
Returns the home's series sliced by year and month.
'''
dt_start = datetime(year,month,1)
dt_end = datetime(year,month,calendar.monthrange(year,month)[1])
index_start = trace.series.index.searchsorted(dt_start)
index_end = trace.series.index.searchsorted(dt_end)
if index_start == 0 or index_end==0:
return -1
else:
return trace.series[index_start:index_end]
In [70]:
def get_list_of_homes_with_certain_month_year(homes,year,month):
'''
Returns a list of homes which have complete trace info for given year and month.
Assumes that homes is dict where keys are dataids and values are traces.
'''
complete_homes = []
for h in homes.keys():
dt_start = datetime(year,month,1)
dt_end = datetime(year,month,calendar.monthrange(year,month)[1])
index_start = homes[h].series.index.searchsorted(dt_start)
index_end = homes[h].series.index.searchsorted(dt_end)
if index_end-index_start==((dt_end-dt_start)*48).days:
complete_homes.append(h)
return complete_homes
In [71]:
get_list_of_homes_with_certain_month_year(hom,2013,6)
Out[71]:
In [62]:
dataids[0]
Out[62]:
In [63]:
hom = {'3923':trace}
In [ ]:
In [ ]: