from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random class Constants(BaseConstants): name_in_url = 'mtest1' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): name = models.StringField( label='Ваше ФИО?', ) zz = models.FloatField() def zz(self): zzz=random.randint(1, 500) return zzz def p6_1(self): random.seed(self.zz) vv = random.randint(100, 2000) return vv def p6_2(self): random.seed(self.zz) vv = random.randint(500, 1500) return vv def p6_3(self): random.seed(self.zz) vv = random.randint(2, 10) return vv def answer61_r(self): #random.seed(100) mm = 0 if (self.p6_1() > 7*self.p6_2()*0.1): mm = 'нет' else: mm = 'да' return mm def answer62_r(self): #random.seed(100) mm = round(self.p6_1() /(self.p6_2()*0.1)+0.4999999,2) return mm def answer63_r(self): # random.seed(100) mm = round(self.p6_1() / (self.p6_3() * 0.1),2) return mm answer61 = models.StringField ( label = '6.1', widget = widgets.RadioSelectHorizontal ) def answer61_choices(self): choices = ['да','нет'] random.shuffle(choices) return choices answer62 = models.FloatField( label='6.2', widget=widgets.RadioSelectHorizontal ) def answer62_choices(self): ff = self.answer62_r() choices = [ff, ff + random.randint(-10, 10)+1, ff + random.randint(-10, 10)-1,ff + random.randint(-10, 10)+2,ff + random.randint(-10, 10)+3] random.shuffle(choices) return choices answer63 = models.FloatField( label='6.3', widget=widgets.RadioSelectHorizontal ) def answer63_choices(self): ff = self.answer63_r() choices = [ff, ff + random.randint(-10, 10)+1, ff + random.randint(-10, 10)-1,ff + random.randint(-10, 10)+2,ff + random.randint(-10, 10)+3] random.shuffle(choices) return choices def point61(self): mm = 1 if (self.answer61 == self.answer61_r()): mm = 1 else: mm = 0 return mm def point62(self): mm = 1 if (self.answer62 == self.answer62_r()): mm = 1 else: mm = 0 return mm def point63(self): mm = 1 if (self.answer62 == self.answer62_r()): mm = 1 else: mm = 0 return mm def mark6(self): nn = 0 nn = self.point61()+self.point62()+self.point63() return nn # вторая задача def p7_1(self): random.seed(self.zz) vv = random.randint(30, 200) if (vv == 60): vv = random.randint(61, 200) else: mm = vv return vv def p7_2(self): random.seed(self.zz) vv = random.randint(60, 240) return vv def answer71_r(self): #random.seed(100) mm = 0 if (self.p7_1()/80 > 3/4): mm = self.p7_1() else: mm = 120 return mm def answer72_r(self): #random.seed(100) if (self.p7_1()/80 < 3/4): mm = 180 else: mm = (240*self.p7_1())/80 return mm def answer73_r(self): # random.seed(100) if (self.p7_1()/80 < 3/4 and self.p7_2()<80 ): mm = round((self.p7_2()-50)*(self.p7_1()/80),2) elif ( self.p7_1()/80 < 3/4 and self.p7_2()>80 ): mm=round((80-50)*(self.p7_1()/80)+(self.p7_2()-80)*(3/4),2) elif ( self.p7_1()/80 > 3/4 and self.p7_2()<160 ): mm=round((self.p7_2()-50)*(3/4),2) else: mm = round((160-50)*(3/4)+(self.p7_2()-160)*(self.p7_1()/80),2) return mm return mm answer71 = models.StringField ( label = '7.1', widget = widgets.RadioSelectHorizontal ) def answer71_choices(self): ff = self.answer71_r() choices = [ff, ff + random.randint(-10, 10)+1, ff + random.randint(-10, 10)-1,ff + random.randint(-10, 10)+2,ff + random.randint(-10, 10)+3] random.shuffle(choices) return choices answer72 = models.FloatField( label='7.2', widget=widgets.RadioSelectHorizontal ) def answer72_choices(self): ff = self.answer72_r() choices = [ff, ff + random.randint(-10, 10)+1, ff + random.randint(-10, 10)-1,ff + random.randint(-10, 10)+2,ff + random.randint(-10, 10)+3] random.shuffle(choices) return choices answer73 = models.FloatField( label='7.3', widget=widgets.RadioSelectHorizontal ) def answer73_choices(self): ff = self.answer73_r() choices = [ff, ff + random.randint(-10, 10)+1, ff + random.randint(-10, 10)-1,ff + random.randint(-10, 10)+2,ff + random.randint(-10, 10)+3] random.shuffle(choices) return choices def point71(self): mm = 1 if (self.answer71 == self.answer71_r()): mm = 1 else: mm = 0 return mm def point72(self): mm = 1 if (self.answer72 == self.answer72_r()): mm = 1 else: mm = 0 return mm def point73(self): mm = 1 if (self.answer72 == self.answer72_r()): mm = 1 else: mm = 0 return mm def mark7(self): nn = 0 nn = self.point71()+self.point72()+self.point73() return nn def mark(self): nn = 0 nn = self.point61()+self.point62()+self.point63()+self.point71()+self.point72()+self.point73() return nn # def time (self): # nn = 0 # nn = self.point61()+self.point62()+self.point63() # return nn def custom_export(players): # header row yield ['session', 'participant_code', 'round_number', 'id_in_group', 'payoff', 'name', 'mark', 'time'] for p in players: participant = p.participant session = p.session yield [session.code, participant.code, p.round_number, p.id_in_group, p.payoff, p.name()]