class Order(ExtraModel): player = models.Link(Player) group = models.Link(Group) orderID = models.IntegerField() direction = models.StringField() # 'buy', 'sell' q_max = models.FloatField() u_max = models.FloatField() p_min = models.FloatField() p_max = models.FloatField() status = models.StringField()
class GameSession(ExtraModel): """Persistent game state linked to each player. Holds name of ordered sandwich and its price. Implements core game logic independant from other models. """ # TODO: this is a temporary data and should be deleted afterwards player = models.Link('Player') ordered = models.StringField() price = models.CurrencyField() def next_order(self, price): """Generates and saves next random order""" self.ordered = random.choice(list(RECIPES.keys())) self.price = price def validate(self, sandwich): """Validates if submitted sandwich matches ordered Returns: valid, reward, errors """ expected = RECIPES[self.ordered] mismatches = len(set(sandwich) ^ set(expected)) if mismatches == 0: return True, self.price, 0 else: return False, 0, mismatches
class MouseEvent(ExtraModel): #player = models.Link(MouseTrackingPlayer) #player = ForeignKey('mousetracking.Player') player = models.Link('mousetracking.Player') stimulus = models.StringField() region = models.IntegerField() action = models.StringField() timestamp = BigIntegerField()
class DataExport(models.ExtraModel): player = models.Link(Player) mail = models.StringField() participant_code = models.StringField() payoff = models.FloatField() ptoday = models.FloatField() tel = models.StringField() mail2 = models.StringField() idp = models.StringField()
class GameSession(ExtraModel): """Persistent game state linked to session""" session = models.Link('Subsession') board = models.StringField() turn = models.StringField() winner = models.StringField() def __repr__(self): return f"<GameSession {repr(self.game)}>" def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.game = Game(self.board, self.turn) def save(self, *args, **kwargs): self.board = self.game.board self.turn = self.game.turn super().save(*args, **kwargs)
class ContractValue(ExtraModel): value = models.IntegerField() player = models.Link(Player) round = models.IntegerField()
class DataExport(models.ExtraModel): kept = models.CurrencyField() group = models.Link(Group)
class HoverEvent(models.ExtraModel): player = models.Link(Player) element_id = models.StringField() enter_time = models.FloatField() leave_time = models.FloatField()