-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for parsing killstreaks from logs. These can be useful for finding clips for frag movies. I didn't add them to the totals page since as an extrema-based statistic, the only thing we can really show is max/count. I think those are better shown on the logs page. Closes: #75 Signed-off-by: Sean Anderson <[email protected]>
- Loading branch information
Showing
10 changed files
with
177 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# SPDX-License-Identifier: AGPL-3.0-only | ||
# Copyright (C) 2024 Sean Anderson <[email protected]> | ||
|
||
import logging | ||
import sys | ||
|
||
import psycopg2.extras | ||
|
||
from ..importer.cli import init_logging | ||
from ..sql import db_connect | ||
from ..steamid import SteamID | ||
from ..util import chunk | ||
|
||
def migrate(database): | ||
init_logging(logging.DEBUG) | ||
with db_connect(database) as c: | ||
with c.cursor() as cur: | ||
logging.info("BEGIN") | ||
cur.execute("BEGIN"); | ||
logging.info("CREATE TABLE killstreak") | ||
cur.execute(""" | ||
CREATE TABLE killstreak ( | ||
logid INT NOT NULL, | ||
playerid INT NOT NULL, | ||
time INT NOT NULL, | ||
kills INT NOT NULL CHECK (kills > 0), | ||
PRIMARY KEY (playerid, logid, time) | ||
);""") | ||
|
||
with c.cursor(name='streaks') as streaks: | ||
streaks.execute(""" | ||
SELECT | ||
logid, | ||
streak -> 'steamid' AS steamid, | ||
streak -> 'time' AS time, | ||
streak -> 'streak' AS kills | ||
FROM (SELECT | ||
logid, | ||
json_array_elements(data -> 'killstreaks') AS streak | ||
FROM log_json | ||
) AS killstreak;""") | ||
for streaks in chunk(streaks, streaks.itersize): | ||
values = [] | ||
for streak in streaks: | ||
try: | ||
values.append((streak[0], SteamID(streak[1]), streak[2], streak[3])) | ||
except ValueError: | ||
continue | ||
logging.info("INSERT killstreak") | ||
psycopg2.extras.execute_values(cur, """ | ||
INSERT INTO killstreak ( | ||
logid, | ||
playerid, | ||
time, | ||
kills | ||
) SELECT | ||
logid, | ||
playerid, | ||
time, | ||
killstreak.kills | ||
FROM (VALUES %s) AS killstreak (logid, steamid64, time, kills) | ||
JOIN player USING (steamid64) | ||
JOIN player_stats USING (logid, playerid) | ||
ON CONFLICT DO NOTHING;""", | ||
values, "(%s, %s, %s, %s)") | ||
|
||
logging.info("ALTER TABLE") | ||
cur.execute(""" | ||
ALTER TABLE killstreak | ||
ADD FOREIGN KEY (logid, playerid) | ||
REFERENCES player_stats_backing (logid, playerid);""") | ||
logging.info("COMMIT") | ||
cur.execute("COMMIT;") | ||
|
||
if __name__ == "__main__": | ||
migrate(sys.argv[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters