-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add sqlalchemy with asyncio * Add test for excluding last played maps * If all maps were played recently, just pick a random one * Query laddergames by looking for "ladder1v1" gamemod * Close db connections when server shuts down * Only return map_id * Clean up imports * Remove mysql specific types * Replace db_pool with sqlalchemy engine everywhere * Add test for empty map pool case * Remove logging cursor * Rename faction "nomads" to "nomad" * Add debug for game timeout * Clean up some formatting * Make sure to fetch ladder results. * Add test for querying ladder history from db. * Set ladder maps correctly. * Replace fetchall with async for iteration where possible. * Refactor update_game_player_stats * Fix stuff I missed during rebase * Row is a dict cursor * Fix column name * Add typing for map tuple
- Loading branch information
Showing
21 changed files
with
607 additions
and
494 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ marisa-trie | |
oauthlib | ||
requests_oauthlib | ||
mock | ||
SQLAlchemy |
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 |
---|---|---|
@@ -1,42 +1,32 @@ | ||
import aiomysql | ||
from .logging_cursor import LoggingCursor | ||
from aiomysql import Pool | ||
from aiomysql.sa import create_engine | ||
|
||
db_pool: Pool = None | ||
engine = None | ||
|
||
|
||
def set_pool(pool: Pool): | ||
def set_engine(engine_): | ||
""" | ||
Set the globally used pool to the given argument | ||
Set the globally used engine to the given argument | ||
""" | ||
global db_pool | ||
db_pool = pool | ||
global engine | ||
engine = engine_ | ||
|
||
|
||
async def connect(loop, | ||
host='localhost', port=3306, user='root', password='', db='faf_test', | ||
minsize=1, maxsize=1, cursorclass=LoggingCursor) -> Pool: | ||
""" | ||
Initialize the database pool | ||
:param loop: | ||
:param host: | ||
:param user: | ||
:param password: | ||
:param db: | ||
:param minsize: | ||
:param maxsize: | ||
:param cursorclass: | ||
:return: | ||
""" | ||
pool = await aiomysql.create_pool(host=host, | ||
port=port, | ||
user=user, | ||
password=password, | ||
db=db, | ||
autocommit=True, | ||
loop=loop, | ||
minsize=minsize, | ||
maxsize=maxsize, | ||
cursorclass=cursorclass) | ||
set_pool(pool) | ||
return pool | ||
async def connect_engine( | ||
loop, host='localhost', port=3306, user='root', password='', db='faf_test', | ||
minsize=1, maxsize=1, echo=True | ||
): | ||
engine = await create_engine( | ||
host=host, | ||
port=port, | ||
user=user, | ||
password=password, | ||
db=db, | ||
autocommit=True, | ||
loop=loop, | ||
minsize=minsize, | ||
maxsize=maxsize, | ||
echo=echo | ||
) | ||
|
||
set_engine(engine) | ||
return engine |
This file was deleted.
Oops, something went wrong.
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,51 @@ | ||
from sqlalchemy import (TIMESTAMP, Boolean, Column, Enum, Float, ForeignKey, | ||
Integer, MetaData, String, Table, Text) | ||
|
||
from ..games.game import Victory | ||
|
||
metadata = MetaData() | ||
|
||
game_featuredMods = Table( | ||
'game_featuredMods', metadata, | ||
Column('id', Integer, primary_key=True), | ||
Column('gamemod', String, unique=True), | ||
Column('descripiton', Text, nullable=False), | ||
Column('name', String, nullable=False), | ||
Column('publish', Boolean, nullable=False, server_default='f'), | ||
Column('order', Integer, nullable=False, server_default='0'), | ||
Column('git_url', String), | ||
Column('git_branch', String), | ||
Column('file_extension',String), | ||
Column('allow_override',Boolean) | ||
) | ||
|
||
game_player_stats = Table( | ||
'game_player_stats', metadata, | ||
Column('id', Integer, primary_key=True), | ||
Column('gameId', Integer, ForeignKey('game_stats.id'), nullable=False), | ||
Column('playerId', Integer, nullable=False), | ||
Column('AI', Boolean, nullable=False), | ||
Column('faction', Integer, nullable=False), | ||
Column('color', Integer, nullable=False), | ||
Column('team', Integer, nullable=False), | ||
Column('place', Integer, nullable=False), | ||
Column('mean', Float, nullable=False), | ||
Column('deviation', Float, nullable=False), | ||
Column('after_mean', Float), | ||
Column('after_deviation', Float), | ||
Column('score', Integer), | ||
Column('scoreTime', TIMESTAMP), | ||
) | ||
|
||
game_stats = Table( | ||
'game_stats', metadata, | ||
Column('id', Integer, primary_key=True), | ||
Column('startTime', TIMESTAMP, nullable=False, server_default="CURRENT_TIMESTAMP"), | ||
Column('endTime', TIMESTAMP), | ||
Column('gameType', Enum(Victory), nullable=False), | ||
Column('gameMod', Integer, ForeignKey('game_featuredMods.id'), nullable=False), | ||
Column('host', Integer, nullable=False), | ||
Column('mapId', Integer), | ||
Column('gameName', String, nullable=False), | ||
Column('validity', Integer, nullable=False), | ||
) |
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
Oops, something went wrong.