from otree.api import Currency as c, currency_range from . import models from ._builtin import Page, WaitPage from .models import Constants class Instructions(Page): def is_displayed(self): return self.round_number == 1 # Mostra la pagina solo al primo round class Demographics(Page): form_model = 'player' form_fields = ['subject_id', 'german'] def is_displayed(self): return self.round_number == 1 # Mostra la pagina solo al primo round class CognitiveReflectionTest(Page): form_model = 'player' form_fields = ['subject_study', 'degree', 'work', 'part_time_work', 'crt_bat', 'crt_widget', 'crt_lake', 'crt_gamble_four', 'crt_repetitions', 'crt_gamble_two', 'crt_gamble_three', 'crt_gamble_five', 'crt_gamble_six', 'crt_gamble_seven', 'age', 'gender', 'nationality'] def is_displayed(self): return self.round_number == 1 # Mostra la pagina solo al primo round class WorkPage(Page): timer_text = 'Time left to complete this round:' timeout_seconds = Constants.task_time def is_displayed(self): return self.player.is_placement_round() or self.player.is_first_session() or self.player.is_second_session() def vars_for_template(self): if self.round_number-1 in range(1+Constants.FIRST_SESSION_ROUNDS): round = self.round_number - 1 else: round = self.round_number - 1 - Constants.FIRST_SESSION_ROUNDS cumulative_payoff = sum([p.payoff for p in self.player.in_all_rounds()]) return { #'image_path': 'real_effort/paragraphs/{}.png'.format(self.round_number), # L'immagine si trova in _static/real_effort/... 'round': round, 'placement': self.player.is_placement_round(), 'placement_score': self.player.in_all_rounds()[0].placement_score, 'cumulative_payoff': cumulative_payoff } def before_next_page(self): # Non so cosa sia... #self.player.round_number #self.player.num_tasks_total #self.player.num_tasks_correct if self.player.is_placement_round(): self.player.evaluate_placement_score() elif self.player.is_first_session() or self.player.is_second_session(): self.player.payoff = self.player.get_tasks_score class IntermediateResults(Page): def is_displayed(self): return self.round_number == 2+Constants.FIRST_SESSION_ROUNDS def vars_for_template(self): player = self.player counting_task_rounds = [] # Exclude the first round (placement) and last round (the current one, didn't played yet) for round in player.in_all_rounds()[1:-1]: #num_counting_attempts.append(round.num_tasks_total) #num_counting_correct.append(round.num_tasks_correct) counting_task_rounds.append({'num_counting_attempts': round.num_tasks_total, 'num_counting_correct': round.num_tasks_correct}) pay = player.in_all_rounds()[0].placement_score for round in player.in_all_rounds()[1:]: pay += round.get_tasks_score return { 'counting_task_rounds': counting_task_rounds, 'placement_score': self.player.in_all_rounds()[0].placement_score, 'cumulative_payoff': pay } class Results(Page): def is_displayed(self): return self.round_number == Constants.num_rounds # Mostra la pagina dei risultati solo all'ultio round def vars_for_template(self): player = self.player num_counting_attempts = [] num_counting_correct = [] counting_task_rounds = [] for round in self.player.in_all_rounds()[1:]: #Exclude the placement round counting_task_rounds.append({'num_counting_attempts': round.num_tasks_total, 'num_counting_correct': round.num_tasks_correct, 'task_score': round.get_tasks_score}) pay = player.in_all_rounds()[0].placement_score for round in player.in_all_rounds()[1:]: pay += round.get_tasks_score return {'age': self.player.in_all_rounds()[0].age, 'subject_id': self.player.in_all_rounds()[0].subject_id, # player.subject_id, 'degree': self.player.in_all_rounds()[0].degree, 'subject_study': self.player.in_all_rounds()[0].subject_study, 'nationality': self.player.in_all_rounds()[0].nationality, 'german': self.player.in_all_rounds()[0].german, 'crt_bat_answer': self.player.in_all_rounds()[0].crt_bat, 'crt_widget_answer': self.player.in_all_rounds()[0].crt_widget, 'crt_lake_answer': self.player.in_all_rounds()[0].crt_lake, 'crt_gamble_four_answer': self.player.in_all_rounds()[0].crt_gamble_four, 'crt_repetitions_answer': self.player.in_all_rounds()[0].crt_repetitions, 'crt_gamble_two_answer': self.player.in_all_rounds()[0].crt_gamble_two, 'crt_gamble_three_answer': self.player.in_all_rounds()[0].crt_gamble_three, 'crt_gamble_five_answer': self.player.in_all_rounds()[0].crt_gamble_five, 'crt_gamble_six_answer': self.player.in_all_rounds()[0].crt_gamble_six, 'crt_gamble_seven_answer': self.player.in_all_rounds()[0].crt_gamble_seven, 'num_counting_attempts': num_counting_attempts, 'num_counting_correct': num_counting_correct, 'counting_task_rounds': counting_task_rounds, 'placement_score': self.player.in_all_rounds()[0].placement_score, 'cumulative_payoff': pay } page_sequence = [ Instructions, CognitiveReflectionTest, IntermediateResults, WorkPage, Results ]