Skip to content

Commit

Permalink
legacy economic model tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeandemeusy committed Jun 7, 2024
1 parent 9b81159 commit 5db96d0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 149 deletions.
11 changes: 6 additions & 5 deletions ct-app/core/model/economic_model_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ def __init__(
self.budget: Budget = None

def transformed_stake(self, stake: float):
func = self.equations.f_x

# convert parameters attribute to dictionary
kwargs = vars(self.coefficients)
kwargs.update({"x": stake})

if not eval(func.condition, kwargs):
func = self.equations.g_x
for func in vars(self.equations).values():
if eval(func.condition, kwargs):
break
else:
return 0

return eval(func.formula, kwargs)

Expand All @@ -80,7 +81,7 @@ def message_count_for_reward(self, stake: float):
denominator = self.budget.ticket_price * self.budget.winning_probability

if denominator != 0:
return round(rewards / denominator * self.economic_model.proportion)
return round(rewards / denominator * self.proportion)
else:
return 0

Expand Down
1 change: 0 additions & 1 deletion ct-app/scripts/core_prod_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ economicModel:
budget:
amount: 190000
period: 2628000 # in seconds
s: 1
countsInPeriod: 1460
winningProbability: 1

Expand Down
139 changes: 0 additions & 139 deletions ct-app/scripts/core_production_config.yaml

This file was deleted.

47 changes: 43 additions & 4 deletions ct-app/test/model/test_economic_model_legacy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,47 @@
import pytest
from core.components.parameters import Parameters
from core.model.budget import Budget
from core.model.economic_model_legacy import EconomicModelLegacy
from core.model.economic_model_legacy import (
Coefficients,
EconomicModelLegacy,
Equation,
Equations,
)


def test_init_class():
pass
@pytest.fixture
def model():
model = EconomicModelLegacy(
Equations(
Equation("a * x", "l <= x <= c"),
Equation("a * c + (x - c) ** (1 / b)", "x > c"),
),
Coefficients(1, 2, 3, 1),
1,
20.0,
)
model.budget = Budget(1200, 1, 1)
model.budget.ticket_price = 0.1

return model


def test_transformed_stake(model: EconomicModelLegacy):
assert model.transformed_stake(0) == 0
assert model.transformed_stake(model.coefficients.l) == model.coefficients.l
assert model.transformed_stake(model.coefficients.c) == model.coefficients.c
assert model.transformed_stake(model.coefficients.c * 2) < (
model.coefficients.c * 2
)


def test_message_count_for_reward(model: EconomicModelLegacy):
assert model.message_count_for_reward(0) == 0, "No reward for 0 stake"
assert model.message_count_for_reward(model.coefficients.l) == round(
model.coefficients.l * model.apr / model.budget.ticket_price / 12
), "Linear result if stake is minimum"
assert model.message_count_for_reward(model.coefficients.c) == round(
model.coefficients.c * model.apr / model.budget.ticket_price / 12
), "Linear result if stake is at threshold"
assert model.message_count_for_reward(model.coefficients.c * 2) < round(
(model.coefficients.c + 2) * model.apr / model.budget.ticket_price / 12
), "Non-linear result if stake is above threshold"

0 comments on commit 5db96d0

Please sign in to comment.