implement round->sql support

This commit is contained in:
Yannik Schmidt
2020-06-20 14:24:47 +02:00
parent 31ecac6009
commit 6513451b83
4 changed files with 29 additions and 1 deletions

View File

@@ -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")

View File

@@ -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)