from otree.api import * c = cu from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random import csv import json import itertools # from otree.models_concrete import ParticipantToPlayerLookup, RoomToSession # from otree.models.session import Session as BaseSession author = 'Erica Ordali' doc = """ Parkinson Experiment: Lottery App - Istruzioni """ def seq_to_dict(s): r = {} l = len(s) - 1 for i, j in enumerate(s): if i < l: r[j] = s[i + 1] else: r[j] = None return r class Constants(BaseConstants): name_in_url = 'p_instructions' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): def creating_session(self): app_seq = self.session.config.get('app_sequence') for p in self.get_players(): first_app, second_app, third_app, last_app = app_seq new_app_seq = [first_app] + [second_app] + [third_app] + [last_app] p.sequence_of_apps = json.dumps(new_app_seq) p.participant.vars['_updated_seq_apps'] = seq_to_dict(new_app_seq) blocks = itertools.cycle([1, 2, 3]) if self.round_number == 1: for p in self.get_players(): p.participant.vars['block_to_pay'] = next(blocks) block_to_pay = next(blocks) p.participant.vars['block_to_pay'] = block_to_pay p.block_to_pay = block_to_pay decisions = itertools.cycle(range(1, 40)) if self.round_number == 1: for p in self.get_players(): p.participant.vars['decision_to_pay'] = next(decisions) decision_to_pay = next(decisions) p.participant.vars['decision_to_pay'] = decision_to_pay p.decision_to_pay = decision_to_pay class Group(BaseGroup): pass class Player(BasePlayer): sequence_of_apps = models.LongStringField() block_to_pay = models.IntegerField() decision_to_pay = models.IntegerField()