mirror of
https://github.com/FAUSheppy/skillbird
synced 2025-12-06 14:51:36 +01:00
implement health query for monitoring
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
import json
|
import json
|
||||||
|
import datetime as dt
|
||||||
import backends.entities.Players as Players
|
import backends.entities.Players as Players
|
||||||
import backends.trueskillWrapper as trueskill
|
import backends.trueskillWrapper as trueskill
|
||||||
|
|
||||||
@@ -10,6 +11,30 @@ import backends.trueskillWrapper as trueskill
|
|||||||
DATABASE = "players.sqlite"
|
DATABASE = "players.sqlite"
|
||||||
DATABASE_ROUNDS = "rounds.sqlite"
|
DATABASE_ROUNDS = "rounds.sqlite"
|
||||||
|
|
||||||
|
def check():
|
||||||
|
conn = sqlite3.connect(DATABASE)
|
||||||
|
conn.close()
|
||||||
|
conn = sqlite3.connect(DATABASE_ROUNDS)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
backlog = dt.datetime.now() - dt.timedelta(days=7)
|
||||||
|
query = "SELECT avg(prediction) FROM rounds WHERE timestamp > ? AND confidence > 0.6 \
|
||||||
|
ORDER BY timestamp DESC;"
|
||||||
|
cursor.execute(query, (backlog.timestamp(),))
|
||||||
|
avgPred = cursor.fetchone()[0]
|
||||||
|
query = "SELECT count(*) FROM rounds WHERE timestamp > ? AND confidence > 0.6 \
|
||||||
|
ORDER BY timestamp DESC;"
|
||||||
|
cursor.execute(query, (backlog.timestamp(),))
|
||||||
|
count = cursor.fetchone()[0]
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
if count < 10:
|
||||||
|
raise AssertionError("Game count last 7 days low ({})".format(count))
|
||||||
|
elif avgPred > 0.5:
|
||||||
|
raise AssertionError("Average Prediction very bad ({})".format(avgPred))
|
||||||
|
else:
|
||||||
|
return (count, avgPred)
|
||||||
|
|
||||||
|
|
||||||
def saveRound(r):
|
def saveRound(r):
|
||||||
conn = sqlite3.connect(DATABASE_ROUNDS)
|
conn = sqlite3.connect(DATABASE_ROUNDS)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|||||||
@@ -17,6 +17,14 @@ def run(port, parser):
|
|||||||
app.run(port=port)
|
app.run(port=port)
|
||||||
|
|
||||||
## SERVER QUERIES ###
|
## SERVER QUERIES ###
|
||||||
|
@app.route('/health')
|
||||||
|
def health():
|
||||||
|
try:
|
||||||
|
count, avgPred = db.check()
|
||||||
|
return ("Rounds: {}, AvgPrediction (lower than 0.5 is good): {}".format(count, avgPred))
|
||||||
|
except AssertionError as e:
|
||||||
|
return ("{}".format(e), 200)
|
||||||
|
|
||||||
@app.route('/get-player-rating-msg')
|
@app.route('/get-player-rating-msg')
|
||||||
def getPlayer():
|
def getPlayer():
|
||||||
playerId = flask.request.args.get("id")
|
playerId = flask.request.args.get("id")
|
||||||
|
|||||||
Reference in New Issue
Block a user