mirror of
https://github.com/FAUSheppy/skillbird
synced 2025-12-06 06:51:34 +01:00
implement live game logging
This commit is contained in:
@@ -36,6 +36,41 @@ def check():
|
||||
else:
|
||||
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):
|
||||
if not timestamp:
|
||||
return
|
||||
|
||||
@@ -102,6 +102,10 @@ def singleEvent():
|
||||
print("Removed orphaned session file: {}".format(fullPath), file=sys.stderr)
|
||||
os.remove(fullPath)
|
||||
|
||||
# update live stats #
|
||||
if jsonDict["etype"] == "active_players":
|
||||
db.logLiveState(jsonDict, session)
|
||||
|
||||
if jsonDict["etype"] == ROUND_END_IDENT:
|
||||
events = []
|
||||
with open(fullPath, "r") as f:
|
||||
|
||||
@@ -8,3 +8,4 @@ CREATE TABLE players(
|
||||
games INTEGER);
|
||||
|
||||
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