from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import datetime class General(Page): def vars_for_template(self): players = self.player.in_previous_rounds() chosen_app = self.participant.vars['chosen_app'] chosen_demand = self.participant.vars['chosen_demand'] return { 'player_in_previous_rounds': players, 'chosen_app': chosen_app, 'chosen_demand': chosen_demand } class General2(Page): def vars_for_template(self): players = self.player.in_previous_rounds() chosen_app = self.participant.vars['chosen_app'] chosen_demand = self.participant.vars['chosen_demand'] return { 'player_in_previous_rounds': players, 'chosen_app': chosen_app, 'chosen_demand': chosen_demand } class Comprehension(Page): form_model = 'player' form_fields = ['CQ1', 'CQ2', 'CQ3', 'CQ4', 'CQ5'] def is_displayed(self): return self.round_number == 1 def vars_for_template(self): y1 = Constants.determined_series[self.player.participant.vars['chosen_demand']][:] y1.insert(0, None) players = self.player.in_previous_rounds() new_days = 26 round_number = self.round_number round_operator = 0 while round_operator < 3: round_operator = round_operator + 1 y1.append(None) chosen_demand = self.participant.vars['chosen_demand'] return { 'highchart_series1': y1, 'player_in_previous_rounds': players, 'new_days': new_days, 'round_number': round_number, 'chosen_demand': chosen_demand } class Intro(Page): def is_displayed(self): return self.round_number == 1 def before_next_page(self): p = self.player p.participant.vars['time_previous'] = datetime.datetime.now() class Round_1(Page): form_model = 'player' form_fields = ['forecast_1'] def before_next_page(self): p = self.player p.actual_1 = 184 p.time_spent1 = (datetime.datetime.now() - p.participant.vars['time_previous']).total_seconds() p.participant.vars['time_previous'] = datetime.datetime.now() p.participant.vars['forecast_1'] = p.forecast_1 p.participant.vars['actual_1'] = p.actual_1 p.participant.vars['forecast_1_error'] = p.forecast_1 - p.actual_1 p.participant.vars['abs_forecast_1_error'] = abs(p.forecast_1 - p.actual_1) def vars_for_template(self): y1 = Constants.determined_series[self.player.participant.vars['chosen_demand']][:] y1.insert(0, None) players = self.player.in_previous_rounds() new_days = 26 round_number = self.round_number round_operator = 0 while round_operator < 3: round_operator = round_operator + 1 y1.append(None) chosen_demand = self.participant.vars['chosen_demand'] return { 'highchart_series1': y1, 'player_in_previous_rounds': players, 'new_days': new_days, 'round_number': round_number, 'chosen_demand': chosen_demand } class Round_2(Page): form_model = 'player' form_fields = ['forecast_2'] def before_next_page(self): p = self.player p.actual_2 = 218 p.time_spent2 = (datetime.datetime.now() - p.participant.vars['time_previous']).total_seconds() p.participant.vars['time_previous'] = datetime.datetime.now() p.participant.vars['forecast_2'] = p.forecast_2 p.participant.vars['actual_2'] = p.actual_2 p.participant.vars['forecast_2_error'] = p.forecast_2 - p.actual_2 p.participant.vars['abs_forecast_2_error'] = abs(p.forecast_2 - p.actual_2) def vars_for_template(self): y1 = Constants.determined_series[self.player.participant.vars['chosen_demand']][:] y1.insert(0, None) players = self.player.in_previous_rounds() new_days = 27 round_number = self.round_number forecast_1 = self.player.forecast_1 round_operator1 = 0 while round_operator1 < 3: round_operator1 = round_operator1 + 1 y1.append(None) chosen_demand = self.participant.vars['chosen_demand'] return { 'highchart_series1': y1, 'player_in_previous_rounds': players, 'new_days': new_days, 'round_number': round_number, 'forecast_1': forecast_1, 'chosen_demand': chosen_demand } class Round_3(Page): form_model = 'player' form_fields = ['forecast_3', ] def before_next_page(self): p = self.player p.actual_3 = 246 p.time_spent3 = (datetime.datetime.now() - p.participant.vars['time_previous']).total_seconds() p.participant.vars['time_previous'] = datetime.datetime.now() p.participant.vars['forecast_3'] = p.forecast_3 p.participant.vars['actual_3'] = p.actual_3 p.participant.vars['forecast_3_error'] = p.forecast_3 - p.actual_3 p.participant.vars['abs_forecast_3_error'] = abs(p.forecast_3 - p.actual_3) def vars_for_template(self): y1 = Constants.determined_series[self.player.participant.vars['chosen_demand']][:] y1.insert(0, None) players = self.player.in_previous_rounds() new_days = 28 round_number = self.round_number forecast_1 = self.player.forecast_1 forecast_2 = self.player.forecast_2 round_operator1 = 0 while round_operator1 < 3: round_operator1 = round_operator1 + 1 y1.append(None) chosen_demand = self.participant.vars['chosen_demand'] return { 'highchart_series1': y1, 'player_in_previous_rounds': players, 'new_days': new_days, 'round_number': round_number, 'forecast_1': forecast_1, 'forecast_2': forecast_2, 'chosen_demand': chosen_demand } class Results(Page): def is_displayed(self): return self.round_number == Constants.num_rounds class AQp1(Page): form_model = 'player' form_fields = ['AQ1', 'AQ2','AQ3'] class AQp2(Page): form_model = 'player' form_fields = ['AQ4', 'AQ5', 'AQ6'] class AQp3(Page): form_model = 'player' form_fields = ['AQ7', 'AQ8', 'AQ9', 'AQ10'] def app_after_this_page(self, upcoming_apps): return upcoming_apps[-1] page_sequence = [ General, General2, Comprehension, Intro, Round_1, Round_2, Round_3, Results, AQp1, AQp2, AQp3 ]