-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
699 additions
and
399 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
Large diffs are not rendered by default.
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
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,4 +1,4 @@ | ||
__author__ = "Askaholic, Clemens Borys" | ||
__author__ = "Askaholic, BlackYps, Clemens Borys" | ||
__contact__ = "[email protected]" | ||
__license__ = "GPLv3" | ||
__copyright__ = "Copyright (c) 2020 " + __author__ |
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,113 @@ | ||
SET time_zone='+00:00'; | ||
|
||
SELECT @Seasonnumber := MAX(season_number) FROM league_season; | ||
SET @Seasonnumber = @Seasonnumber + 1; | ||
|
||
SET @start_date = ADDDATE(LAST_DAY(CURRENT_DATE), 1); | ||
SET @end_date = LAST_DAY(ADD_MONTHS(CURRENT_DATE, 3)); | ||
|
||
-- season starts and ends at noon, so that all timezones see the same date in the client | ||
INSERT INTO league_season (id, league_id, leaderboard_id, placement_games, season_number, name_key, start_date, end_date) VALUES | ||
(@Seasonnumber * 3, 1, 2, 10, @Seasonnumber, "1v1_season", TIMESTAMP(@start_date, "12:00:00"), TIMESTAMP(@end_date, "12:00:00")), | ||
(@Seasonnumber * 3 + 1, 2, 3, 10, @Seasonnumber, "2v2_season", TIMESTAMP(@start_date, "12:00:00"), TIMESTAMP(@end_date, "12:00:00")), | ||
(@Seasonnumber * 3 + 2, 3, 4, 10, @Seasonnumber, "4v4_fs_season", TIMESTAMP(@start_date, "12:00:00"), TIMESTAMP(@end_date, "12:00:00")); | ||
|
||
INSERT INTO league_season_division (id, league_season_id, division_index, description_key, name_key) VALUES | ||
(@Seasonnumber * 18 - 6 + 1, @Seasonnumber * 3 , 1, CONCAT("1v1_season_", @Seasonnumber, ".division.1"), "bronze"), | ||
(@Seasonnumber * 18 - 6 + 2, @Seasonnumber * 3 , 2, CONCAT("1v1_season_", @Seasonnumber, ".division.2"), "silver"), | ||
(@Seasonnumber * 18 - 6 + 3, @Seasonnumber * 3 , 3, CONCAT("1v1_season_", @Seasonnumber, ".division.3"), "gold"), | ||
(@Seasonnumber * 18 - 6 + 4, @Seasonnumber * 3 , 4, CONCAT("1v1_season_", @Seasonnumber, ".division.4"), "diamond"), | ||
(@Seasonnumber * 18 - 6 + 5, @Seasonnumber * 3 , 5, CONCAT("1v1_season_", @Seasonnumber, ".division.5"), "master"), | ||
(@Seasonnumber * 18 - 6 + 6, @Seasonnumber * 3 , 6, CONCAT("1v1_season_", @Seasonnumber, ".division.6"), "grandmaster"), | ||
(@Seasonnumber * 18 - 6 + 7, @Seasonnumber * 3 + 1, 1, CONCAT("2v2_season_", @Seasonnumber, ".division.1"), "bronze"), | ||
(@Seasonnumber * 18 - 6 + 8, @Seasonnumber * 3 + 1, 2, CONCAT("2v2_season_", @Seasonnumber, ".division.2"), "silver"), | ||
(@Seasonnumber * 18 - 6 + 9, @Seasonnumber * 3 + 1, 3, CONCAT("2v2_season_", @Seasonnumber, ".division.3"), "gold"), | ||
(@Seasonnumber * 18 - 6 + 10, @Seasonnumber * 3 + 1, 4, CONCAT("2v2_season_", @Seasonnumber, ".division.4"), "diamond"), | ||
(@Seasonnumber * 18 - 6 + 11, @Seasonnumber * 3 + 1, 5, CONCAT("2v2_season_", @Seasonnumber, ".division.5"), "master"), | ||
(@Seasonnumber * 18 - 6 + 12, @Seasonnumber * 3 + 1, 6, CONCAT("2v2_season_", @Seasonnumber, ".division.6"), "grandmaster"), | ||
(@Seasonnumber * 18 - 6 + 13, @Seasonnumber * 3 + 2, 1, CONCAT("4v4_fs_season_", @Seasonnumber, ".division.1"), "bronze"), | ||
(@Seasonnumber * 18 - 6 + 14, @Seasonnumber * 3 + 2, 2, CONCAT("4v4_fs_season_", @Seasonnumber, ".division.2"), "silver"), | ||
(@Seasonnumber * 18 - 6 + 15, @Seasonnumber * 3 + 2, 3, CONCAT("4v4_fs_season_", @Seasonnumber, ".division.3"), "gold"), | ||
(@Seasonnumber * 18 - 6 + 16, @Seasonnumber * 3 + 2, 4, CONCAT("4v4_fs_season_", @Seasonnumber, ".division.4"), "diamond"), | ||
(@Seasonnumber * 18 - 6 + 17, @Seasonnumber * 3 + 2, 5, CONCAT("4v4_fs_season_", @Seasonnumber, ".division.5"), "master"), | ||
(@Seasonnumber * 18 - 6 + 18, @Seasonnumber * 3 + 2, 6, CONCAT("4v4_fs_season_", @Seasonnumber, ".division.6"), "grandmaster"); | ||
|
||
INSERT INTO league_season_division_subdivision (league_season_division_id, subdivision_index, description_key, min_rating, max_rating, highest_score, name_key) VALUES | ||
(@Seasonnumber * 18 - 6 + 1, 1, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.1.1"), -800, -40, 10, "V"), | ||
(@Seasonnumber * 18 - 6 + 1, 2, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.1.2"), -40, 45, 10, "IV"), | ||
(@Seasonnumber * 18 - 6 + 1, 3, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.1.3"), 45, 130, 10, "III"), | ||
(@Seasonnumber * 18 - 6 + 1, 4, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.1.4"), 130, 215, 10, "II"), | ||
(@Seasonnumber * 18 - 6 + 1, 5, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.1.5"), 215, 300, 10, "I"), | ||
(@Seasonnumber * 18 - 6 + 2, 1, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.2.1"), 300, 385, 10, "V"), | ||
(@Seasonnumber * 18 - 6 + 2, 2, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.2.2"), 385, 470, 10, "IV"), | ||
(@Seasonnumber * 18 - 6 + 2, 3, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.2.3"), 470, 555, 10, "III"), | ||
(@Seasonnumber * 18 - 6 + 2, 4, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.2.4"), 555, 640, 10, "II"), | ||
(@Seasonnumber * 18 - 6 + 2, 5, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.2.5"), 640, 725, 10, "I"), | ||
(@Seasonnumber * 18 - 6 + 3, 1, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.3.1"), 725, 810, 10, "V"), | ||
(@Seasonnumber * 18 - 6 + 3, 2, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.3.2"), 810, 895, 10, "IV"), | ||
(@Seasonnumber * 18 - 6 + 3, 3, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.3.3"), 895, 980, 10, "III"), | ||
(@Seasonnumber * 18 - 6 + 3, 4, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.3.4"), 980, 1065, 10, "II"), | ||
(@Seasonnumber * 18 - 6 + 3, 5, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.3.5"), 1065, 1150, 10, "I"), | ||
(@Seasonnumber * 18 - 6 + 4, 1, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.4.1"), 1150, 1235, 10, "V"), | ||
(@Seasonnumber * 18 - 6 + 4, 2, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.4.2"), 1235, 1320, 10, "IV"), | ||
(@Seasonnumber * 18 - 6 + 4, 3, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.4.3"), 1320, 1405, 10, "III"), | ||
(@Seasonnumber * 18 - 6 + 4, 4, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.4.4"), 1405, 1490, 10, "II"), | ||
(@Seasonnumber * 18 - 6 + 4, 5, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.4.5"), 1490, 1575, 10, "I"), | ||
(@Seasonnumber * 18 - 6 + 5, 1, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.5.1"), 1575, 1660, 10, "V"), | ||
(@Seasonnumber * 18 - 6 + 5, 2, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.5.2"), 1660, 1745, 10, "IV"), | ||
(@Seasonnumber * 18 - 6 + 5, 3, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.5.3"), 1745, 1830, 10, "III"), | ||
(@Seasonnumber * 18 - 6 + 5, 4, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.5.4"), 1830, 1915, 10, "II"), | ||
(@Seasonnumber * 18 - 6 + 5, 5, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.5.5"), 1915, 2000, 10, "I"), | ||
(@Seasonnumber * 18 - 6 + 6, 1, CONCAT("1v1_season_", @Seasonnumber, ".subdivision.6.1"), 2000, 2850, 100, ""), | ||
(@Seasonnumber * 18 - 6 + 7, 1, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.1.1"), -800, -40, 10, "V"), | ||
(@Seasonnumber * 18 - 6 + 7, 2, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.1.2"), -40, 45, 10, "IV"), | ||
(@Seasonnumber * 18 - 6 + 7, 3, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.1.3"), 45, 130, 10, "III"), | ||
(@Seasonnumber * 18 - 6 + 7, 4, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.1.4"), 130, 215, 10, "II"), | ||
(@Seasonnumber * 18 - 6 + 7, 5, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.1.5"), 215, 300, 10, "I"), | ||
(@Seasonnumber * 18 - 6 + 8, 1, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.2.1"), 300, 385, 10, "V"), | ||
(@Seasonnumber * 18 - 6 + 8, 2, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.2.2"), 385, 470, 10, "IV"), | ||
(@Seasonnumber * 18 - 6 + 8, 3, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.2.3"), 470, 555, 10, "III"), | ||
(@Seasonnumber * 18 - 6 + 8, 4, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.2.4"), 555, 640, 10, "II"), | ||
(@Seasonnumber * 18 - 6 + 8, 5, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.2.5"), 640, 725, 10, "I"), | ||
(@Seasonnumber * 18 - 6 + 9, 1, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.3.1"), 725, 810, 10, "V"), | ||
(@Seasonnumber * 18 - 6 + 9, 2, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.3.2"), 810, 895, 10, "IV"), | ||
(@Seasonnumber * 18 - 6 + 9, 3, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.3.3"), 895, 980, 10, "III"), | ||
(@Seasonnumber * 18 - 6 + 9, 4, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.3.4"), 980, 1065, 10, "II"), | ||
(@Seasonnumber * 18 - 6 + 9, 5, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.3.5"), 1065, 1150, 10, "I"), | ||
(@Seasonnumber * 18 - 6 + 10, 1, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.4.1"), 1150, 1235, 10, "V"), | ||
(@Seasonnumber * 18 - 6 + 10, 2, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.4.2"), 1235, 1320, 10, "IV"), | ||
(@Seasonnumber * 18 - 6 + 10, 3, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.4.3"), 1320, 1405, 10, "III"), | ||
(@Seasonnumber * 18 - 6 + 10, 4, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.4.4"), 1405, 1490, 10, "II"), | ||
(@Seasonnumber * 18 - 6 + 10, 5, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.4.5"), 1490, 1575, 10, "I"), | ||
(@Seasonnumber * 18 - 6 + 11, 1, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.5.1"), 1575, 1660, 10, "V"), | ||
(@Seasonnumber * 18 - 6 + 11, 2, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.5.2"), 1660, 1745, 10, "IV"), | ||
(@Seasonnumber * 18 - 6 + 11, 3, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.5.3"), 1745, 1830, 10, "III"), | ||
(@Seasonnumber * 18 - 6 + 11, 4, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.5.4"), 1830, 1915, 10, "II"), | ||
(@Seasonnumber * 18 - 6 + 11, 5, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.5.5"), 1915, 2000, 10, "I"), | ||
(@Seasonnumber * 18 - 6 + 12, 1, CONCAT("2v2_season_", @Seasonnumber, ".subdivision.6.1"), 2000, 2850, 100, ""), | ||
(@Seasonnumber * 18 - 6 + 13, 1, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.1.1"), -800, -40, 10, "V"), | ||
(@Seasonnumber * 18 - 6 + 13, 2, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.1.2"), -40, 45, 10, "IV"), | ||
(@Seasonnumber * 18 - 6 + 13, 3, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.1.3"), 45, 130, 10, "III"), | ||
(@Seasonnumber * 18 - 6 + 13, 4, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.1.4"), 130, 215, 10, "II"), | ||
(@Seasonnumber * 18 - 6 + 13, 5, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.1.5"), 215, 300, 10, "I"), | ||
(@Seasonnumber * 18 - 6 + 14, 1, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.2.1"), 300, 385, 10, "V"), | ||
(@Seasonnumber * 18 - 6 + 14, 2, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.2.2"), 385, 470, 10, "IV"), | ||
(@Seasonnumber * 18 - 6 + 14, 3, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.2.3"), 470, 555, 10, "III"), | ||
(@Seasonnumber * 18 - 6 + 14, 4, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.2.4"), 555, 640, 10, "II"), | ||
(@Seasonnumber * 18 - 6 + 14, 5, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.2.5"), 640, 725, 10, "I"), | ||
(@Seasonnumber * 18 - 6 + 15, 1, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.3.1"), 725, 810, 10, "V"), | ||
(@Seasonnumber * 18 - 6 + 15, 2, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.3.2"), 810, 895, 10, "IV"), | ||
(@Seasonnumber * 18 - 6 + 15, 3, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.3.3"), 895, 980, 10, "III"), | ||
(@Seasonnumber * 18 - 6 + 15, 4, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.3.4"), 980, 1065, 10, "II"), | ||
(@Seasonnumber * 18 - 6 + 15, 5, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.3.5"), 1065, 1150, 10, "I"), | ||
(@Seasonnumber * 18 - 6 + 16, 1, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.4.1"), 1150, 1235, 10, "V"), | ||
(@Seasonnumber * 18 - 6 + 16, 2, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.4.2"), 1235, 1320, 10, "IV"), | ||
(@Seasonnumber * 18 - 6 + 16, 3, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.4.3"), 1320, 1405, 10, "III"), | ||
(@Seasonnumber * 18 - 6 + 16, 4, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.4.4"), 1405, 1490, 10, "II"), | ||
(@Seasonnumber * 18 - 6 + 16, 5, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.4.5"), 1490, 1575, 10, "I"), | ||
(@Seasonnumber * 18 - 6 + 17, 1, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.5.1"), 1575, 1660, 10, "V"), | ||
(@Seasonnumber * 18 - 6 + 17, 2, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.5.2"), 1660, 1745, 10, "IV"), | ||
(@Seasonnumber * 18 - 6 + 17, 3, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.5.3"), 1745, 1830, 10, "III"), | ||
(@Seasonnumber * 18 - 6 + 17, 4, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.5.4"), 1830, 1915, 10, "II"), | ||
(@Seasonnumber * 18 - 6 + 17, 5, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.5.5"), 1915, 2000, 10, "I"), | ||
(@Seasonnumber * 18 - 6 + 18, 1, CONCAT("4v4_fs_season_", @Seasonnumber, ".subdivision.6.1"), 2000, 2850, 100, ""); |
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,45 @@ | ||
from datetime import datetime, timedelta | ||
|
||
import aiocron | ||
from sqlalchemy import select, text | ||
|
||
from service.config import SEASON_GENERATION_DAYS_BEFORE_SEASON_END | ||
from service.db import FAFDatabase | ||
from service.db.models import league_season | ||
from service.decorators import with_logger | ||
|
||
|
||
@with_logger | ||
class SeasonGenerator: | ||
def __init__(self, database: FAFDatabase): | ||
self._logger.info("Season generator created.") | ||
self._db = database | ||
|
||
def initialize(self): | ||
self._update_cron = aiocron.crontab( | ||
"0 0 * * *", func=self.check_season_end | ||
) | ||
|
||
async def check_season_end(self): | ||
self._logger.debug("Checking if latest season ends soon.") | ||
async with self._db.acquire() as conn: | ||
sql = select([league_season]) | ||
result = await conn.execute(sql) | ||
rows = await result.fetchall() | ||
|
||
max_date = max(row[league_season.c.end_date] for row in rows) | ||
|
||
if max_date < datetime.now() + timedelta(days=SEASON_GENERATION_DAYS_BEFORE_SEASON_END): | ||
try: | ||
await self.generate_season() | ||
except Exception: | ||
self._logger.exception("Failed to generate new season") | ||
else: | ||
self._logger.info("Season successfully created!") | ||
|
||
async def generate_season(self): | ||
self._logger.info("Generating new season...") | ||
async with self._db.acquire() as conn: | ||
with open("service/generate_season.sql") as file: | ||
query = text(file.read()) | ||
await conn.execute(query) |
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.