from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random author = 'Sunduz Divle' doc = """ Rat social confidence practise """ class Constants(BaseConstants): name_in_url = 'social_confidence' players_per_group = None minutes_given = 1.5 payment_per_question = 5 num_rounds = 1 num_questions = 13 answer_keys = ["ARASI", "TEK", "HAVASI"] class Subsession(BaseSubsession): pass # def creating_session(self): # players = self.get_players() # volunteers = [p for p in players if p.participant.vars['social_confidence'] == 1] # if len(volunteers) > 0: # p_perform = random.choice(volunteers) # for p in players: # p.practise = len(volunteers) # if p == p_perform: # p.perform = 1 # else: # p.perform = 0 # p.participant.vars['perform'] = p.perform # p.participant.vars['practise'] = p.practise # else: # for p in players: # p.practise = 0 # p.perform = 0 # p.participant.vars['perform'] = p.perform # p.participant.vars['practise'] = p.practise class Group(BaseGroup): pass class Player(BasePlayer): # perform = models.IntegerField(initial=0) # practise= models.IntegerField(initial=0) # payoff_social_confidence = models.IntegerField(initial=0) q1 = models.StringField(label="Ekmek/Uluslar/Öğle") q2 = models.StringField(label="Yön/Şerit/Taş") q3 = models.StringField(label="Matem/Bayram/Göbek") q1_correct = models.IntegerField() q2_correct = models.IntegerField() q3_correct = models.IntegerField() rat_total_correct = models.IntegerField( initial=0, doc="total number of correct answers" ) def set_performances(self): self.q1=self.q1.upper() self.q2=self.q2.upper() self.q3=self.q3.upper() if self.q1 == Constants.answer_keys[0]: self.q1_correct = 1 else: self.q1_correct = 0 if self.q2 == Constants.answer_keys[1]: self.q2_correct = 1 else: self.q2_correct = 0 if self.q3 == Constants.answer_keys[2]: self.q3_correct = 1 else: self.q3_correct = 0 self.rat_total_correct = self.q1_correct + \ self.q2_correct + \ self.q3_correct self.payoff_social_confidence = self.rat_total_correct * Constants.payment_per_question self.participant.vars['payoff_social_confidence'] = self.payoff_social_confidence print("Total number of correct: rat_social_confidence", self.rat_total_correct) print("Payoff: social confidence", self.payoff_social_confidence) print("Payoff: social confidence", self.participant.vars['payoff_social_confidence'])