#1 by ecopsy2023
Hi there, I wanted to calculate the points/payoff associated with participants' responses to consumption levels. However, when player.consumption is less than 21, the data returned says 0. Then between 21 and 50 I get the same result of around 158. Finally, when player.consumption is greater than 50 it gives me the proper result. @staticmethod def before_next_page(player, timeout_happened): player.consumption_points = 250 * (1 - math.exp( -0.02 * player.consumption ) ) I have tried the python code in online coding environment and it worked as expected. However, in oTree I cant seem to get it to work. Any advice or instruction would be much appreciated! Thank you again
#2 by Fanist
@ecopsy2023 Hi, I have tried your code and it works well for me in local env. Have you "import math"?
#3 by ecopsy2023
Hi there, I have "import math" at the top of my __init__.py file. I also receive no errors when saving in VScode which leads me to believe the code works. However, for some reason in the oTree Demo Data section it shows that the player.consumption_points values follow this weird nature (as described in above in the original post) seems bizarre. Yet I am thankful to hear it works for you.
#4 by Daniel_Frey
How is player.consumption_points defined? Is it an integer-field? Maybe that's the problem.
#5 by ecopsy2023
Hi there, Currently, player.consumption_points is defined as a float-field
#6 by ecopsy2023
SOLUTION: @Daniel_Frey's comment along with the aid of Bing Chat, helped me to diagnose that the problem arises when player.consumption is defined as CurrencyField(). Upon changing it to a float-field, the code now works. Thank you all again!