mirror of
https://github.com/FAUSheppy/skillbird
synced 2025-12-06 06:51:34 +01:00
implement round->sql support
This commit is contained in:
@@ -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}'''
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user