Database#

functions#

All database related functions are here.

class src.db.ReactionStatus(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Enum for reaction status

class src.db.GameStatus(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Enum for game status

property icon#

Status assignment icon

class src.db.Base(**kwargs)[source]#

Declarative base class

Parameters:

DeclarativeBase (_type_) – Basic class that is inherited

metadata: ClassVar[MetaData] = MetaData()#

Refers to the _schema.MetaData collection that will be used for new _schema.Table objects.

registry: ClassVar[_RegistryType] = <sqlalchemy.orm.decl_api.registry object>#

Refers to the _orm.registry in use where new _orm.Mapper objects will be associated.

class src.db.GamePlayerAssociation(**kwargs)[source]#

_summary_

Parameters:

Base (_type_) – _description_

class src.db.Player(**kwargs)[source]#

_summary_

Parameters:

Base (_type_) – _description_

class src.db.League(**kwargs)[source]#

League table

Parameters:

Base (_type_) – Basic class that is inherited

class src.db.Rank(**kwargs)[source]#

List of ranks for each player per game

Parameters:

Base (_type_) – Basic class that is inherited

class src.db.Game(**kwargs)[source]#

Game table

Parameters:

Base (_type_) – Basic class that is inherited

class src.db.Game1PlayerResult(**kwargs)[source]#

Class table for game 1.

Parameters:

Base (_type_) – Basic class that is inherited

class src.db.Exercise(**kwargs)[source]#

Exercise table

Parameters:

Base (_type_) – Basic class that is inherited

class src.db.Quest(**kwargs)[source]#

Quests table

Parameters:

Base (_type_) – Basic class that is inherited

class src.db.Task(**kwargs)[source]#

Task table

Parameters:

Base (_type_) – Basic class that is inherited

class src.db.Reaction(**kwargs)[source]#

Reaction table

Parameters:

Base (_type_) – Basic class that is inherited

async src.db.get_player(config, player_id)[source]#

Function to get a player from the database by dc_id

Parameters:
  • config (_type_) – App configuration

  • player (Player) – Player object to search for

Returns:

Player object from the database or None if not found

Return type:

Player

async src.db.get_game_from_id(config, game_id)[source]#

Function to get a game from the database by id

Parameters:
  • config (Configuration) – App configuration

  • game_id (str) – Game id from DB

Returns:

Game object from the database or None if not found

Return type:

Game

async src.db.process_player(config, player_list)[source]#

Function to process a player list and add them to the database if they are not already there. Also update the hours of a player if there are new values.

Parameters:
  • config (_type_) – _description_

  • player_list (list[Player]) – List of players to process

Returns:

processed player list

Return type:

list[Player]

async src.db.create_game(config, game_name, player)[source]#

Function to create a game in the database and link all players to the game.

Parameters:
  • config (Configuration) – App configuration

  • game_name (str) – Game name

  • player (list[Player]) – All players in the game

Returns:

Object of the created game for further processing

Return type:

Game

async src.db.get_game_player_association(config, game_id, player_id)[source]#

Funktion to get a game player association from the database by game id and player id.

Parameters:
  • config (Configuration) – App configuration

  • game_id (int) – Game ID

  • player_id (int) – Player ID

Returns:

Object of the game player association or None if not found

Return type:

GamePlayerAssociation | None

async src.db.get_games_w_status(config, status)[source]#

This function get all changeable games back. Games that have the status CREATED, RUNNING or PAUSED can be changed.

Parameters:

config (Configuration) – App configuration

Returns:

The list if changeable games

Return type:

list[Game]

async src.db.get_games_f_reaction(config)[source]#

_summary_

Parameters:

config (Configuration) – app configuration

Returns:

valid games to track reactions or None if no games found

Return type:

list[Game] | None

async src.db.get_random_tasks(config, limit, rating_min=0, rating_max=101)[source]#

This function gets a list of random tasks from the database. The number of tasks is limited by the limit parameter.

Parameters:
  • config (Configuration) – App configuration

  • limit (int) – number of tasks to get

Returns:

Tasks from the database

Return type:

list[Task]

async src.db.get_main_task(config)[source]#

Funktion to get a random main task from the database for game 1

Parameters:

config (Configuration) – App configuration

Returns:

main task

Return type:

Task

async src.db.get_tasks_based_on_rating_1(config, rating)[source]#

This function gets a list of tasks from the database based on the rating for game 1. The rating is used to filter the tasks.

Parameters:
  • config (Configuration) – App configuration

  • rating (int) – rating to filter the tasks from 0 to 100

Returns:

Tasks from the database

Return type:

list[Task]

async src.db.get_tasks_sort_hard(tasks, number_of_tasks=5)[source]#

Get the top tasks based on their rating sorted by hardness (highest rating first).

Parameters:
  • tasks (list[Task]) – List of Task objects to sort.

  • number_of_tasks (int, optional) – Number of tasks to return. Defaults to 5.

Returns:

Sorted list of Task objects, limited to the specified number of tasks.

Return type:

list[Task]

async src.db.get_tasks_sort_soft(tasks, number_of_tasks=5)[source]#

Get the top tasks based on their rating sorted by hardness (lowest rating first).

Parameters:
  • tasks (list[Task]) – List of Task objects to sort.

  • number_of_tasks (int, optional) – Number of tasks to return. Defaults to 5.

Returns:

Sorted list of Task objects, limited to the specified number of tasks.

Return type:

list[Task]

async src.db.balanced_task_mix(tasks, number_of_tasks=5)[source]#

This function creates a balanced task mix from the list of tasks. The tasks are sorted by rating and the list is divided into equal parts. There is one task from each of the different difficulty levels.

Returns:

Balanced task mix

Return type:

list[Task]

async src.db.balanced_task_mix_random(config, tasks, exclude_ids)[source]#

This function creates a balanced random task mix from the list of tasks. The tasks are sorted by rating and the list is divided into equal parts. There is one task from each of the different difficulty levels.

Returns:

Balanced task mix

Return type:

list[Task]

async src.db.get_all_game_x_player_from_message_id(config, message_id)[source]#

Function get all games based on message_id with join off all players in the game.

Parameters:
  • config (Configuration) – App configuration

  • message_id (int) – Message ID from Game

Returns:

All games with players based on message_id

Return type:

list[Game]

async src.db.get_all_db_obj_from_id(config, obj, ids)[source]#

Function returns all objects from database based on given IDs from handed over object class.

Parameters:
  • config (Configuration) – App configuration

  • obj (Player) – Object class to get from database

  • ids (list[int]) – List of IDs to get from database

Returns:

List of objects from database based on IDs and handed over class

Return type:

list[Player]

async src.db.update_db_obj(config, obj)[source]#

Function to update a game or player object in the database

Parameters:
Return type:

Union[Game, Player, Exercise, Reaction, Game1PlayerResult]

async src.db.update_db_objs(config, objs)[source]#

Function to update a game or player object in the database

Parameters:
Return type:

None

async src.db.insert_db_obj(config, obj)[source]#

Fuction to insert a new handed over object into the database and return the object.

Parameters:
  • config (Configuration) – App configuration

  • obj (Reaction) – Handed over object to insert into the database

Returns:

Inserted and updated object

Return type:

Reaction

async src.db.get_reaction_for_remove(config, message_id, user_id, emoji_name)[source]#

Get all reactions for a given message ID, user ID and emoji name.

Parameters:
  • config (Configuration) – App configuration

  • message_id (int) – Message ID to search for

  • user_id (int) – User ID to search for

  • emoji_name (str) – Emoji to search for

Returns:

Reaction object if found, otherwise None

Return type:

Reaction | None

async src.db.set_reaction_status(config, reactions, status)[source]#

Set the status of a list of reactions to a given status.

Parameters:
  • config (Configuration) – App configuration

  • reactions (list[Reaction]) – List of Reaction objects to update

  • status (ReactionStatus) – Status to set for the reactions

Return type:

None

async src.db.get_reaction(config, message_id, user_id, status)[source]#

Function to get all reactions for a given message ID, user ID and status.

Parameters:
  • config (Configuration) – App configuration

  • message_id (int) – Message ID to search from DC

  • user_id (int) – Disscord user ID

  • status (ReactionStatus) – Status from reaction to search for

Returns:

List of reactions or None if an error occurs

Return type:

list[Reaction] | None

async src.db.merging_calc_base_game_1(config, game_ids)[source]#

Function prepares the ranking for game 1 based on the game IDs. The ranking is based on the number of completed tasks, survival status and player days.

Parameters:
  • config (Configuration) – App configuration

  • game_ids (list[int]) – Game IDs to determine the ranks for

Returns:

List of Game1PlayerResult objects with determined ranks

Return type:

list[Game1PlayerResult]

async src.db.schedule_new_league_table(config, sorted_players)[source]#

Function to create a new league table based on the sorted players. First the old league table is deleted and then the new one is created based on the sorted players with their points and survived games.

Parameters:
  • config (Configuration) – App configuration

  • sorted_players (list[tuple]) – Sorted list of players with their points and survived games

Return type:

None

async src.db.get_all_game_days(config)[source]#

Function to get the total number of playing days from all finished games in the database.

Parameters:

config (Configuration) – App configuration

Returns:

Total number of playing days from all finished games

Return type:

int

async src.db.sync_db(engine)[source]#

Function to run the sync command and create all DB dependencies and tables

Parameters:

engine (AsyncEngine) – The engine to run the sync command