added runtimestats to piflow and advvfdipp
This commit is contained in:
BIN
advvfdipp/.DS_Store
vendored
BIN
advvfdipp/.DS_Store
vendored
Binary file not shown.
@@ -28,7 +28,7 @@ from Channel import PLCChannel, ModbusChannel,read_tag, write_tag, TAG_DATAERROR
|
||||
from utilities import get_public_ip_address, get_additional_tags, convert_int
|
||||
from file_logger import filelogger as log
|
||||
from Tags import tags
|
||||
|
||||
from runtimeStats import RuntimeStats as RTS
|
||||
|
||||
path = "/root/python_firmware/drivers/additional_tags.py"
|
||||
|
||||
@@ -69,7 +69,7 @@ class start(threading.Thread, deviceBase):
|
||||
mqtt=mqtt, Nodes=Nodes)
|
||||
|
||||
self.daemon = True
|
||||
self.version = "15"
|
||||
self.version = "16"
|
||||
self.finished = threading.Event()
|
||||
self.force_send = False
|
||||
self.public_ip_address = ""
|
||||
@@ -78,6 +78,10 @@ class start(threading.Thread, deviceBase):
|
||||
self.watchdog_last_checked = 0
|
||||
self.watchdog_last_sent = 0
|
||||
self.ping_counter = 0
|
||||
self.rts = RTS()
|
||||
self.rts.loadDataFromFile()
|
||||
self.rts.saveDataToFile()
|
||||
|
||||
threading.Thread.start(self)
|
||||
|
||||
# this is a required function for all drivers, its goal is to upload some piece of data
|
||||
@@ -128,6 +132,23 @@ class start(threading.Thread, deviceBase):
|
||||
if chan.plc_tag in convert_list:
|
||||
converted_value = convert_int(chan.plc_tag, val)
|
||||
self.sendtodbDev(1, chan.mesh_name, converted_value, 0, 'advvfdipp')
|
||||
elif chan.mesh_name == "wellstatus":
|
||||
if val == 0 and not self.rts.runs[self.rts.todayString]["run_" + str(self.rts.currentRun)]["start"]:
|
||||
self.rts.startRun()
|
||||
self.rts.saveDataToFile()
|
||||
elif val > 0 and self.rts.runs[self.rts.todayString]["run_" + str(self.rts.currentRun)]["start"] and not self.rts.runs[self.rts.todayString]["run_" + str(self.rts.currentRun)]["end"]:
|
||||
self.rts.endRun()
|
||||
self.rts.saveDataToFile()
|
||||
if chan.check(val, self.force_send):
|
||||
self.sendtodbDev(1, chan.mesh_name, chan.value, 0, 'advvfdipp')
|
||||
self.sendtodbDev(1, "percentRunTime30Days", self.rts.calculateRunPercentMultiDay(), 0,'advvfdipp')
|
||||
elif chan.mesh_name == "vfdfrequency":
|
||||
if val > 0:
|
||||
self.rts.addHertzDataPoint(val)
|
||||
self.rts.saveDataToFile()
|
||||
|
||||
self.sendtodbDev(1, chan.mesh_name, chan.value, 0, 'advvfdipp')
|
||||
self.sendtodbDev(1, "avgFrequency30Days", self.rts.calculateAverageHertzMultiDay(),0,'advvfdipp')
|
||||
else:
|
||||
self.sendtodbDev(1, chan.mesh_name, chan.value, 0, 'advvfdipp')
|
||||
#time.sleep(TAG_DATAERROR_SLEEPTIME) # sleep to allow Micro800 to handle ENET requests
|
||||
@@ -174,10 +195,10 @@ class start(threading.Thread, deviceBase):
|
||||
|
||||
#and then check the response...
|
||||
if response == 0:
|
||||
print hostname, 'is up!'
|
||||
print(hostname, 'is up!')
|
||||
self.ping_counter = 0
|
||||
else:
|
||||
print hostname, 'is down!'
|
||||
print(hostname, 'is down!')
|
||||
self.ping_counter += 1
|
||||
|
||||
if self.ping_counter >= 3:
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
"file1": "advvfdipp.py",
|
||||
"file6": "persistence.py",
|
||||
"file5": "utilities.py",
|
||||
"file4": "Tags.py"
|
||||
"file4": "Tags.py",
|
||||
"file5": "runtimeStats.py"
|
||||
},
|
||||
"deviceName": "advvfdipp",
|
||||
"releaseVersion": "15",
|
||||
"releaseVersion": "16",
|
||||
"driverFileName": "advvfdipp.py",
|
||||
"driverId": "0100"
|
||||
}
|
||||
172
advvfdipp/advvfdippv2/runtimeStats.py
Normal file
172
advvfdipp/advvfdippv2/runtimeStats.py
Normal file
@@ -0,0 +1,172 @@
|
||||
from datetime import datetime as dt
|
||||
import time
|
||||
import json
|
||||
import math
|
||||
|
||||
class RuntimeStats:
|
||||
|
||||
def __init__(self):
|
||||
self.runs = {}
|
||||
self.currentRun = 0
|
||||
self.today = ""
|
||||
self.todayString = ""
|
||||
|
||||
def manageTime(self):
|
||||
if self.todayString != dt.strftime(dt.today(), "%Y-%m-%d"):
|
||||
if self.runs[self.todayString]["run_" + str(self.currentRun)]["start"] and not self.runs[self.todayString]["run_" + str(self.currentRun)]["end"]:
|
||||
self.runs[self.todayString]["run_" + str(self.currentRun)]["end"] = time.mktime(dt.strptime(self.todayString + " 23:59:59", "%Y-%m-%d %H:%M:%S").timetuple())
|
||||
self.addDay()
|
||||
self.today = dt.today()
|
||||
self.todayString = dt.strftime(self.today, "%Y-%m-%d")
|
||||
days = list(self.runs.keys())
|
||||
days.sort()
|
||||
while (dt.strptime(days[-1],"%Y-%m-%d") - dt.strptime(days[0], "%Y-%m-%d")).days > 30:
|
||||
self.removeDay(day=days[0])
|
||||
days = list(self.runs.keys())
|
||||
days.sort()
|
||||
|
||||
def addHertzDataPoint(self, frequency):
|
||||
if frequency > 0:
|
||||
self.manageTime()
|
||||
try:
|
||||
self.runs[self.todayString]["run_" + str(self.currentRun)]["frequencies"].append(frequency)
|
||||
except:
|
||||
self.runs[self.todayString]["run_" + str(self.currentRun)]["frequencies"] = [frequency]
|
||||
|
||||
def startRun(self):
|
||||
if self.checkRunning():
|
||||
self.endRun()
|
||||
self.runs[self.todayString]["run_" + str(self.currentRun)]["start"] = time.time()
|
||||
|
||||
def endRun(self):
|
||||
self.runs[self.todayString]["run_" + str(self.currentRun)]["end"] = time.time()
|
||||
self.currentRun += 1
|
||||
self.runs[self.todayString]["run_" + str(self.currentRun)] = {"start":0, "end": 0, "frequencies":[]}
|
||||
|
||||
def checkRunning(self):
|
||||
if self.runs[self.todayString]["run_" + str(self.currentRun)]["start"] and not self.runs[self.todayString]["run_" + str(self.currentRun)]["end"]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def addDay(self):
|
||||
self.today = dt.today()
|
||||
self.todayString = dt.strftime(self.today, "%Y-%m-%d")
|
||||
self.currentRun = 1
|
||||
self.runs[self.todayString] = {}
|
||||
self.runs[self.todayString]["run_" + str(self.currentRun)] = {"start":0, "end": 0, "frequencies":[]}
|
||||
|
||||
def countRunsDay(self, day=None):
|
||||
if not day:
|
||||
day = self.todayString
|
||||
return len(self.runs[day].keys())
|
||||
|
||||
def countRunsMultiDay(self, numDays=30):
|
||||
total_runs = 0
|
||||
for day in list(self.runs.keys()):
|
||||
total_runs += self.countRunsDay(day=day)
|
||||
return total_runs
|
||||
|
||||
def calculateAverageHertzDay(self, day=None, returnArray=False):
|
||||
dayFrequencies = []
|
||||
if not day:
|
||||
day = self.todayString
|
||||
for run in list(self.runs[day].keys()):
|
||||
try:
|
||||
dayFrequencies += self.runs[day][run]["frequencies"]
|
||||
except Exception as e:
|
||||
print("{} missing frequency data for {}".format(day,run))
|
||||
if returnArray:
|
||||
return dayFrequencies
|
||||
return round(math.fsum(dayFrequencies)/len(dayFrequencies),2)
|
||||
|
||||
def calculateAverageHertzMultiDay(self, numDays=30):
|
||||
self.manageTime()
|
||||
frequencies = []
|
||||
for day in list(self.runs.keys()):
|
||||
if not day == self.todayString and (dt.strptime(self.todayString, "%Y-%m-%d") - dt.strptime(day, "%Y-%m-%d")).days <= numDays:
|
||||
try:
|
||||
frequencies += self.calculateAverageHertzDay(day=day, returnArray=True)
|
||||
except Exception as e:
|
||||
print("{} missing frequency data".format(day))
|
||||
if len(frequencies):
|
||||
return round(math.fsum(frequencies)/len(frequencies), 2)
|
||||
return 0
|
||||
|
||||
def calculateRunTimeDay(self, day=None, convertToHours=True):
|
||||
total_time = 0
|
||||
if not day:
|
||||
day = self.todayString
|
||||
for run in list(self.runs[day].keys()):
|
||||
total_time = self.runs[day][run]["end"] - self.runs[day][run]["start"] + total_time
|
||||
if convertToHours:
|
||||
return self.convertSecondstoHours(total_time)
|
||||
return total_time
|
||||
|
||||
def calculateRunTimeMultiDay(self, numDays=30, convertToHours=True):
|
||||
total_time = 0
|
||||
for day in list(self.runs.keys()):
|
||||
if not day == self.todayString and (dt.strptime(self.todayString, "%Y-%m-%d") - dt.strptime(day, "%Y-%m-%d")).days <= numDays:
|
||||
total_time += self.calculateRunTimeDay(day=day, convertToHours=False)
|
||||
if convertToHours:
|
||||
return self.convertSecondstoHours(total_time)
|
||||
return total_time
|
||||
|
||||
def calculateRunPercentDay(self, day=None, precise=False):
|
||||
if not day:
|
||||
day = self.todayString
|
||||
if precise:
|
||||
return (self.calculateRunTimeDay(day=day)/24) * 100
|
||||
return round((self.calculateRunTimeDay(day=day)/24) * 100, 2)
|
||||
|
||||
|
||||
def calculateRunPercentMultiDay(self, numDays=30, precise=False):
|
||||
self.manageTime()
|
||||
if precise:
|
||||
return (self.calculateRunTimeMultiDay()/(24*numDays)) * 100
|
||||
return round((self.calculateRunTimeMultiDay()/(24*numDays)) * 100,2)
|
||||
|
||||
def removeDay(self, day=None):
|
||||
if not day:
|
||||
raise Exception("Day can not be None")
|
||||
print("removing day {}".format(day))
|
||||
del self.runs[day]
|
||||
|
||||
def convertSecondstoHours(self, seconds):
|
||||
return round(seconds / (60*60),2)
|
||||
|
||||
def loadDataFromFile(self, filePath="./runtimestats.json"):
|
||||
try:
|
||||
with open(filePath, "r") as f:
|
||||
temp = json.load(f)
|
||||
self.runs = temp["data"]
|
||||
self.currentRun = temp["current_run"]
|
||||
self.today = dt.strptime(temp["current_day"], "%Y-%m-%d")
|
||||
self.todayString = temp["current_day"]
|
||||
self.manageTime()
|
||||
except:
|
||||
print("Could not find file at {}".format(filePath))
|
||||
print("creating file")
|
||||
self.addDay()
|
||||
try:
|
||||
with open(filePath, "w") as f:
|
||||
d = {
|
||||
"current_run": self.currentRun,
|
||||
"current_day": self.todayString,
|
||||
"data": self.runs
|
||||
}
|
||||
json.dump(d, f, indent=4)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
def saveDataToFile(self, filePath="./runtimestats.json"):
|
||||
try:
|
||||
print("Saving Runs")
|
||||
with open(filePath, "w") as f:
|
||||
d = {
|
||||
"current_run": self.currentRun,
|
||||
"current_day": self.todayString,
|
||||
"data": self.runs
|
||||
}
|
||||
json.dump(d, f, indent=4)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
@@ -103,7 +103,7 @@ class start(threading.Thread, deviceBase):
|
||||
mqtt=mqtt, Nodes=Nodes)
|
||||
|
||||
self.daemon = True
|
||||
self.version = "26"
|
||||
self.version = "27"
|
||||
self.finished = threading.Event()
|
||||
self.force_send = False
|
||||
self.public_ip_address = ""
|
||||
@@ -113,6 +113,8 @@ class start(threading.Thread, deviceBase):
|
||||
self.alarm = ""
|
||||
self.rts = RTS()
|
||||
self.rts.loadDataFromFile()
|
||||
self.rts.saveDataToFile()
|
||||
|
||||
threading.Thread.start(self)
|
||||
|
||||
# this is a required function for all drivers, its goal is to upload some piece of data
|
||||
@@ -164,6 +166,13 @@ class start(threading.Thread, deviceBase):
|
||||
self.sendtodbDev(1,"today_"+chan.mesh_name, today_total,0,'PiFlow')
|
||||
self.sendtodbDev(1,"yesterday_"+chan.mesh_name, yesterday_total,0,'PiFlow')
|
||||
self.sendtodbDev(1, chan.mesh_name + "_units", "BBL",0,'PiFlow')
|
||||
elif chan.mesh_name == "frequency":
|
||||
if val > 0:
|
||||
self.rts.addHertzDataPoint(val)
|
||||
self.rts.saveDataToFile()
|
||||
if chan.check(val, self.force_send):
|
||||
self.sendtodbDev(1, chan.mesh_name, chan.value, 0, 'PiFlow')
|
||||
self.sendtodbDev(1, "avgFrequency30Days", self.rts.calculateAverageHertzMultiDay(),0,'PiFlow')
|
||||
else:
|
||||
if chan.check(val, self.force_send):
|
||||
self.sendtodbDev(1, chan.mesh_name, chan.value, 0, 'PiFlow')
|
||||
@@ -350,6 +359,7 @@ class start(threading.Thread, deviceBase):
|
||||
persistence.store(PERSIST, 'persist.json')
|
||||
today_total = val - yesterday_total_midnight
|
||||
if hour == 0 and minute == 0 and not(day == yesterday):
|
||||
self.rts.manageTime()
|
||||
yesterday_total = today_total
|
||||
yesterday_total_midnight = val
|
||||
today_total = val - yesterday_total_midnight
|
||||
@@ -523,10 +533,18 @@ class start(threading.Thread, deviceBase):
|
||||
except Exception as e:
|
||||
log.warning("Error in send status semicolon: {}".format(e))
|
||||
|
||||
|
||||
if self.status != status_string:
|
||||
self.status = status_string
|
||||
log.info("Sending {} for {}".format(status_string, 'run_status'))
|
||||
self.sendtodbDev(1, 'run_status', status_string, 0, 'PiFlow')
|
||||
if "Operating" in status_string and not self.rts.runs[self.rts.todayString]["run_" + str(self.rts.currentRun)]["start"]:
|
||||
self.rts.startRun()
|
||||
self.rts.saveDataToFile()
|
||||
elif "Stopped" in status_string and self.rts.runs[self.rts.todayString]["run_" + str(self.rts.currentRun)]["start"] and not self.rts.runs[self.rts.todayString]["run_" + str(self.rts.currentRun)]["end"]:
|
||||
self.rts.endRun()
|
||||
self.rts.saveDataToFile()
|
||||
self.sendtodbDev(1, "percentRunTime30Days", self.rts.calculateRunPercentMultiDay(), 0,'PiFlow')
|
||||
if self.alarm != alarm_string:
|
||||
self.alarm = alarm_string
|
||||
log.info("Sending {} for {}".format(alarm_string, 'fault_a'))
|
||||
|
||||
BIN
piflow/__pycache__/runtimeStats.cpython-39.pyc
Normal file
BIN
piflow/__pycache__/runtimeStats.cpython-39.pyc
Normal file
Binary file not shown.
@@ -3,14 +3,15 @@
|
||||
"driverFileName":"PiFlow.py",
|
||||
"deviceName":"piflow",
|
||||
"driverId":"0280",
|
||||
"releaseVersion":"26",
|
||||
"releaseVersion":"27",
|
||||
"files": {
|
||||
"file1":"PiFlow.py",
|
||||
"file2":"Channel.py",
|
||||
"file3":"file_logger.py",
|
||||
"file4":"Tags.py",
|
||||
"file5":"utilities.py",
|
||||
"file6":"persistence.py"
|
||||
"file6":"persistence.py",
|
||||
"file7":"runtimeStats.py"
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,10 +12,12 @@ class RuntimeStats:
|
||||
self.todayString = ""
|
||||
|
||||
def manageTime(self):
|
||||
if self.today != dt.today():
|
||||
if self.todayString != dt.strftime(dt.today(), "%Y-%m-%d"):
|
||||
if self.runs[self.todayString]["run_" + str(self.currentRun)]["start"] and not self.runs[self.todayString]["run_" + str(self.currentRun)]["end"]:
|
||||
self.runs[self.todayString]["run_" + str(self.currentRun)]["end"] = time.mktime(dt.strptime(self.todayString + " 23:59:59", "%Y-%m-%d %H:%M:%S").timetuple())
|
||||
self.addDay()
|
||||
self.today = dt.today()
|
||||
self.todayString = dt.strftime(self.today, "%Y-%m-%d")
|
||||
days = list(self.runs.keys())
|
||||
days.sort()
|
||||
while (dt.strptime(days[-1],"%Y-%m-%d") - dt.strptime(days[0], "%Y-%m-%d")).days > 30:
|
||||
@@ -32,10 +34,19 @@ class RuntimeStats:
|
||||
self.runs[self.todayString]["run_" + str(self.currentRun)]["frequencies"] = [frequency]
|
||||
|
||||
def startRun(self):
|
||||
if self.checkRunning():
|
||||
self.endRun()
|
||||
self.runs[self.todayString]["run_" + str(self.currentRun)]["start"] = time.time()
|
||||
|
||||
def endRun(self):
|
||||
self.runs[self.todayString]["run_" + str(self.currentRun)]["end"] = time.time()
|
||||
self.runs[self.todayString]["run_" + str(self.currentRun)]["end"] = time.time()
|
||||
self.currentRun += 1
|
||||
self.runs[self.todayString]["run_" + str(self.currentRun)] = {"start":0, "end": 0, "frequencies":[]}
|
||||
|
||||
def checkRunning(self):
|
||||
if self.runs[self.todayString]["run_" + str(self.currentRun)]["start"] and not self.runs[self.todayString]["run_" + str(self.currentRun)]["end"]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def addDay(self):
|
||||
self.today = dt.today()
|
||||
@@ -72,11 +83,14 @@ class RuntimeStats:
|
||||
self.manageTime()
|
||||
frequencies = []
|
||||
for day in list(self.runs.keys()):
|
||||
try:
|
||||
frequencies += self.calculateAverageHertzDay(day=day, returnArray=True)
|
||||
except Exception as e:
|
||||
print("{} missing frequency data".format(day))
|
||||
return round(math.fsum(frequencies)/len(frequencies), 2)
|
||||
if not day == self.todayString and (dt.strptime(self.todayString, "%Y-%m-%d") - dt.strptime(day, "%Y-%m-%d")).days <= numDays:
|
||||
try:
|
||||
frequencies += self.calculateAverageHertzDay(day=day, returnArray=True)
|
||||
except Exception as e:
|
||||
print("{} missing frequency data".format(day))
|
||||
if len(frequencies):
|
||||
return round(math.fsum(frequencies)/len(frequencies), 2)
|
||||
return 0
|
||||
|
||||
def calculateRunTimeDay(self, day=None, convertToHours=True):
|
||||
total_time = 0
|
||||
@@ -91,7 +105,8 @@ class RuntimeStats:
|
||||
def calculateRunTimeMultiDay(self, numDays=30, convertToHours=True):
|
||||
total_time = 0
|
||||
for day in list(self.runs.keys()):
|
||||
total_time += self.calculateRunTimeDay(day=day, convertToHours=False)
|
||||
if not day == self.todayString and (dt.strptime(self.todayString, "%Y-%m-%d") - dt.strptime(day, "%Y-%m-%d")).days <= numDays:
|
||||
total_time += self.calculateRunTimeDay(day=day, convertToHours=False)
|
||||
if convertToHours:
|
||||
return self.convertSecondstoHours(total_time)
|
||||
return total_time
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"execution_count": 106,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -23,23 +23,42 @@
|
||||
" \n",
|
||||
" def __init__(self):\n",
|
||||
" self.runs = {}\n",
|
||||
" self.currentRun = 1\n",
|
||||
" self.today = dt.today()\n",
|
||||
" self.todayString = str(self.today.year)+\"-\"+str(self.today.month)+\"-\"+str(self.today.day)\n",
|
||||
" self.currentRun = 0\n",
|
||||
" self.today = \"\"\n",
|
||||
" self.todayString = \"\"\n",
|
||||
"\n",
|
||||
" def manageTime(self):\n",
|
||||
" if self.today != dt.today():\n",
|
||||
" if self.runs[self.todayString][\"run_\" + str(self.currentRun)][\"start\"] and not self.runs[self.todayString][\"run_\" + str(self.currentRun)][\"end\"]:\n",
|
||||
" self.runs[self.todayString][\"run_\" + str(self.currentRun)][\"end\"] = dt.timestamp(dt.strptime(self.todayString + \" 23:59:59\", \"%Y-%m-%d %H:%M:%S\"))\n",
|
||||
" self.addDay()\n",
|
||||
" days = list(self.runs.keys())\n",
|
||||
" days.sort()\n",
|
||||
" while (dt.strptime(days[-1],\"%Y-%m-%d\") - dt.strptime(days[0], \"%Y-%m-%d\")).days > 30:\n",
|
||||
" self.removeDay(day=days[0])\n",
|
||||
" days = list(self.runs.keys())\n",
|
||||
" days.sort()\n",
|
||||
"\n",
|
||||
" def addHertzDataPoint(self, frequency):\n",
|
||||
" try:\n",
|
||||
" self.runs[self.todayString][\"run_\" + str(self.currentRun)][\"frequencies\"].append(frequency)\n",
|
||||
" except:\n",
|
||||
" self.runs[self.todayString][\"run_\" + str(self.currentRun)][\"frequencies\"] = [frequency]\n",
|
||||
" if frequency > 0:\n",
|
||||
" self.manageTime()\n",
|
||||
" try:\n",
|
||||
" self.runs[self.todayString][\"run_\" + str(self.currentRun)][\"frequencies\"].append(frequency)\n",
|
||||
" except:\n",
|
||||
" self.runs[self.todayString][\"run_\" + str(self.currentRun)][\"frequencies\"] = [frequency]\n",
|
||||
"\n",
|
||||
" def startRun(self):\n",
|
||||
" self.runs[self.todayString][\"run_\" + str(self.currentRun)] = {\"start\": dt.timestamp(dt.now())}\n",
|
||||
" \n",
|
||||
" self.runs[self.todayString][\"run_\" + str(self.currentRun)][\"start\"] = dt.timestamp(dt.now())\n",
|
||||
"\n",
|
||||
" def endRun(self):\n",
|
||||
" self.runs[self.todayString][\"run_\" + str(self.currentRun)][\"end\"] = dt.timestamp(self.today) \n",
|
||||
" self.currentRun += 1\n",
|
||||
" self.runs[self.todayString][\"run_\" + str(self.currentRun)][\"end\"] = dt.timestamp(dt.now()) \n",
|
||||
"\n",
|
||||
" def addDay(self):\n",
|
||||
" self.today = dt.today()\n",
|
||||
" self.todayString = dt.strftime(self.today, \"%Y-%m-%d\")\n",
|
||||
" self.currentRun = 1\n",
|
||||
" self.runs[self.todayString] = {}\n",
|
||||
" self.runs[self.todayString][\"run_\" + str(self.currentRun)] = {\"start\":0, \"end\": 0, \"frequencies\":[]}\n",
|
||||
"\n",
|
||||
" def countRunsDay(self, day=None):\n",
|
||||
" if not day:\n",
|
||||
@@ -78,8 +97,8 @@
|
||||
" total_time = 0\n",
|
||||
" if not day:\n",
|
||||
" day = self.todayString\n",
|
||||
" for key in list(self.runs[day].keys()):\n",
|
||||
" total_time = self.runs[day][key][\"end\"] - self.runs[day][key][\"start\"] + total_time\n",
|
||||
" for run in list(self.runs[day].keys()):\n",
|
||||
" total_time = self.runs[day][run][\"end\"] - self.runs[day][run][\"start\"] + total_time\n",
|
||||
" if convertToHours:\n",
|
||||
" return RuntimeStats.convertSecondstoHours(total_time)\n",
|
||||
" return total_time\n",
|
||||
@@ -108,6 +127,7 @@
|
||||
" def removeDay(self, day=None):\n",
|
||||
" if not day:\n",
|
||||
" raise Exception(\"Day can not be None\")\n",
|
||||
" print(\"removing day {}\".format(day))\n",
|
||||
" del self.runs[day]\n",
|
||||
" \n",
|
||||
" def convertSecondstoHours(seconds):\n",
|
||||
@@ -116,7 +136,12 @@
|
||||
" def loadDataFromFile(self, filePath=\"../runtimestats.json\"):\n",
|
||||
" try:\n",
|
||||
" with open(filePath, \"r\") as f:\n",
|
||||
" self.runs = json.load(f)\n",
|
||||
" temp = json.load(f)\n",
|
||||
" self.runs = temp[\"data\"]\n",
|
||||
" self.currentRun = temp[\"current_run\"]\n",
|
||||
" self.today = dt.strptime(temp[\"current_day\"], \"%Y-%m-%d\")\n",
|
||||
" self.todayString = temp[\"current_day\"]\n",
|
||||
" self.manageTime()\n",
|
||||
" except FileExistsError:\n",
|
||||
" print(\"Could not find file at {}\".format(filePath))\n",
|
||||
" except FileNotFoundError:\n",
|
||||
@@ -124,7 +149,12 @@
|
||||
" print(\"creating file\")\n",
|
||||
" try:\n",
|
||||
" with open(filePath, \"w\") as f:\n",
|
||||
" json.dump(self.runs, f, indent=4)\n",
|
||||
" d = {\n",
|
||||
" \"current_run\": self.currentRun,\n",
|
||||
" \"current_day\": self.todayString,\n",
|
||||
" \"data\": self.runs\n",
|
||||
" }\n",
|
||||
" json.dump(d, f, indent=4)\n",
|
||||
" except Exception as e:\n",
|
||||
" print(e)\n",
|
||||
" except Exception as e:\n",
|
||||
@@ -134,7 +164,12 @@
|
||||
" try:\n",
|
||||
" print(\"Saving Runs\")\n",
|
||||
" with open(filePath, \"w+\") as f:\n",
|
||||
" json.dump(self.runs, f, indent=4)\n",
|
||||
" d = {\n",
|
||||
" \"current_run\": self.currentRun,\n",
|
||||
" \"current_day\": self.todayString,\n",
|
||||
" \"data\": self.runs\n",
|
||||
" }\n",
|
||||
" json.dump(d, f, indent=4)\n",
|
||||
" except FileNotFoundError:\n",
|
||||
" print(\"Could not find file at {}\".format(filePath))\n",
|
||||
" except Exception as e:\n",
|
||||
@@ -143,7 +178,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"execution_count": 107,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -151,7 +186,7 @@
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"{}\n",
|
||||
"{'2023-1-11': {'run_1': {'start': 1673465959.694776, 'frequencies': [67, 65, 59, 62, 100], 'end': 1673475545.313309}, 'run_2': {'start': 1673469145.271416, 'end': 1673469136.691883, 'frequencies': [100, 99, 98, 87, 56, 56, 58, 67]}}, '2023-1-10': {'run_1': {'start': 1673465959.694776, 'frequencies': [67, 65, 59, 62], 'end': 1673469136.691883}, 'run_2': {'start': 1673469145.271416, 'end': 1673469136.691883}}, '2023-1-9': {'run_1': {'start': 1673465959.694776, 'frequencies': [67, 65, 59, 62], 'end': 1673469136.691883}, 'run_2': {'start': 1673469145.271416, 'end': 1673469136.691883}}}\n"
|
||||
"{'2023-01-11': {'run_1': {'start': 1673465959.694776, 'frequencies': [67, 65, 59, 62, 100], 'end': 1673475545.313309}, 'run_2': {'start': 1673469145.271416, 'end': 1673469136.691883, 'frequencies': [100, 99, 98, 87, 56, 56, 58, 67]}}, '2023-01-10': {'run_1': {'start': 1673465959.694776, 'frequencies': [67, 65, 59, 62], 'end': 1673469136.691883}, 'run_2': {'start': 1673469145.271416, 'end': 1673469136.691883}}, '2023-01-09': {'run_1': {'start': 1673465959.694776, 'frequencies': [67, 65, 59, 62], 'end': 1673469136.691883}, 'run_2': {'start': 1673469145.271416, 'end': 1673469136.691883}}, '2022-12-17': {'run_1': {'start': 0, 'end': 0, 'frequencies': []}}}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -163,6 +198,57 @@
|
||||
"print(rts.runs)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 108,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"removing day 2022-12-17\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"rts.manageTime()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 109,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'2023-01-11': {'run_1': {'start': 1673465959.694776,\n",
|
||||
" 'frequencies': [67, 65, 59, 62, 100],\n",
|
||||
" 'end': 1673475545.313309},\n",
|
||||
" 'run_2': {'start': 1673469145.271416,\n",
|
||||
" 'end': 1673469136.691883,\n",
|
||||
" 'frequencies': [100, 99, 98, 87, 56, 56, 58, 67]}},\n",
|
||||
" '2023-01-10': {'run_1': {'start': 1673465959.694776,\n",
|
||||
" 'frequencies': [67, 65, 59, 62],\n",
|
||||
" 'end': 1673469136.691883},\n",
|
||||
" 'run_2': {'start': 1673469145.271416, 'end': 1673469136.691883}},\n",
|
||||
" '2023-01-09': {'run_1': {'start': 1673465959.694776,\n",
|
||||
" 'frequencies': [67, 65, 59, 62],\n",
|
||||
" 'end': 1673469136.691883},\n",
|
||||
" 'run_2': {'start': 1673469145.271416, 'end': 1673469136.691883}},\n",
|
||||
" '2023-01-17': {'run_1': {'start': 0, 'end': 0, 'frequencies': []}}}"
|
||||
]
|
||||
},
|
||||
"execution_count": 109,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"rts.runs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -203,7 +289,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"execution_count": 30,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -212,7 +298,7 @@
|
||||
"2.66"
|
||||
]
|
||||
},
|
||||
"execution_count": 23,
|
||||
"execution_count": 30,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -223,7 +309,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"execution_count": 31,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -232,7 +318,7 @@
|
||||
"11.08"
|
||||
]
|
||||
},
|
||||
"execution_count": 13,
|
||||
"execution_count": 31,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -243,7 +329,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"execution_count": 32,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -252,7 +338,7 @@
|
||||
"0.61"
|
||||
]
|
||||
},
|
||||
"execution_count": 12,
|
||||
"execution_count": 32,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -263,18 +349,46 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 33,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"4.42"
|
||||
]
|
||||
},
|
||||
"execution_count": 33,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"rts.calculateRunTimeMultiDay()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 34,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "KeyError",
|
||||
"evalue": "'2023-1-17'",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[1;32m/Users/nico/Documents/GitHub/HenryPump-Drivers/piflow/runtimestats.ipynb Cell 12\u001b[0m in \u001b[0;36mRuntimeStats.addHertzDataPoint\u001b[0;34m(self, frequency)\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/nico/Documents/GitHub/HenryPump-Drivers/piflow/runtimestats.ipynb#X13sZmlsZQ%3D%3D?line=9'>10</a>\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m---> <a href='vscode-notebook-cell:/Users/nico/Documents/GitHub/HenryPump-Drivers/piflow/runtimestats.ipynb#X13sZmlsZQ%3D%3D?line=10'>11</a>\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mruns[\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mtodayString][\u001b[39m\"\u001b[39m\u001b[39mrun_\u001b[39m\u001b[39m\"\u001b[39m \u001b[39m+\u001b[39m \u001b[39mstr\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcurrentRun)][\u001b[39m\"\u001b[39m\u001b[39mfrequencies\u001b[39m\u001b[39m\"\u001b[39m]\u001b[39m.\u001b[39mappend(frequency)\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/nico/Documents/GitHub/HenryPump-Drivers/piflow/runtimestats.ipynb#X13sZmlsZQ%3D%3D?line=11'>12</a>\u001b[0m \u001b[39mexcept\u001b[39;00m:\n",
|
||||
"\u001b[0;31mKeyError\u001b[0m: '2023-1-17'",
|
||||
"\nDuring handling of the above exception, another exception occurred:\n",
|
||||
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[1;32m/Users/nico/Documents/GitHub/HenryPump-Drivers/piflow/runtimestats.ipynb Cell 12\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> <a href='vscode-notebook-cell:/Users/nico/Documents/GitHub/HenryPump-Drivers/piflow/runtimestats.ipynb#X13sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m rts\u001b[39m.\u001b[39;49maddHertzDataPoint(\u001b[39m67\u001b[39;49m)\n",
|
||||
"\u001b[1;32m/Users/nico/Documents/GitHub/HenryPump-Drivers/piflow/runtimestats.ipynb Cell 12\u001b[0m in \u001b[0;36mRuntimeStats.addHertzDataPoint\u001b[0;34m(self, frequency)\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/nico/Documents/GitHub/HenryPump-Drivers/piflow/runtimestats.ipynb#X13sZmlsZQ%3D%3D?line=10'>11</a>\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mruns[\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mtodayString][\u001b[39m\"\u001b[39m\u001b[39mrun_\u001b[39m\u001b[39m\"\u001b[39m \u001b[39m+\u001b[39m \u001b[39mstr\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcurrentRun)][\u001b[39m\"\u001b[39m\u001b[39mfrequencies\u001b[39m\u001b[39m\"\u001b[39m]\u001b[39m.\u001b[39mappend(frequency)\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/nico/Documents/GitHub/HenryPump-Drivers/piflow/runtimestats.ipynb#X13sZmlsZQ%3D%3D?line=11'>12</a>\u001b[0m \u001b[39mexcept\u001b[39;00m:\n\u001b[0;32m---> <a href='vscode-notebook-cell:/Users/nico/Documents/GitHub/HenryPump-Drivers/piflow/runtimestats.ipynb#X13sZmlsZQ%3D%3D?line=12'>13</a>\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mruns[\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mtodayString][\u001b[39m\"\u001b[39m\u001b[39mrun_\u001b[39m\u001b[39m\"\u001b[39m \u001b[39m+\u001b[39m \u001b[39mstr\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcurrentRun)][\u001b[39m\"\u001b[39m\u001b[39mfrequencies\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m [frequency]\n",
|
||||
"\u001b[0;31mKeyError\u001b[0m: '2023-1-17'"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"rts.addHertzDataPoint(67)"
|
||||
]
|
||||
@@ -345,6 +459,45 @@
|
||||
"today = dt.today()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 39,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"1673991101.567802\n",
|
||||
"1674021599.0\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print(dt.timestamp(dt.now()))\n",
|
||||
"print(dt.timestamp(dt.strptime(rts.todayString + \" 23:59:59\", \"%Y-%m-%d %H:%M:%S\")))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 47,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'2023-01-17'"
|
||||
]
|
||||
},
|
||||
"execution_count": 47,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"dt.strftime(dt.now(), \"%Y-%m-%d\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -371,21 +524,87 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"execution_count": 35,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"{'that': {'is': 'a bigger test'}}\n"
|
||||
"works\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"t = {\"this\": \"test1\", \"that\": {\"is\": \"a bigger test\"}}\n",
|
||||
"del t[\"this\"]\n",
|
||||
"print(t)"
|
||||
"try:\n",
|
||||
" t[\"those\"]\n",
|
||||
"except:\n",
|
||||
" print(\"works\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 59,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Saving Runs\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"rts.addDay()\n",
|
||||
"rts.saveDataToFile(filePath=path)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 78,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2023-01-17\n",
|
||||
"2022-12-17\n",
|
||||
"31\n",
|
||||
"31\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"days = list(rts.runs.keys())\n",
|
||||
"days.sort()\n",
|
||||
"print(days[-1])\n",
|
||||
"print(days[0])\n",
|
||||
"print((dt.strptime(days[-1],\"%Y-%m-%d\") - dt.strptime(days[0], \"%Y-%m-%d\")).days)\n",
|
||||
"if (dt.strptime(days[-1],\"%Y-%m-%d\") - dt.strptime(days[0], \"%Y-%m-%d\")).days > 30:\n",
|
||||
" print((dt.strptime(days[-1],\"%Y-%m-%d\") - dt.strptime(days[0], \"%Y-%m-%d\")).days)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 110,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"True\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"s = \"Operating in Forward;\"\n",
|
||||
"if \"Operating\" in s:\n",
|
||||
" print(True)"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -405,7 +624,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.12"
|
||||
"version": "3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:25:14) \n[Clang 12.0.1 ]"
|
||||
},
|
||||
"orig_nbformat": 4,
|
||||
"vscode": {
|
||||
|
||||
11
piflow/testRTS.py
Normal file
11
piflow/testRTS.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from runtimeStats import RuntimeStats as RTS
|
||||
|
||||
|
||||
rts = RTS()
|
||||
rts.loadDataFromFile("/Users/nico/Documents/test/runtimestats.json")
|
||||
rts.startRun()
|
||||
#rts.endRun()
|
||||
rts.saveDataToFile("/Users/nico/Documents/test/runtimestats.json")
|
||||
print(rts.runs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user