from enum import Enum from otree.api import cu, Currency class RewardGroup(Enum): HIGH = [cu(0.15), cu(0.15), cu(0.30)] LOW = [cu(0.05), cu(0.05), cu(0.10)] def get_reward(self, points: int, round_nr: int) -> Currency: if len(self.value) < round_nr: raise RuntimeError(f"Cannot get_reward for round_nr {round_nr}. Only {len(self.value)} rewards exist.") reward = self.value[round_nr - 1] return points * reward def get_opposite(self): if self == RewardGroup.HIGH: return RewardGroup.LOW else: return RewardGroup.HIGH def __str__(self): return self.name.capitalize() @staticmethod def get_high_reward(round_nr: int) -> Currency: if len(RewardGroup.HIGH.value) < round_nr: raise RuntimeError( f"Cannot get_high_reward for round_nr {round_nr}. Only {len(RewardGroup.HIGH.value)} rewards exist." ) return RewardGroup.HIGH.value[round_nr - 1] @staticmethod def get_low_reward(round_nr: int) -> Currency: if len(RewardGroup.LOW.value) < round_nr: raise RuntimeError( f"Cannot get_low_reward for round_nr {round_nr}. Only {len(RewardGroup.LOW.value)} rewards exist." ) return RewardGroup.LOW.value[round_nr - 1]