In [570]:
cd /root/git/SolarDataRESTfulAPI/
In [1048]:
import os
print os.system("cd /root/git/SolarDataRESTfulAPI/ && git pull")
reload(IoTtoolkit)
reload(InfluxDBInterface)
Out[1048]:
In [1049]:
import IoTtoolkit
import InfluxDBInterface
import time
In [1050]:
cat influxInterfaceCredentials2.json
In [1051]:
DataLink = InfluxDBInterface.InfluxDBInterface("influxInterfaceCredentials2.json")
LogDB = DataLink.databases[u'SolarLogdata']
ProductionDB = DataLink.databases[u'SolarProductionSites']
AreaDB = DataLink.databases[u'SolarProductionAreas']
Test = DataLink.databases[u'test']
In [1026]:
q= "select Min(Energy) as Energy from e63710a4-78d9-4071-9a2e-ad35534355f4 group by time(1h) where time < '2014-11-24 23:59:00' and time > '2014-11-22' limit 1000"
res = ProductionDB.QueryDf(q,'s')
#ProductionDB.ResultToDataframe(res,'s')
res["Power"] = res["Energy"].diff().shift(-1)
res["Timestamp"] = res.index.to_series()
mydict = {"points":res.to_dict("list")}
mydict["columns"] = list(res.columns)
mydict
In [1031]:
type(df) == pd.DataFrame
Out[1031]:
In [1036]:
type(None)
Out[1036]:
In [927]:
SitesProduction = IoTtoolkit.Feed()
sites = ["46d55815-f927-459f-a8e2-8bbcd88008ee"]
PowerStreams = SitesProduction.CombineStreamsFromMulipleSources("Power",ProductionDB,sites,"Power",Compressed=False)
EnergyStreams = SitesProduction.CombineStreamsFromMulipleSources("Energy",ProductionDB,sites,"Energy",Compressed=True)
SitesProductionBuf = SitesProduction.GetBuffer()
SitesProductionBuf.Size = 5000
In [ ]:
In [928]:
t = time.time()-3600*36
a = SitesProductionBuf.Feed.GetValuesAt(t)
b = SitesProductionBuf.Feed.GetValuesAt(t+3600)
a,b
Out[928]:
In [929]:
rs = SitesProduction.GetResampleBuffer(t0,3600,10)
In [930]:
rs.AddResampleColumn("Power","Energy1",rs.InterpolatePowerFromCounter)
rs.AddResampleColumn("Energy","Energy1",rs.InterpolateCounter)
In [931]:
rs.Interpolate()
Out[931]:
In [1042]:
df.plot()
In [952]:
t0
Out[952]:
In [828]:
def p(y):
print y
In [829]:
a = [p,1,2]
In [830]:
a
Out[830]:
In [831]:
a[0](1)
In [731]:
df.loc[t0,"Test2"]=2
In [851]:
df.iloc[:,1].diff().shift(-1).iloc[1:-1]
Out[851]:
In [845]:
tst.iloc[1:-1]
Out[845]:
In [825]:
rs.Data["Power"] = rs.Data["Energy1"].diff().shift(-1)
In [867]:
s1 = rs.ResampleValues["Energy1"]
s1
Out[867]:
In [865]:
s2 = rs.ResampleTimes["Energy1"]
s2
Out[865]:
In [869]:
(s2 < 3600).replace(False,float("nan")) * s1
Out[869]:
In [870]:
s2
Out[870]:
In [106]:
SitesProductionBuf.Data.index[0]
Out[106]:
In [107]:
SitesProductionBuf.Data.loc[SitesProductionBuf.Data.index[0],"Energy1"] = 0
In [108]:
SitesProductionBuf.Data
Out[108]:
In [109]:
for Value in SitesProductionBuf.Values:
print Value
In [110]:
SitesProductionBuf.Values
Out[110]:
In [112]:
SitesProductionBuf.Values[Value].Timestamp
Out[112]:
In [144]:
t0 = time.time()-3600*22
v0 = SitesProductionBuf.Feed.GetValuesAt(t0)
v0
Out[144]:
In [116]:
Out[116]:
In [117]:
SitesProductionBuf.Feed.DataStreams.columns
Out[117]:
In [120]:
SitesProductionBuf.Data.columns
Out[120]:
In [121]:
pd
In [122]:
import pandas as pd
In [123]:
df = pd.DataFrame(columns = SitesProductionBuf.Feed.DataStreams.columns)
In [125]:
df.loc[pd.MultiIndex,"Power0"] = 1
In [146]:
index = pd.MultiIndex.from_tuples([(1400,1280),(1400,1280),(1400,1290)], names=['ResampleTime', 'Timestamp'])
In [147]:
index
Out[147]:
In [130]:
df.loc[index,"Power0"] = 1
In [135]:
df2 = pd.DataFrame(columns = SitesProductionBuf.Feed.DataStreams.columns,index=index)
In [940]:
import uuid
In [944]:
uuid.uuid1()
Out[944]:
In [946]:
print time.time()
for f in range(1,50):
print uuid.uuid1()
print time.time()
In [142]:
df.append(df2)
Out[142]:
In [141]:
df
Out[141]:
In [145]:
v0
Out[145]:
In [149]:
v0.
Out[149]:
In [150]:
df
Out[150]:
In [154]:
df.index.append(pd.MultiIndex.from_arrays([[1,3]]))
In [155]:
df
Out[155]:
In [165]:
df["Power0"]= 45
In [166]:
df["Power0"]
Out[166]:
In [160]:
In [167]:
df
Out[167]:
In [174]:
df.iloc[0]
Out[174]:
In [175]:
SitesProductionBuf.Feed.DataStreams.
Out[175]:
In [177]:
index
Out[177]:
In [182]:
df2 = pd.DataFrame(columns = SitesProductionBuf.Feed.DataStreams.columns,index=index,data=[34,35])
In [183]:
df2
Out[183]:
In [180]:
df
Out[180]:
In [230]:
index = pd.MultiIndex.from_tuples([(1300,1280)],names=["ResampleTime","Timestamp"])
In [231]:
df3 = pd.DataFrame(index=index)
In [232]:
df3
Out[232]:
In [233]:
df3["C"]=0
In [234]:
df3
Out[234]:
In [227]:
df.join(df3)
Out[227]:
In [228]:
df
Out[228]:
In [229]:
df3
Out[229]:
In [235]:
df
Out[235]:
In [238]:
df["Power0"]=[(1300,1230,1),46]
In [249]:
df.loc[(1300,1280),"Power0"]
Out[249]:
In [247]:
df.sortlevel(
Out[247]:
In [253]:
df["Power0"][(1300,1290)]= 0
In [257]:
ind2 = df.index.append(pd.MultiIndex.from_tuples([(1300,1280)]))
In [258]:
ind2
Out[258]:
In [260]:
ind2.has_duplicates
Out[260]:
In [261]:
ind2.reindex()
In [263]:
ind2.insert(0,(1,2))
Out[263]:
In [264]:
ind2
Out[264]:
In [266]:
df0 = pd.DataFrame()
In [267]:
df0
Out[267]:
In [269]:
df
Out[269]:
In [270]:
df.sort_index()
Out[270]:
In [271]:
pd.version
Out[271]:
In [274]:
df["Power0"]=[(1300,1280),1]
In [297]:
df.loc[(1300,1285),"Power0"]= 23
In [298]:
df
Out[298]:
In [302]:
df.index.compress()
In [302]:
In [303]:
df3
Out[303]:
In [306]:
df
Out[306]:
In [307]:
df2
Out[307]:
In [308]:
df.join(df2)
In [407]:
dfa = pd.DataFrame(index=index,columns=["Power0","Energy1"],data=[[80,34]])
In [315]:
dfa
Out[315]:
In [316]:
df
Out[316]:
In [329]:
df.loc[1500] = [1280,23,23,34]
In [358]:
df
Out[358]:
In [374]:
df.drop(1280,axis=1,inplace = True)
In [355]:
df
Out[355]:
In [356]:
dfa
Out[356]:
In [361]:
type(df.loc[1500])
Out[361]:
In [362]:
dfa = df.loc[1500]
In [363]:
dfa]
Out[363]:
In [367]:
df.sort_index(inplace=True)
In [369]:
df
Out[369]:
In [372]:
df.loc[1600,1280]=1
In [375]:
df
Out[375]:
In [379]:
df.ix[1600,0] = 5
In [382]:
df.xs
In [384]:
index
Out[384]:
In [386]:
df2
Out[386]:
In [387]:
Out[387]:
In [393]:
df.join(df3,how="outer")
Out[393]:
In [394]:
df3
Out[394]:
In [391]:
df2
Out[391]:
In [400]:
df.drop(1600,inplace=True)
In [401]:
df
Out[401]:
In [403]:
df3
Out[403]:
In [404]:
df2
Out[404]:
In [405]:
df
Out[405]:
In [408]:
dfa
Out[408]:
In [414]:
dfa.loc[(1300,1280)]=float("nan")
dfa
Out[414]:
In [418]:
df.join(dfa)
In [417]:
Out[417]:
In [487]:
re = 1400
ts = 1390
In [488]:
Names = ["ResampleTime","Timestamp"]
In [489]:
index2 = pd.MultiIndex.from_tuples([(re,ts)],names = Names)
In [497]:
df2 = pd.DataFrame(index=index2)
In [498]:
Name="Energy"
In [500]:
df2[Name]=56
In [501]:
df2
Out[501]:
In [459]:
df.loc[1400,"1380"]=4
In [460]:
df
Out[460]:
In [461]:
df.drop("1385",axis=1,inplace=True)
In [463]:
df
Out[463]:
In [471]:
df = df.sort()
In [475]:
df
Out[475]:
In [492]:
index
Out[492]:
In [493]:
index2
Out[493]:
In [496]:
df.index = df.index.append(index2)
In [495]:
df.index
Out[495]:
In [501]:
In [502]:
df2
Out[502]:
In [505]:
df2.index
Out[505]:
In [506]:
df
Out[506]:
In [507]:
df2
Out[507]:
In [515]:
pd.join(df,df2)
In [513]:
df
Out[513]:
In [514]:
df2
Out[514]:
In [518]:
pd.merge(df,df2,left_index=True, right_index=True)
Out[518]:
In [520]:
pd.concat([df,df2,df])
Out[520]:
In [529]:
dfx=pd.DataFrame(columns=)
In [532]:
In [528]:
dfx
Out[528]:
In [533]:
dfx.index=dfx["Power0"]
In [534]:
dfx
Out[534]:
In [537]:
dfx
Out[537]:
In [538]:
SitesProductionBuf.Data
Out[538]:
In [539]:
i2= pd.Series(name="time")
In [540]:
dfx= pd.DataFrame(index = i2)
In [554]:
dfx["test"]=1
In [560]:
dfx.loc[123,"test"]=55
In [561]:
dfx
Out[561]:
In [562]:
df3
Out[562]:
In [563]:
df2
Out[563]:
In [568]:
df2.loc[(1400,1380),"Energy"] = 4
In [569]:
df2
Out[569]:
In [1046]:
SitesProductionBuf.Data
Out[1046]:
In [1047]:
ProdutionDB
In [1052]:
____________________
********************
select Min(Energy) as Energy from 32383bde-7648-4abe-9dac-44701eabd72f group by time(1h) where time < '2014-11-30 22:59:00' and time > '2014-10-31 23:00:00' limit 1000
____________________
In [1053]:
ProdutionDB
In [1055]:
d55=ProductionDB.QueryDf("select Min(Energy) as Energy from 32383bde-7648-4abe-9dac-44701eabd72f group by time(1h) where time < '2014-11-30 22:59:00' and time > '2014-10-31 23:00:00' limit 1000","m")
In [1056]:
d55.index.max()
Out[1056]:
In [1059]:
df.shape[0]
Out[1059]:
In [1063]:
df["Energy"].diff()/2
Out[1063]:
In [ ]: