In [1]:
cd git/SolarDataRESTfulAPI/
In [2]:
ls
In [3]:
import json
import pandas as pd
import InfluxDBInterface
import time
reload(InfluxDBInterface)
from ElasticsearchInterface import ESinterface
import IoTtoolkit
#reload(IoTtoolkit)
import sys
import mosquitto
import os
import argparse
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']
es = ESinterface()
def EpocToDate(timestamp):
try:
return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(timestamp))
except:
return "-"
def SecToHMS(sec):
try:
sec = int(sec)
hour = sec / 3600
minutes = (sec - (hour * 3600))/60
secs = sec % 60
return "%i h %i min %i s" %(hour,minutes,secs)
except:
return "-"
In [4]:
def GetRawStatusFrame():
#Sites = LogDB.ListSeries()
res = es.GetHitsAsDataFrame(index="solar-sites-index", doc_type='meta-data')
Sites = res.columns
print "Procssing"
df = pd.DataFrame()
df.index.name = "Sites"
now = time.time() *1000
for site in Sites:
print "*",
df.loc[site,"OpID"] = res[site]["Operator_ID"]
df.loc[site,"LogStart"] = LogDB.GetFirstTimestamp(site)
df.loc[site,"LogStop"] = LogDB.GetLastTimestamp(site)
df.loc[site,"ProdStart"] = ProductionDB.GetFirstTimestamp(site)
df.loc[site,"ProdStop"] = ProductionDB.GetLastTimestamp(site)
df["LogLag"] = now - df["LogStop"]
df["ProdLag"] = now - df["ProdStop"]
print "\rDone! "
return df
In [5]:
def FormatStatusFrame(df):
df2 = pd.DataFrame()
df2["OpID"] = df["OpID"]
df2["LogLag"] = (df.LogLag/1000).apply(SecToHMS)
df2["LogStop"] = (df.LogStop/1000).apply(EpocToDate)
df2["LogStart"] = (df.LogStart/1000).apply(EpocToDate)
df2["ProdLag"] = (df.ProdLag/1000).apply(SecToHMS)
df2["ProdStop"] = (df.ProdStop/1000).apply(EpocToDate)
df2["ProdStart"] = (df.ProdStart/1000).apply(EpocToDate)
df2 = df2.reindex_axis(df.columns, axis=1)
return df2
In [6]:
def GetStatusFrame():
return FormatStatusFrame(GetRawStatusFrame())
In [7]:
def UpdateStatusWebpage(filename = "/var/www/html/status.html"):
status_raw = GetRawStatusFrame()
status = FormatStatusFrame(status_raw.sort("ProdLag"))
html = status.to_html(max_rows=50)
file = open(filename,"w")
file.write(html)
file.close()
#print status
print "Status written to %s" % filename
In [8]:
UpdateStatusWebpage()
In [22]:
status_raw = GetRawStatusFrame()
In [23]:
status = FormatStatusFrame(status_raw.sort("LogLag"))
In [123]:
status
Out[123]:
In [10]:
slb = pd.io.html.read_html("http://slb.nu/soldata/")
In [12]:
type(slb)
Out[12]:
In [36]:
ids = slb[0][8].dropna()
In [37]:
ids
Out[37]:
In [24]:
id2 = status["OpID"]
In [26]:
ids2 = id2.values
In [28]:
ids2
Out[28]:
In [38]:
ids = ids.values
In [35]:
ids
In [32]:
ids = ids.sort()
In [33]:
dis
In [39]:
ids.sort()
In [40]:
ids
Out[40]:
In [41]:
ids2.sort()
In [42]:
ids2
Out[42]:
In [ ]: