mirror of
https://github.com/FAUSheppy/skillbird
synced 2025-12-06 06:51:34 +01:00
implment collection of historical data
This commit is contained in:
@@ -7,6 +7,7 @@ import backends.trueskillWrapper as trueskill
|
|||||||
# setup
|
# setup
|
||||||
# create TABLE players (id TEXT PRIMARY KEY, name TEXT, lastgame TEXT, wins INTEGER, mu REAL, sigma REAL, game INTEGER);
|
# 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)
|
# create TABLE rounds (timestamp TEXT PRIMARY KEY, winners BLOB, losers BLOB, winnerSide INTEGER, map TEXT, duration INTEGER, prediction REAL, confidence REAL)
|
||||||
|
# create TABLE playerHistoricalData (id TEXT, timestamp TEXT, mu REAL, sima REAL)
|
||||||
|
|
||||||
DATABASE = "players.sqlite"
|
DATABASE = "players.sqlite"
|
||||||
DATABASE_ROUNDS = "rounds.sqlite"
|
DATABASE_ROUNDS = "rounds.sqlite"
|
||||||
@@ -34,6 +35,20 @@ def check():
|
|||||||
else:
|
else:
|
||||||
return (count, avgPred)
|
return (count, avgPred)
|
||||||
|
|
||||||
|
def logHistoricalData(player, timestamp):
|
||||||
|
if not timestamp:
|
||||||
|
return
|
||||||
|
conn = sqlite3.connect(DATABASE)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("INSERT INTO playerHistoricalData VALUES (?,?,?,?)", (
|
||||||
|
player.id,
|
||||||
|
timestamp.timestamp(),
|
||||||
|
player.rating.mu,
|
||||||
|
player.rating.sigma))
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def saveRound(r):
|
def saveRound(r):
|
||||||
conn = sqlite3.connect(DATABASE_ROUNDS)
|
conn = sqlite3.connect(DATABASE_ROUNDS)
|
||||||
@@ -86,7 +101,7 @@ def getOrCreatePlayer(player):
|
|||||||
def getMultiplePlayers(playerIdList):
|
def getMultiplePlayers(playerIdList):
|
||||||
return [ getPlayer(p) for p in playerIdList ]
|
return [ getPlayer(p) for p in playerIdList ]
|
||||||
|
|
||||||
def savePlayerToDatabase(player, incrementWins=0):
|
def savePlayerToDatabase(player, incrementWins=0, timestamp=None):
|
||||||
conn = sqlite3.connect(DATABASE)
|
conn = sqlite3.connect(DATABASE)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
@@ -110,8 +125,27 @@ def savePlayerToDatabase(player, incrementWins=0):
|
|||||||
player.rating.mu, player.rating.sigma, 0))
|
player.rating.mu, player.rating.sigma, 0))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
return getPlayer(player.id)
|
playerDone = getPlayer(player.id)
|
||||||
|
|
||||||
def saveMultiplePlayersToDatabase(playerList, incrementWins=0):
|
logHistoricalData(playerDone, timestamp)
|
||||||
|
return playerDone
|
||||||
|
|
||||||
|
def saveMultiplePlayersToDatabase(playerList, incrementWins=0, timestamp=None):
|
||||||
for p in playerList:
|
for p in playerList:
|
||||||
savePlayerToDatabase(p, incrementWins)
|
savePlayerToDatabase(p, incrementWins, timestamp=timestamp)
|
||||||
|
|
||||||
|
def getBuddyGraphs(players):
|
||||||
|
conn = sqlite3.connect(DATABASE)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
graphs = dict()
|
||||||
|
|
||||||
|
for p in players:
|
||||||
|
rows = []# cursor.execute("SELECT buddy from buddies where playerId = ?;", (p.id,))
|
||||||
|
buddies = [ r[0] for r in rows ]
|
||||||
|
for b in buddies:
|
||||||
|
if b in players:
|
||||||
|
pass
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|||||||
@@ -106,10 +106,13 @@ def predictOutcome(teamA, teamB):
|
|||||||
else:
|
else:
|
||||||
raise ValueError("Probability was NAN, team rating must have been malformed.")
|
raise ValueError("Probability was NAN, team rating must have been malformed.")
|
||||||
|
|
||||||
def balance(players, buddies=None):
|
def balance(players):
|
||||||
sortedByRating = sorted(players, key=lambda p: env.expose(p.rating))
|
sortedByRating = sorted(players, key=lambda p: env.expose(p.rating))
|
||||||
teamA = []
|
teamA = []
|
||||||
teamB = []
|
teamB = []
|
||||||
|
|
||||||
|
graphs = db.getBuddyGraphs(players)
|
||||||
|
|
||||||
for i in range(0, len(players)):
|
for i in range(0, len(players)):
|
||||||
if i % 2 == 0:
|
if i % 2 == 0:
|
||||||
teamA += [sortedByRating[i]]
|
teamA += [sortedByRating[i]]
|
||||||
|
|||||||
@@ -141,5 +141,6 @@ def evaluateRound(matchRound):
|
|||||||
for playerInDatabase in losersRated.keys():
|
for playerInDatabase in losersRated.keys():
|
||||||
playerInDatabase.rating = losersRated[playerInDatabase]
|
playerInDatabase.rating = losersRated[playerInDatabase]
|
||||||
|
|
||||||
db.saveMultiplePlayersToDatabase(winnersRated.keys(), incrementWins=1)
|
db.saveMultiplePlayersToDatabase(winnersRated.keys(), incrementWins=1,
|
||||||
db.saveMultiplePlayersToDatabase(losersRated.keys())
|
timestamp=matchRound.start)
|
||||||
|
db.saveMultiplePlayersToDatabase(losersRated.keys(), timestamp=matchRound.start)
|
||||||
|
|||||||
@@ -6,3 +6,5 @@ CREATE TABLE players(
|
|||||||
mu INTEGER,
|
mu INTEGER,
|
||||||
sigma INTEGER,
|
sigma INTEGER,
|
||||||
games INTEGER);
|
games INTEGER);
|
||||||
|
|
||||||
|
create TABLE playerHistoricalData (id TEXT, timestamp TEXT, mu REAL, sima REAL);
|
||||||
|
|||||||
Reference in New Issue
Block a user