app.engine.greencrowdStrategy module

# noqa https://dreampuf.github.io/GraphvizOnline/?engine=dot#digraph%20G%7B%0A%20%20%20%20rankdir%3DTB%3B%0A%20%20%20%20node%20%5Bshape%3Dbox%2C%20style%3Dfilled%2C%20fillcolor%3Dlightgray%5D%3B%0A%20%20%20%20edge%20%5Bfontsize%3D10%5D%3B%0A%20%20%20%20%0A%20%20%20%20leyend%5Blabel%3D%22BP%3A%20Base%20Points%20%5Cn%20DIM_BP%3A%20Base%20Points%20Reward%20%5Cn%20DIM_LBE%3A%20Location-Based%20Equity%20%5Cn%20DIM_TD%3A%20Time%20Diversity%20%5Cn%20DIM_PP%3A%20Personal%20Performance%20%5Cn%20DIM_S%3A%20Streak%20Bonus%22%2C%20fillcolor%3Dyellowgreen%5D%0A%20%20%20%20%0A%20%20%20%20start%20%5Blabel%3D%22Start%22%2C%20shape%3Dellipse%2C%20fillcolor%3Dlightgray%5D%3B%0A%20%20%20%20taskCompleted%20%5Blabel%3D%22Task%20Completed%3F%22%2C%20shape%3Ddiamond%2C%20fillcolor%3Dlightblue%5D%3B%0A%20%20%20%20assignBP%20%5Blabel%3D%22Assign%20BP%20(DIM_BP)%22%2C%20shape%3Dparallelogram%2C%20fillcolor%3Dlightyellow%5D%3B%0A%20%20%20%20%0A%20%20%20%20checkLBE%20%5Blabel%3D%22Evaluate%20DIM_LBE%5Cn(Geolocation%20Equity)%22%2C%20shape%3Ddiamond%2C%20fillcolor%3Dlightblue%5D%3B%0A%20%20%20%20assignLBE%20%5Blabel%3D%22Assign%20BP%20*%200.5%20(if%20POI%20%3C%20Avg)%22%2C%20shape%3Dparallelogram%2C%20fillcolor%3Dlightyellow%5D%3B%0A%20%20%20%20%0A%20%20%20%20checkTD%20%5Blabel%3D%22Evaluate%20DIM_TD%5Cn(Time%20Diversity)%22%2C%20shape%3Ddiamond%2C%20fillcolor%3Dlightblue%5D%3B%0A%20%20%20%20assignTD%20%5Blabel%3D%22Assign%20BP%20*%20Coe_time%22%2C%20shape%3Dparallelogram%2C%20fillcolor%3Dlightyellow%5D%3B%0A%20%20%20%20%0A%20%20%20%20checkPP%20%5Blabel%3D%22Evaluate%20DIM_PP%5Cn(Personal%20Performance)%22%2C%20shape%3Ddiamond%2C%20fillcolor%3Dlightblue%5D%3B%0A%20%20%20%20assignPP%20%5Blabel%3D%22Assign%20BP%20*%20(AVG_Time_Window%20-%20Last_Time_Window)%20%2F%20AVG_Time_Window%22%2C%20shape%3Dparallelogram%2C%20fillcolor%3Dlightyellow%5D%3B%0A%20%20%20%20%0A%20%20%20%20checkStreak%20%5Blabel%3D%22Evaluate%20DIM_S%5Cn(Consistency)%22%2C%20shape%3Ddiamond%2C%20fillcolor%3Dlightblue%5D%3B%0A%20%20%20%20assignStreak%20%5Blabel%3D%22Assign%20BP%20*%20(2%5EDays_Consecutive%20%2F%207)%22%2C%20shape%3Dparallelogram%2C%20fillcolor%3Dlightyellow%5D%3B%0A%20%20%20%20%0A%20%20%20%20totalPoints%20%5Blabel%3D%22Total%20Reward%20Calculation%22%2C%20shape%3Dparallelogram%2C%20fillcolor%3Dlightyellow%5D%3B%0A%20%20%20%20%0A%20%20%20%20start%20-%3E%20taskCompleted%3B%0A%20%20%20%20taskCompleted%20-%3E%20assignBP%20%5Blabel%3D%22Yes%22%5D%3B%0A%20%20%20%20taskCompleted%20-%3E%20totalPoints%20%5Blabel%3D%22No%22%2C%20style%3Ddashed%5D%3B%0A%20%20%20%20%0A%20%20%20%20assignBP%20-%3E%20checkLBE%3B%0A%20%20%20%20checkLBE%20-%3E%20assignLBE%20%5Blabel%3D%22POI%20%3C%20Avg%22%5D%3B%0A%20%20%20%20checkLBE%20-%3E%20checkTD%20%5Blabel%3D%22POI%20%3E%3D%20Avg%22%5D%3B%0A%20%20%20%20assignLBE%20-%3E%20checkTD%3B%0A%20%20%20%20%0A%20%20%20%20checkTD%20-%3E%20assignTD%20%5Blabel%3D%22Valid%20Time%20Slot%22%5D%3B%0A%20%20%20%20checkTD%20-%3E%20checkPP%20%5Blabel%3D%22Invalid%20Time%20Slot%22%5D%3B%0A%20%20%20%20assignTD%20-%3E%20checkPP%3B%0A%20%20%20%20%0A%20%20%20%20checkPP%20-%3E%20assignPP%20%5Blabel%3D%22Improved%20Response%20Time%22%5D%3B%0A%20%20%20%20checkPP%20-%3E%20checkStreak%20%5Blabel%3D%22No%20Improvement%22%5D%3B%0A%20%20%20%20assignPP%20-%3E%20checkStreak%3B%0A%20%20%20%20%0A%20%20%20%20checkStreak%20-%3E%20assignStreak%20%5Blabel%3D%22Maintained%20Streak%22%5D%3B%0A%20%20%20%20checkStreak%20-%3E%20totalPoints%20%5Blabel%3D%22No%20Streak%22%5D%3B%0A%20%20%20%20assignStreak%20-%3E%20totalPoints%3B%0A%7D

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.

generate_hash(response_data)[source]

Generate a hash for the response to ensure integrity.

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_simulate payload 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)

checkISExpired(expiration_date)[source]

Check if the expiration date has passed.

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 data payload is structured as:

{
    "experimentGroup": str,
    "simulationHash": str,
    "dimensions": [
        {"DIM_BP": int, "DIM_LBE": int, "DIM_TD": int,
         "DIM_PP": int, "DIM_S": int},
        ...
    ]
}