Skip to content

Commit

Permalink
WIP Engine
Browse files Browse the repository at this point in the history
  • Loading branch information
fvergaracl committed Mar 6, 2024
1 parent f9b921b commit 7b7fb92
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 24 deletions.
40 changes: 16 additions & 24 deletions app/engine/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,23 @@
#### Comparative Performance Scenarios
| Case/Subcase | Conditions | Points Awarded | Tag | Required Variables | Condition Check |
| ------------ | -------------------------------------------------------- | ---------------------------------------------------------------------------------- | -------------------- | ----------------------------------------------------------------------------- | --------------------------------------------- |
| Case 2.1 | Second measurement with time taken > global calculation. | Fixed points or bonus/penalty based on the difference from the global calculation. | `PerformancePenalty` | `defaut_points_task_campaign`, `tiempo_tardado_ultima_task`, `Calculo_global` | `tiempo_tardado_ultima_task > Calculo_global` |
| Case 2.2 | Second measurement with time taken < global calculation. | Base points + bonus. | `PerformanceBonus` | `defaut_points_task_campaign`, `tiempo_tardado_ultima_task`, `Calculo_global` | `tiempo_tardado_ultima_task < Calculo_global` |
| Case/Subcase | Conditions | Points Awarded | Tag | Required Variables | Condition Check |
| ------------ | -------------------------------------------------------- | ----------------------- | ------------------ | ----------------------------------------------------------------------------- | --------------------------------------------- |
| Case 2 | Second measurement with time taken < global calculation. | Base points + bonus. | `PerformanceBonus` | `defaut_points_task_campaign`, `tiempo_tardado_ultima_task`, `Calculo_global` | `tiempo_tardado_ultima_task < Calculo_global` |
#### Individual Improvement Scenario
| Case/Subcase | Conditions | Points Awarded | Tag | Required Variables | Condition Check |
| ------------ | ----------------------------------------------------------- | --------------------- | ---------------------- | --------------------------------------------------------------------------------- | -------------------------------------------------- |
| Case 3 | Comparison with individual calculation (greater or lesser). | Base + bonus/penalty. | `IndividualAdjustment` | `defaut_points_task_campaign`, `tiempo_tardado_ultima_task`, `calculo_individual` | `tiempo_tardado_ultima_task <> calculo_individual` |
| Case 3 | Comparison with individual calculation (greater or lesser). | Base + bonus. | `IndividualAdjustment` | `defaut_points_task_campaign`, `tiempo_tardado_ultima_task`, `calculo_individual` | `tiempo_tardado_ultima_task <> calculo_individual` |
#### Advanced Gamification Strategies
| Case/Subcase | Conditions | Points Awarded | Tag | Required Variables | Condition Check |
| ------------ | ---------------------------------------------------- | --------------------------------------------------------------------------------------- | --------------------------- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| Case/Subcase | Conditions | Points Awarded | Tag | Required Variables | Condition Check |
| ------------ | ---------------------------------------------------- | --------------------------------------------------------------------------------- | --------------------------- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| Case 4.1 | Individual improvement but below the global average. | Adjusted points based on individual improvement without penalty for global performance. | `IndividualOverGlobal` | `defaut_points_task_campaign`, `tiempo_tardado_ultima_task`, `calculo_individual`, `Calculo_global` | `tiempo_tardado_ultima_task < calculo_individual && tiempo_tardado_ultima_task > Calculo_global` |
| Case 4.2 | Individual worsening and below the global average. | Default points. | `NeedForMotivation` | `defaut_points_task_campaign`, `tiempo_tardado_ultima_task`, `calculo_individual`, `Calculo_global` | `tiempo_tardado_ultima_task > calculo_individual && tiempo_tardado_ultima_task > Calculo_global` |
| Case 4.3 | Individual improvement and above the global average. | Significantly increased points. | `PeakPerformerBonus` | `defaut_points_task_campaign`, `tiempo_tardado_ultima_task`, `calculo_individual`, `Calculo_global` | `tiempo_tardado_ultima_task < calculo_individual && tiempo_tardado_ultima_task < Calculo_global` |
| Case 4.4 | Individual worsening, but above the global average. | Adjusted points based on global performance. | `GlobalAdvantageAdjustment` | `defaut_points_task_campaign`, `tiempo_tardado_ultima_task`, `calculo_individual`, `Calculo_global` | `tiempo_tardado_ultima_task > calculo_individual && tiempo_tardado_ultima_task < Calculo_global` |
| Case 4.2 | Individual improvement and above the global average. | Significantly increased points. | `PeakPerformerBonus` | `defaut_points_task_campaign`, `tiempo_tardado_ultima_task`, `calculo_individual`, `Calculo_global` | `tiempo_tardado_ultima_task < calculo_individual && tiempo_tardado_ultima_task < Calculo_global` |
| Case 4.3 | Individual worsening, but above the global average. | Adjusted points based on global performance. | `GlobalAdvantageAdjustment` | `defaut_points_task_campaign`, `tiempo_tardado_ultima_task`, `calculo_individual`, `Calculo_global` | `tiempo_tardado_ultima_task > calculo_individual && tiempo_tardado_ultima_task < Calculo_global` |
Gamification System Decision Tree
.
Expand All @@ -37,23 +35,19 @@
│ └── No
│ └── Is this the user's second measurement?
│ ├── Yes
│ │ └── Is the time taken for the last task greater than the global calculation?
│ │ ├── Yes
│ │ │ └── Use Case 2.1: `PerformancePenalty`
│ │ └── No
│ │ └── Use Case 2.2: `PerformanceBonus`
│ │ └── Is the time taken for the last task less than the global calculation?
│ │ └── Yes
│ │ └── Use Case 2: `PerformanceBonus`
│ └── No (It's a subsequent measurement)
│ └── Is the time taken for the last task greater or less than the individual calculation?
│ ├── Greater or equal
│ │ └── Evaluate against both, individual and global calculations
│ │ ├── If time is less than the individual calculation AND greater than the global calculation
│ │ │ └── Use Case 4.1: `IndividualOverGlobal`
│ │ ├── If time is greater than both, individual and global calculations
│ │ │ └── Use Case 4.2: `NeedForMotivation`
│ │ ├── If time is less than both, individual and global calculations
│ │ │ └── Use Case 4.3: `PeakPerformerBonus`
│ │ │ └── Use Case 4.2: `PeakPerformerBonus`
│ │ └── If time is greater than the individual calculation but less than the global calculation
│ │ └── Use Case 4.4: `GlobalAdvantageAdjustment`
│ │ └── Use Case 4.3: `GlobalAdvantageAdjustment`
│ └── Less
│ └── Use Case 3: `IndividualAdjustment`
Expand All @@ -62,15 +56,13 @@
| Function Name | Description | Points Awarded |
| ------------------------------------ | ----------------------------------------------------------------------------------------------- | -------------- |
| `basic_engagement_points` | Fixed number of points for a user's initial actions within the gamification system. | 1 |
| `performance_penalty_points` | Points deducted as a penalty for performance below a certain threshold. | -5 |
| `performance_bonus_points` | Additional points awarded for performance above a certain threshold. | 10 |
| `performance
_bonus_points` | Additional points awarded for performance above a certain threshold. | 10 |
| `individual_over_global_points` | Additional points for users who have improved their performance compared to their own history. | 5 |
| `need_for_motivation_points` | Small point incentive for users underperforming both individually and globally. | 2 |
| `peak_performer_bonus_points` | Bonus points for users exceeding both their individual performance and the global average. | 15 |
| `global_advantage_adjustment_points` | Additional points for users above the global average but with decreased individual performance. | 7 |
| `individual_adjustment_points` | Points awarded for users who have improved their individual performance. | 8 |
"""

from app.engine.base_strategy import BaseStrategy
Expand Down
Empty file.
21 changes: 21 additions & 0 deletions app/engine/functions/get_user_measurements_count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from app.repository.user_points_repository import UserPointsRepository


def get_user_measurements_count(
user_id: int,
user_points_repository: UserPointsRepository) -> int:
"""
Get the number of measurements a user has completed in a campaign.
Args:
user_id (int): The user's unique identifier.
user_points_repository (UserPointsRepository): The repository to access user points data.
Returns:
int: The number of measurements completed by the user.
"""
# Asumiendo que UserPointsRepository tiene un método para contar mediciones por user_id
measurements_count = user_points_repository.count_measurements_by_user_id(
user_id)

return measurements_count
49 changes: 49 additions & 0 deletions app/repository/engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from app.repository.base_repository import BaseRepository
from contextlib import AbstractContextManager
from typing import Callable

from sqlalchemy.orm import Session

from app.repository.game_params_repository import GameParamsRepository
from app.repository.game_repository import GameRepository
from app.repository.strategy_repository import StrategyRepository
from app.repository.task_repository import TaskRepository
from app.repository.user_points_repository import UserPointsRepository
from app.repository.user_repository import UserRepository
from app.repository.wallet_repository import WalletRepository
from app.repository.wallet_transaction_repository import WalletTransactionRepository


class EngineRepository(BaseRepository):

def __init__(
self,
session_factory: Callable[..., AbstractContextManager[Session]],
model_game_params_repository=GameParamsRepository,
model_game_repository=GameRepository,
model_strategy_repository=StrategyRepository,
model_task_repository=TaskRepository,
model_user_points_repository=UserPointsRepository,
model_user_repository=UserRepository,
model_wallet_repository=WalletRepository,
model_wallet_transaction_repository=WalletTransactionRepository
) -> None:
self.model_game_params_repository = model_game_params_repository
self.model_game_repository = model_game_repository
self.model_strategy_repository = model_strategy_repository
self.model_task_repository = model_task_repository
self.model_user_points_repository = model_user_points_repository
self.model_user_repository = model_user_repository
self.model_wallet_repository = model_wallet_repository
self.model_wallet_transaction_repository = model_wallet_transaction_repository
super().__init__(
session_factory,
model_game_params_repository,
model_game_repository,
model_strategy_repository,
model_task_repository,
model_user_points_repository,
model_user_repository,
model_wallet_repository,
model_wallet_transaction_repository
)

0 comments on commit 7b7fb92

Please sign in to comment.