mirror of
https://github.com/FAUSheppy/skillbird
synced 2025-12-06 06:51:34 +01:00
implement last game for db
This commit is contained in:
@@ -29,7 +29,7 @@ class Round:
|
|||||||
|
|
||||||
### Sync players from Databse ###
|
### Sync players from Databse ###
|
||||||
for p in self.winners + self.losers:
|
for p in self.winners + self.losers:
|
||||||
playerInDB = db.getOrCreatePlayer(p)
|
playerInDB = db.getOrCreatePlayer(p, startTime)
|
||||||
p.rating = playerInDB.rating
|
p.rating = playerInDB.rating
|
||||||
|
|
||||||
self.prediction, self.confidence = ts.predictOutcome(self.winners, self.losers)
|
self.prediction, self.confidence = ts.predictOutcome(self.winners, self.losers)
|
||||||
|
|||||||
@@ -90,10 +90,10 @@ def getPlayerRank(player):
|
|||||||
conn.close()
|
conn.close()
|
||||||
return rank
|
return rank
|
||||||
|
|
||||||
def getOrCreatePlayer(player):
|
def getOrCreatePlayer(player, timestamp=None):
|
||||||
playerInDb = getPlayer(player.id)
|
playerInDb = getPlayer(player.id)
|
||||||
if not playerInDb:
|
if not playerInDb:
|
||||||
return savePlayerToDatabase(player)
|
return savePlayerToDatabase(player, timestamp=timestamp)
|
||||||
else:
|
else:
|
||||||
return playerInDb
|
return playerInDb
|
||||||
|
|
||||||
@@ -117,11 +117,13 @@ def savePlayerToDatabase(player, incrementWins=0, timestamp=None):
|
|||||||
sigma = ?,
|
sigma = ?,
|
||||||
games = ?
|
games = ?
|
||||||
WHERE id = ?''',
|
WHERE id = ?''',
|
||||||
(player.id, player.name, None, playerFromDatabase.wins + incrementWins,
|
(player.id, player.name, timestamp.timestamp(),
|
||||||
player.rating.mu, player.rating.sigma, playerFromDatabase.games + 1, player.id))
|
playerFromDatabase.wins + incrementWins,
|
||||||
|
player.rating.mu, player.rating.sigma, playerFromDatabase.games + 1,
|
||||||
|
player.id))
|
||||||
else:
|
else:
|
||||||
cursor.execute("INSERT INTO players VALUES (?,?,?,?,?,?,?)",
|
cursor.execute("INSERT INTO players VALUES (?,?,?,?,?,?,?)",
|
||||||
(player.id, player.name, None, 0,
|
(player.id, player.name, timestamp.timestamp(), 0,
|
||||||
player.rating.mu, player.rating.sigma, 0))
|
player.rating.mu, player.rating.sigma, 0))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user