From 1d28b90e76281959f863820a15eef1ce0db21059 Mon Sep 17 00:00:00 2001 From: "jmosrael@gmail.com" Date: Thu, 23 May 2024 23:42:48 -0700 Subject: [PATCH] Update loader, add event and fix count to api --- backend/src/app.ts | 2 ++ backend/src/db.ts | 2 +- loader/databasesync.py | 26 ++++++++++++++++++++------ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/backend/src/app.ts b/backend/src/app.ts index bf9d6c5..ab7193c 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -36,6 +36,8 @@ app.post('/api/serverstats/gamestats', jsonParser, async (req, res) => { 'SUM(CASE WHEN status = "Complete" THEN 1 ELSE 0 END) as Complete, ' + 'SUM(CASE WHEN status = "Postponed" THEN 1 ELSE 0 END) as Postponed, ' + 'SUM(CASE WHEN status = "Pending" THEN 1 ELSE 0 END) as Pending, ' + + 'SUM(event) as Events, ' + + 'SUM(fix) as Fixes, ' + 'SUM(payoutEB) as TotalEB, ' + 'SUM(payoutIP) as TotalIP, ' + 'SUM(payoutEB) / SUM(CASE WHEN status = "Complete" THEN 1 ELSE 0 END) as AverageEB, ' + diff --git a/backend/src/db.ts b/backend/src/db.ts index a7a4842..c12e568 100644 --- a/backend/src/db.ts +++ b/backend/src/db.ts @@ -31,7 +31,7 @@ export const Game = database.define( gamemaster: { type: DataTypes.TEXT }, payoutEB: { type: DataTypes.INTEGER }, payoutIP: { type: DataTypes.INTEGER }, - payputLoot: { type: DataTypes.INTEGER } + payoutLoot: { type: DataTypes.INTEGER } }, { timestamps: false } ) diff --git a/loader/databasesync.py b/loader/databasesync.py index 1e1b3b8..8e30921 100644 --- a/loader/databasesync.py +++ b/loader/databasesync.py @@ -27,7 +27,7 @@ def extractGameFromRow(counter, row): row['Game Title'], row['Game Status'], row['Fix'], - 0, + row['Event'], int(datetime.strptime(row['Game Date'],'%d-%b-%Y').timestamp()) if row['Game Date'] else 0, row['GM'], row['Payout (EB)'], @@ -88,7 +88,7 @@ def loadAppsAndPicks(characterNameToId, gameTitleToId, gameFileName): picks.append(Link(gameId, gameTitle, characterId, characterName)) for i in range(1,51): characterName = row['Applicant {}'.format(i)] - if characterName: + if characterName and characterName in characterNameToId: characterId = characterNameToId[characterName] apps.append(Link(gameId, gameTitle, characterId, characterName)) @@ -103,11 +103,25 @@ def main(): cursor = connection.cursor() for character in characters: cursor.execute(""" - REPLACE INTO Characters (characterName, id, playerName, role, creationDate, status) - VALUES (?, ?, ?, ?, ?, ?) + REPLACE INTO Characters (characterName, id, playerName, role, creationDate, status) + VALUES (?, ?, ?, ?, ?, ?) """, [character.characterName, character.id, character.playerName, character.role, character.creationDate, character.status]) - + for game in games: + cursor.execute(""" + REPLACE INTO Games (id, title, status, fix, event, postdate, gamemaster, payoutEB, payoutIP, payoutLoot) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + """, [game.id, game.title, game.status, game.fix, game.event, game.postdate, game.gamemaster, game.payouteb, game.payoutip, game.payoutloot]) + for app in apps: + cursor.execute(""" + REPLACE INTO Apps (gameId, gameTitle, characterId, characterName) + VALUES (?, ?, ?, ?) + """, [app.gameId, app.gameTitle, app.characterId, app.characterName]) + for pick in picks: + cursor.execute(""" + REPLACE INTO Picks (gameId, gameTitle, characterId, characterName) + VALUES (?, ?, ?, ?) + """, [pick.gameId, pick.gameTitle, pick.characterId, pick.characterName]) if __name__ == "__main__": - main() \ No newline at end of file + main()