diff --git a/python/Round.py b/python/Round.py index 2c999fb..b6b223f 100644 --- a/python/Round.py +++ b/python/Round.py @@ -3,6 +3,7 @@ import datetime as dt import dateutil.parser import backends.entities.Players as Players import backends.database as db +import backends.trueskillWrapper as ts ## A comment on why the login-offset is nessesary ## ## - losing teams tend to have players leaving and joining more rapidly @@ -31,7 +32,7 @@ class Round: playerInDB = db.getOrCreatePlayer(p) p.rating = playerInDB.rating - + self.prediction, self.confidence = ts.predictOutcome(self.winners, self.losers) def normalized_playtimes(self): '''returns a dict-Object with {key=(teamid,player):value=player_time_played/total_time_of_round}''' diff --git a/python/backends/database.py b/python/backends/database.py index 6609251..a3700bd 100644 --- a/python/backends/database.py +++ b/python/backends/database.py @@ -1,11 +1,27 @@ import sqlite3 +import json import backends.entities.Players as Players import backends.trueskillWrapper as trueskill # setup # create TABLE players (id TEXT PRIMARY KEY, name TEXT, lastgame TEXT, wins INTEGER, mu REAL, sigma REAL, game INTEGER); +# create TABLE rounds (timestamp TEXT PRIMARY KEY, winners BLOB, losers BLOB, winnerSide INTEGER, map TEXT, duration INTEGER, prediction REAL, confidence REAL) DATABASE = "players.sqlite" +DATABASE_ROUNDS = "rounds.sqlite" + +def saveRound(r): + conn = sqlite3.connect(DATABASE_ROUNDS) + cursor = conn.cursor() + cursor.execute("INSERT INTO rounds VALUES (?,?,?,?,?,?,?,?)", (r.start.timestamp(), + json.dumps([ p.toJson() for p in r.winners ]), + json.dumps([ p.toJson() for p in r.losers ]), + r.winnerSide, r.map, r.duration.total_seconds(), + r.prediction, r.confidence)) + + conn.commit() + conn.close() + def getPlayer(playerId): conn = sqlite3.connect("players.sqlite") diff --git a/python/backends/entities/Players.py b/python/backends/entities/Players.py index bfd4d54..6b0d9b8 100644 --- a/python/backends/entities/Players.py +++ b/python/backends/entities/Players.py @@ -34,6 +34,15 @@ class PlayerInRound(Player): self.is_fake = is_fake self.timestamp = timestamp + def toJson(self): + retDict = { "name" : self.name, + "id" : self.id, + "active_time" : self.activeTime.total_seconds(), + "timestamp" : self.timestamp.timestamp(), + "team" : self.team + } + return retDict + def __str__(self): return "PlayerInRound: N: {} ID: {} Team: {}".format(self.name, self.id, self.team) diff --git a/python/httpAPI.py b/python/httpAPI.py index 81ffcd8..0b318eb 100644 --- a/python/httpAPI.py +++ b/python/httpAPI.py @@ -122,6 +122,8 @@ def eventBlob(): def evaluateRound(matchRound): '''Run a match round throught the backand (includeing persisting it''' + db.saveRound(matchRound) + # winners/losers are both dictionaries in the form of { PlayerInDatabase : newRating } # winnersRated, losersRated = ts.evaluateRound(matchRound)