fixed bug pointing to wrong save files

This commit is contained in:
Nico Melone
2025-12-03 09:44:50 -06:00
parent 3da1c034cf
commit 1bbdf7aace

View File

@@ -164,9 +164,9 @@ class RuntimeStats:
self.manageTime()
return True
def loadDataFromFile(self, filePath="/var/user/files/runtimestats.json"):
def loadDataFromFile(self):
try:
with open(filePath, "r") as f:
with open(self.filePath, "r") as f:
temp = json.load(f)
self.runs = temp["data"]
self.currentRun = temp["current_run"]
@@ -174,11 +174,11 @@ class RuntimeStats:
self.todayString = temp["current_day"]
self.manageTime()
except:
logger.debug("Could not find file at {}".format(filePath))
logger.debug("Could not find file at {}".format(self.filePath))
logger.debug("creating file")
self.addDay()
try:
with open(filePath, "w") as f:
with open(self.filePath, "w") as f:
d = {
"current_run": self.currentRun,
"current_day": self.todayString,
@@ -188,10 +188,10 @@ class RuntimeStats:
except Exception as e:
logger.error(e)
def saveDataToFile(self, filePath="/var/user/files/runtimestats.json"):
def saveDataToFile(self):
try:
logger.debug("Saving Runs")
with open(filePath, "w") as f:
with open(self.filePath, "w") as f:
d = {
"current_run": self.currentRun,
"current_day": self.todayString,
@@ -201,15 +201,13 @@ class RuntimeStats:
except Exception as e:
logger.error(e)
p001_path = "/var/user/files/runtimestats_p001.json"
rts1 = RuntimeStats("/var/user/files/runtimestats_p001.json")
rts1.loadDataFromFile(p001_path)
rts1.saveDataToFile(p001_path)
rts1.loadDataFromFile()
rts1.saveDataToFile()
p002_path = "/var/user/files/runtimestats_p002.json"
rts2 = RuntimeStats("/var/user/files/runtimestats_p002.json")
rts2.loadDataFromFile(p002_path)
rts2.saveDataToFile(p002_path)
rts2.loadDataFromFile()
rts2.saveDataToFile()
def reboot():
# basic = Basic()
@@ -444,7 +442,7 @@ def sendData(message):
rts1.manageTime()
if value == 1 and not rts1.runs[rts1.todayString]["run_" + str(rts1.currentRun)]["start"]:
rts1.startRun()
rts1.saveDataToFile(p001_path)
rts1.saveDataToFile()
elif value == 0 and rts1.runs[rts1.todayString]["run_" + str(rts1.currentRun)]["start"] and not rts1.runs[rts1.todayString]["run_" + str(rts1.currentRun)]["end"]:
rts1.endRun()
rts1.saveDataToFile()
@@ -454,7 +452,7 @@ def sendData(message):
rts2.manageTime()
if value == 1 and not rts2.runs[rts2.todayString]["run_" + str(rts2.currentRun)]["start"]:
rts2.startRun()
rts2.saveDataToFile(p002_path)
rts2.saveDataToFile()
elif value == 0 and rts2.runs[rts2.todayString]["run_" + str(rts2.currentRun)]["start"] and not rts2.runs[rts2.todayString]["run_" + str(rts2.currentRun)]["end"]:
rts2.endRun()
rts2.saveDataToFile()