if error != 0: continue # grab daily energy, if empty drop through loop daily_energy, error = og.get_daily_energy_for_circuit_id(c["circuit_id"], date_start, date_end) # if daily_energy == None: if error != 0: continue # shift daily_energy index by one to line up better import pandas as p daily_energy = daily_energy.shift(1, offset=p.DateOffset(days=1)) # get hourly credit credit = og.get_credit_for_circuit_id(c["circuit_id"], date_start, date_end) # plot each circuit daily energy values for all time f, ax = plt.subplots(4, 1, sharex=True, figsize=(8, 12)) # plot energy on axis 0 # ax[0].plot_date(daily_energy.index, daily_energy.values, mfc='#dddddd', ms=15) ax[0].plot_date(hourly_energy.index, hourly_energy.values, "ko-") ax[0].set_xlabel("Date") ax[0].set_ylabel("Daily Watthours") ax[0].set_xlim((date_start, date_end)) ax[0].set_title(filename) # plot credit on axis 1 ax[1].plot_date(credit.index, credit.values, "ko-") ax[1].set_ylabel("Credit Balance (XFCA)")
circuit_dict_list = og.get_circuit_dict_list() # place time series for credit of each pin in a dictionary d = {} for i, c in enumerate(circuit_dict_list): if not filter_by_meter_list or c['meter_name'] in meter_list: # generate appropriate dictionary key if method == 'meter': label = c['meter_name'] + '-' + c['ip_address'][-2:] if method == 'pin': label = c['pin'] # query database and append to dictionary print 'querying for', i, 'th circuit =', label credit = og.get_credit_for_circuit_id(c['circuit_id'], date_start, date_end) sampled_credit = credit[[True if i.hour == 0 else False for i in credit.index]] d[label] = sampled_credit # assemble dictionary into dataframe import pandas as p df = p.DataFrame(d) # transpose dataframe and output to CSV filename = 'credit_daily_' + str(date_start.year) + '-' + str(date_start.month) filename += '_' + method + '.csv' df.T.to_csv(filename)
cred_DF = pd.DataFrame(index = datelist) # Populate the list of all circuits and mains # AND populate dictionary to translate string name to number name for ix, row in enumerate(cl): circ_list.append(row[1].encode('ascii')+'_'+str(int(row[2][-2:]))) circ_dict[circ_list[ix]] = row[0] # Create a DataFrame of Wh for each main or site for ix, row in enumerate(circ_list): wh_col = gw.get_watthours_for_circuit_id(circ_dict[row], date_start, date_end)[0].apply(np.float32) wh_col.resample('H', how = np.max) # resample options sum, mean, std, max, min, median, first, last, ohlc. wh_col = pd.Series(wh_col, name = row) wh_DF = wh_DF.join(wh_col) cred_col = gw.get_credit_for_circuit_id(circ_dict[row], date_start, date_end).apply(np.float32) cred_col.resample('H', how = np.min) cred_col = pd.Series(cred_col, name = row) cred_DF = cred_DF.join(cred_col) print row wh_DF.to_csv('gw_wh.csv', index_label = 'dates' ) cred_DF.to_csv('gw_cred.csv',index_label = 'dates' )