mirror of
https://github.com/FAUSheppy/skillbird
synced 2025-12-08 07:31:35 +01:00
implement live game logging
This commit is contained in:
@@ -36,6 +36,41 @@ def check():
|
|||||||
else:
|
else:
|
||||||
return (count, avgPred)
|
return (count, avgPred)
|
||||||
|
|
||||||
|
def logLiveState(jsonDict, trackingId):
|
||||||
|
'''Log live state for leaderboard'''
|
||||||
|
|
||||||
|
conn = sqlite3.connect(DATABASE)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("SELECT time FROM live WHERE id = ?", (trackingId,))
|
||||||
|
row = cursor.fetchone()
|
||||||
|
|
||||||
|
if row:
|
||||||
|
startTime = dt.datetime.fromtimestamp(int(row[0]))
|
||||||
|
duration = dt.datetime.now() - startTime
|
||||||
|
|
||||||
|
# check age of entry #
|
||||||
|
if duration < dt.timedelta(minutes=60):
|
||||||
|
cursor.execute("UPDATE live SET duration = ?, players = ? WHERE id = ?", (
|
||||||
|
int(duration.total_seconds()),
|
||||||
|
json.dumps(jsonDict["players"]),
|
||||||
|
trackingId))
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
cursor.execute("DELETE FROM live WHERE id = ?", (trackingId,))
|
||||||
|
|
||||||
|
startTime = dt.datetime.now()
|
||||||
|
duration = dt.timedelta(0)
|
||||||
|
cursor.execute("INSERT INTO live VALUES (?,?,?,?)", (
|
||||||
|
trackingId,
|
||||||
|
int(startTime.timestamp()),
|
||||||
|
int(duration.total_seconds()),
|
||||||
|
json.dumps(jsonDict["players"])))
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
def logHistoricalData(player, timestamp):
|
def logHistoricalData(player, timestamp):
|
||||||
if not timestamp:
|
if not timestamp:
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -102,6 +102,10 @@ def singleEvent():
|
|||||||
print("Removed orphaned session file: {}".format(fullPath), file=sys.stderr)
|
print("Removed orphaned session file: {}".format(fullPath), file=sys.stderr)
|
||||||
os.remove(fullPath)
|
os.remove(fullPath)
|
||||||
|
|
||||||
|
# update live stats #
|
||||||
|
if jsonDict["etype"] == "active_players":
|
||||||
|
db.logLiveState(jsonDict, session)
|
||||||
|
|
||||||
if jsonDict["etype"] == ROUND_END_IDENT:
|
if jsonDict["etype"] == ROUND_END_IDENT:
|
||||||
events = []
|
events = []
|
||||||
with open(fullPath, "r") as f:
|
with open(fullPath, "r") as f:
|
||||||
|
|||||||
@@ -8,3 +8,4 @@ CREATE TABLE players(
|
|||||||
games INTEGER);
|
games INTEGER);
|
||||||
|
|
||||||
create TABLE playerHistoricalData (id TEXT, timestamp TEXT, mu REAL, sima REAL);
|
create TABLE playerHistoricalData (id TEXT, timestamp TEXT, mu REAL, sima REAL);
|
||||||
|
create TABLE live (id text, time INTEGER, duration INTEGER, players TEXT);
|
||||||
|
|||||||
Reference in New Issue
Block a user