app.engine.greencrowdStrategy module¶
- app.engine.greencrowdStrategy.get_random_values_from_tasks(all_records)[source]¶
Extracts all dimensions from the tasks and generates random values within the range of the minimum and maximum values found in the tasks.
- Parameters:
all_records (list) – A list of all tasks.
- Returns:
dict – A dictionary containing random values for each dimension.
- app.engine.greencrowdStrategy.get_average_values_from_tasks(task, all_records)[source]¶
Compute the average integer value of each dimension across tasks.
- Parameters:
task – The current task (unused placeholder kept for signature compatibility).
all_records (list) – All task records to average over.
- Returns:
dict – Average integer value for each dimension.
- app.engine.greencrowdStrategy.get_dynamic_values_from_tasks(task, list_ids_tasks, all_records, user, variable_basic_points, variable_lbe_multiplier)[source]¶
Calculates dynamic values based on user participation in tasks.
- Parameters:
task (object) – The task object.
list_ids_tasks (list) – A list of task IDs with externalTaskId references.
all_records (list) – A list of all task participation records.
user (object) – The user object participating in tasks.
variable_basic_points (int) – The base points per participation.
variable_lbe_multiplier (float) – The location-based equity multiplier.
- Returns:
dict –
- A dictionary containing calculated values for each dimension:
”DIM_BP”: Base points adjusted for task uniqueness.
”DIM_LBE”: Points adjusted for location-based equity.
”DIM_TD”: Points based on temporal distribution of participation.
”DIM_PP”: Points adjusted for participation periodicity.
”DIM_S”: Streak-based points for continuous participation.
- app.engine.greencrowdStrategy.assign_random_scores(min_value, max_value)[source]¶
Generate random scores for each GREENCROWD scoring dimension.
Used to seed simulations/tests with plausible per-dimension values.
- Parameters:
min_value (int) – Inclusive lower bound for each random score.
max_value (int) – Inclusive upper bound for each random score.
- Returns:
dict – Random integer scores keyed by dimension (
DIM_BP,DIM_TD,DIM_LBE,DIM_PP,DIM_S).
- class app.engine.greencrowdStrategy.GREENCROWDGamificationStrategy[source]¶
Bases:
BaseStrategy- generate_logic_graph(format='png')[source]¶
Render the GREENCROWD scoring logic as a Graphviz diagram.
Produces a labelled flowchart of the five scoring dimensions (base points, location-based equity, time diversity, personal performance and streak bonus) for display in the dashboard.
- Parameters:
format (str) – Graphviz output format (e.g.
"png","svg").- Returns:
graphviz.Digraph – The constructed diagram.
- simulate_strategy(data_to_simulate=None, userGroup='dynamic', user_last_task=None)[source]¶
Estimate the points a user would receive, without assigning them.
Five dimensions contribute to the score:
Task Diversity Base Points (
DIM_BP)Location-Based Equity (
DIM_LBE)Time Diversity (
DIM_TD)Personal Performance (
DIM_PP)Streak Bonus (
DIM_S)
- Parameters:
data_to_simulate (dict, optional) – Data for the simulation, with the structure shown below.
userGroup (str) – The user group to simulate for; one of
random_range,average_score,dynamic_calculation.user_last_task (dict, optional) – The user’s last task.
The
data_to_simulatepayload is structured as:{ "task": dict, # single task object "allTasks": list, # all tasks "externalUserId": str, # the user the simulation is run for }
- Returns:
list –
One result dict per task, each structured as:
{ "externalUserId": str, "dimensions": list, # points per dimension "totalSimulatedPoints": int, # total estimated points }
- Parameters:
data_to_simulate (dict)
userGroup (str)
user_last_task (dict)
- async calculate_points(externalGameId, externalTaskId, externalUserId, data)[source]¶
Calculate the points for the GREENCROWD gamification strategy.
- Parameters:
externalGameId (str) – The external game id.
externalTaskId (str) – The external task id.
externalUserId (str) – The external user id.
data (dict) – The dimensions used for the calculation, with the shape shown below.
The
datapayload is structured as:{ "experimentGroup": str, "simulationHash": str, "dimensions": [ {"DIM_BP": int, "DIM_LBE": int, "DIM_TD": int, "DIM_PP": int, "DIM_S": int}, ... ] }