Loading and saving fitness metrics

merge-requests/30/head
Bob Mottram 2021-10-19 18:35:52 +01:00
parent 4f38fd4e29
commit 2bd1bef5b4
3 changed files with 22 additions and 0 deletions

View File

@ -347,6 +347,7 @@ from context import getIndividualPostContext
from speaker import getSSMLbox from speaker import getSSMLbox
from city import getSpoofedCity from city import getSpoofedCity
from fitnessFunctions import fitnessPerformance from fitnessFunctions import fitnessPerformance
from fitnessFunctions import fitnessThread
import os import os
@ -16917,7 +16918,10 @@ def runDaemon(defaultReplyIntervalHours: int,
assert not scanThemesForScripts(baseDir) assert not scanThemesForScripts(baseDir)
# fitness metrics # fitness metrics
fitnessFilename = baseDir + '/accounts/fitness.json'
httpd.fitness = {} httpd.fitness = {}
if os.path.isfile(fitnessFilename):
httpd.fitness = loadJson(fitnessFilename)
# initialize authorized fetch key # initialize authorized fetch key
httpd.signingPrivateKeyPem = None httpd.signingPrivateKeyPem = None
@ -17223,6 +17227,12 @@ def runDaemon(defaultReplyIntervalHours: int,
print('Creating shared item files directory') print('Creating shared item files directory')
os.mkdir(baseDir + '/sharefiles') os.mkdir(baseDir + '/sharefiles')
print('Creating fitness thread')
httpd.thrFitness = \
threadWithTrace(target=fitnessThread,
args=(baseDir, httpd.fitness), daemon=True)
httpd.thrFitness.start()
print('Creating cache expiry thread') print('Creating cache expiry thread')
httpd.thrCache = \ httpd.thrCache = \
threadWithTrace(target=expireCache, threadWithTrace(target=expireCache,

View File

@ -8,6 +8,7 @@ __status__ = "Production"
__module_group__ = "Core" __module_group__ = "Core"
import time import time
from utils import saveJson
def fitnessPerformance(startTime, fitnessState: {}, def fitnessPerformance(startTime, fitnessState: {},
@ -37,3 +38,13 @@ def fitnessPerformance(startTime, fitnessState: {},
print('FITNESS: performance/' + fitnessId + '/' + print('FITNESS: performance/' + fitnessId + '/' +
watchPoint + '/' + watchPoint + '/' +
str(fitnessState['performance'][fitnessId][watchPoint])) str(fitnessState['performance'][fitnessId][watchPoint]))
def fitnessThread(baseDir: str, fitness: {}):
"""Thread used to save fitness function scores
"""
fitnessFilename = baseDir + '/accounts/fitness.json'
while True:
# every 10 mins
time.sleep(60 * 10)
saveJson(fitness, fitnessFilename)

View File

@ -4530,6 +4530,7 @@ def _testFunctions():
'runNewswireWatchdog', 'runNewswireWatchdog',
'runFederatedSharesWatchdog', 'runFederatedSharesWatchdog',
'runFederatedSharesDaemon', 'runFederatedSharesDaemon',
'fitnessThread',
'threadSendPost', 'threadSendPost',
'sendToFollowers', 'sendToFollowers',
'expireCache', 'expireCache',