app.services package¶
Submodules¶
app.services.base_service module¶
- class app.services.base_service.BaseService(repository)[source]¶
Bases:
object
Base service class providing common CRUD operations.
- repository¶
The repository instance used for database operations.
- add(schema)[source]¶
Adds a new item using the provided schema.
- Parameters:
schema – The schema representing the item to be added.
- Returns:
The added item.
- Return type:
- get_by_id(id: UUID)[source]¶
Retrieves an item by its ID.
- Parameters:
id (UUID) – The unique identifier of the item.
- Returns:
The item with the given ID.
- Return type:
- get_list(schema)[source]¶
Retrieves a list of items based on the provided schema.
- Parameters:
schema – The schema for filtering the items.
- Returns:
A list of items matching the schema.
- Return type:
- patch(id: UUID, schema)[source]¶
Updates an item partially by its ID using the provided schema.
- Parameters:
id (UUID) – The unique identifier of the item.
schema – The schema representing the updated data.
- Returns:
The updated item.
- Return type:
app.services.game_params_service module¶
- class app.services.game_params_service.GameParamsService(game_params_repository: GameParamsRepository)[source]¶
Bases:
BaseService
Service class for game parameters.
- game_params_repository¶
Repository instance for game parameters.
- Type:
app.services.game_service module¶
- class app.services.game_service.GameService(game_repository: GameRepository, game_params_repository: GameParamsRepository, task_repository: TaskRepository, strategy_service: StrategyService)[source]¶
Bases:
BaseService
Service class for managing games.
- game_repository¶
Repository instance for games.
- Type:
- game_params_repository¶
Repository instance for game parameters.
- Type:
- task_repository¶
Repository instance for tasks.
- Type:
- strategy_service¶
Service instance for strategies.
- Type:
- async create(schema: PostCreateGame, api_key: str | None = None, oauth_user_id=None)[source]¶
Creates a new game using the provided schema.
- delete_game_by_id(gameId: UUID)[source]¶
Deletes a game by its game ID.
- Parameters:
gameId (UUID) – The game ID.
- Raises:
NotFoundError – If the game is not found.
- get_by_gameId(gameId: UUID)[source]¶
Retrieves a game by its game ID.
- Parameters:
gameId (UUID) – The game ID.
- Returns:
The game details.
- Return type:
BaseGameResult
- get_strategy_by_externalGameId(externalGameId: str)[source]¶
Retrieves the strategy associated with a game by its external game ID.
- get_strategy_by_gameId(gameId: UUID)[source]¶
Retrieves the strategy associated with a game by its game ID.
- Parameters:
gameId (UUID) – The game ID.
- Returns:
The strategy details.
- Return type:
- get_tasks_by_gameId(gameId: UUID)[source]¶
Retrieves the tasks associated with a game by its game ID.
- Parameters:
gameId (UUID) – The game ID.
- Returns:
The game details including tasks.
- Return type:
- patch_game_by_externalGameId(externalGameId: str, schema: PatchGame)[source]¶
Updates a game by its external game ID using the provided schema.
- Parameters:
externalGameId (str) – The external game ID.
schema (PatchGame) – The schema representing the updated data.
- Returns:
The updated game details.
- Return type:
ResponsePatchGame
app.services.strategy_service module¶
- class app.services.strategy_service.StrategyService[source]¶
Bases:
BaseService
Service class for managing strategies.
- None¶
- get_Class_by_id(id)[source]¶
Retrieves the class of a strategy by its ID.
- Parameters:
id (str) – The ID of the strategy.
- Returns:
The strategy class.
- Return type:
class
- Raises:
NotFoundError – If the strategy class is not found.
app.services.task_service module¶
- class app.services.task_service.TaskService(strategy_service: StrategyService, task_repository: TaskRepository, game_repository: GameRepository, user_repository: UserRepository, user_points_repository: UserPointsRepository, game_params_repository: GameParamsRepository, task_params_repository: TaskParamsRepository)[source]¶
Bases:
BaseService
Service class for managing tasks.
- strategy_service¶
Service instance for strategies.
- Type:
- task_repository¶
Repository instance for tasks.
- Type:
- game_repository¶
Repository instance for games.
- Type:
- user_repository¶
Repository instance for users.
- Type:
- user_points_repository¶
Repository instance for user points.
- Type:
- game_params_repository¶
Repository instance for game parameters.
- Type:
- task_params_repository¶
Repository instance for task parameters.
- Type:
- create_task_by_externalGameId(externalGameId, create_query)[source]¶
Creates a task for a game by its external game ID.
- Parameters:
externalGameId (str) – The external game ID.
create_query – The query for creating the task.
- Returns:
The created task details.
- Return type:
CreateTaskPostSuccesfullyCreated
- create_task_by_game_id(gameId, create_query, api_key: str | None = None)[source]¶
Creates a task for a game by its game ID.
- Parameters:
gameId (UUID) – The game ID.
create_query – The query for creating the task.
- Returns:
The created task details.
- Return type:
CreateTaskPostSuccesfullyCreated
- get_points_by_task_id_with_details(gameId, externalTaskId)[source]¶
Retrieves points by task ID with details.
- get_points_of_user_by_task_id(gameId, externalTaskId, externalUserId)[source]¶
Retrieves points of a user by task ID.
- get_task_by_externalGameId_externalTaskId(gameId, externalTaskId)[source]¶
Retrieves a task by its game ID and external task ID.
- Parameters:
gameId (UUID) – The game ID.
externalTaskId (str) – The external task ID.
- Returns:
The task details.
- Return type:
CreateTaskPostSuccesfullyCreated
- get_task_by_gameId_externalTaskId(gameId, externalTaskId)[source]¶
Retrieves a task by its game ID and external task ID.
- Parameters:
gameId (UUID) – The game ID.
externalTaskId (str) – The external task ID.
- Returns:
The task details.
- Return type:
CreateTaskPostSuccesfullyCreated
- get_task_detail_by_id(schema)[source]¶
Retrieves task details by its ID.
- Parameters:
schema – The schema containing the task ID.
- Returns:
The task and strategy details.
- Return type:
- get_task_params_by_externalTaskId(externalTaskId)[source]¶
Retrieves task parameters by external task ID.
app.services.user_points_service module¶
- class app.services.user_points_service.UserPointsService(user_points_repository: UserPointsRepository, users_repository: UserRepository, game_repository: GameRepository, task_repository: TaskRepository, wallet_repository: WalletRepository, wallet_transaction_repository: WalletTransactionRepository)[source]¶
Bases:
BaseService
- count_personal_records_by_external_game_id(external_game_id, externalUserId)[source]¶
Count the number of records for a user in a game.
- get_avg_time_between_tasks_by_user_and_game_task(externalGameId, externalTaskId, externalUserId)[source]¶
- get_global_avg_by_external_game_id(external_game_id)[source]¶
- Get the global average time rewarded. It does not take into account
the time with 0 value (minutes)
- get_personal_avg_by_external_game_id(external_game_id, externalUserId)[source]¶
- Get the personal average time rewarded. It does not take into account
the time with 0 value (minutes)
app.services.user_service module¶
- class app.services.user_service.UserService(user_repository: UserRepository, user_points_repository: UserPointsRepository, task_repository: TaskRepository, wallet_repository: WalletRepository, wallet_transaction_repository: WalletTransactionRepository)[source]¶
Bases:
BaseService
Service class for managing users.
- user_repository¶
Repository instance for users.
- Type:
- user_points_repository¶
Repository instance for user points.
- Type:
- task_repository¶
Repository instance for tasks.
- Type:
- wallet_repository¶
Repository instance for wallets.
- Type:
- wallet_transaction_repository¶
Repository instance for wallet transactions.
- assign_points_to_user(userId, schema: BaseUserPointsBaseModel)[source]¶
Assigns points to a user based on the provided schema.
- Parameters:
userId (str) – The user ID.
schema (BaseUserPointsBaseModel) – The schema containing point assignment details.
- Returns:
The assigned points details.
- Return type:
UserPointsAssigned
- basic_engagement_points()[source]¶
- Provides a fixed number of points as a basic engagement reward for a
user’s initial actions within the gamification system.
- Returns:
The fixed number of basic engagement points.
- Return type:
- convert_points_to_coins(userId, schema: PostPointsConversionRequest, api_key)[source]¶
Converts points to coins for a user based on the provided schema.
- Parameters:
userId (str) – The user ID.
schema (PostPointsConversionRequest) – The schema containing conversion details. api_key (str): The API key.
- Returns:
The conversion details.
- Return type:
ResponsePointsConversion
- convert_points_to_coins_externalUserId(externalUserId, schema: PostPointsConversionRequest, api_key: str | None = None)[source]¶
- Converts points to coins for a user by their external user ID based on
the provided schema.
- create_user(schema)[source]¶
Creates a new user using the provided schema.
- Parameters:
schema – The schema representing the user to be created.
- Returns:
The created user.
- Return type:
- get_points_by_user_id(userId)[source]¶
Retrieves points associated with a user by their user ID.
- Parameters:
userId (str) – The user ID.
- Returns:
The user’s points and associated tasks.
- Return type:
UserPointsTasks
- get_wallet_by_externalUserId(externalUserId)[source]¶
Retrieves the wallet associated with a user by their external user ID.
- Parameters:
externalUserId (str) – The external user ID.
- Returns:
The wallet details.
- Return type:
UserWallet
- get_wallet_by_user_id(userId)[source]¶
Retrieves the wallet associated with a user by their user ID.
- Parameters:
userId (str) – The user ID.
- Returns:
The wallet details.
- Return type:
UserWallet
- global_advantage_adjustment_points()[source]¶
- Awards additional points to users whose performance is above the
- global average but have shown a decrease in their individual
- performance. It’s designed to encourage users to strive for
- above-average performance, recognizing their effort amidst
challenges.
- Returns:
- The number of adjustment points for maintaining a global
advantage.
- Return type:
- individual_adjustment_points()[source]¶
- Rewards users who have improved their individual performance,
- regardless of their standing against the global average. It aims to
- acknowledge and encourage personal improvement, motivating users
to keep advancing.
- Returns:
- The number of points to award for individual performance
improvement.
- Return type:
- individual_over_global_points()[source]¶
- Awards additional points for users who have improved their individual
- performance compared to their own history, even if below the global
average.
- Returns:
The number of additional points to award.
- Return type:
- need_for_motivation_points()[source]¶
- Provides a small point incentive for users who are underperforming
both individually and globally, to motivate improvement.
- Returns:
The number of points to award as motivation.
- Return type:
- peak_performer_bonus_points()[source]¶
- Rewards users who have exceeded both their individual performance and
the global average, standing out as peak performers in the system.
- Returns:
The number of bonus points for peak performers.
- Return type:
- performance_bonus_points()[source]¶
- Calculates the number of additional points to award for performance
above a certain threshold.
- Returns:
The number of bonus points to award.
- Return type:
- performance_penalty_points()[source]¶
- Calculates the number of points to deduct as a penalty for performance
below a certain threshold.
- Returns:
The number of points to deduct.
- Return type:
- preview_points_to_coins_conversion(userId, points)[source]¶
Previews the conversion of points to coins for a user.
app.services.wallet_service module¶
- class app.services.wallet_service.WalletService(wallet_repository: WalletRepository, user_repository: UserRepository)[source]¶
Bases:
BaseService
Service class for managing wallets.
- wallet_repository¶
Repository instance for wallets.
- Type:
- user_repository¶
Repository instance for users.
- Type:
app.services.wallet_transaction_service module¶
- class app.services.wallet_transaction_service.WalletTransactionService(wallet_transaction_repository: WalletTransactionRepository)[source]¶
Bases:
BaseService
Service class for wallet transactions.
- wallet_transaction_repository¶
Repository instance for wallet transactions.