from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import numpy import random import numpy as np import time author = 'Vincent L' doc = """ tache d'effort seulement consistant à compter les 0 d'une matrice """ class Constants(BaseConstants): name_in_url = 'Reference_Point_App' players_per_group = None num_rounds = 200 c_Timer = 240 c_win_D1 = 1 c_RowCol44 = 4 c_RowCol66 = 6 c_Group = [1,2] class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: for p in self.get_players(): Group_rnd = random.choice(Constants.c_Group) # tache 0 # ------------------------------------------- if Group_rnd == 1: p.participant.vars['task'] = np.random.randint(2, size=(Constants.c_RowCol44, Constants.c_RowCol44)) p.participant.vars['Group'] = 44 elif Group_rnd == 2: p.participant.vars['task'] = np.random.randint(2, size=(Constants.c_RowCol66, Constants.c_RowCol66)) p.participant.vars['Group'] = 66 print(p.participant.vars['task']) p.participant.vars['total'] = 0 p.participant.vars['total_task'] = 0 class Group(BaseGroup): pass #def chunkify(lst, n): # return [lst[i::n] for i in range(n)] class Player(BasePlayer): real_count0 = models.IntegerField() suj_count0 = models.IntegerField() total_just = models.IntegerField() total_task = models.IntegerField() total_just1 = models.IntegerField() total_task1 = models.IntegerField() task_critere1 = models.IntegerField() time_reaction = models.FloatField() Group_expe = models.IntegerField() def groupage(self): self.in_round(Constants.num_rounds).task_critere1 = Constants.c_win_D1 def reinit_total(self): if self.round_number == 1 : self.participant.vars['total'] = 0 self.participant.vars['total_task'] = 0 #################################################################### # EFFORT 1 #################################################################### def matrix_i(self): if self.participant.vars['Group'] == 44 : self.participant.vars['task'] = np.random.randint(2, size=(Constants.c_RowCol44, Constants.c_RowCol44)) elif self.participant.vars['Group'] == 66 : self.participant.vars['task'] = np.random.randint(2, size=(Constants.c_RowCol66, Constants.c_RowCol66)) print(self.participant.vars['task']) self.real_count0 = np.count_nonzero(self.participant.vars['task'] == 0) print(self.real_count0) self.in_round(199).real_count0 = self.real_count0 def count_correct(self): if self.real_count0 == self.suj_count0: self.participant.vars['total'] = self.participant.vars['total'] + 1 self.participant.vars['total_task'] = self.participant.vars['total_task'] + 1 elif self.real_count0 != self.suj_count0: self.participant.vars['total'] = self.participant.vars['total'] + 0 self.participant.vars['total_task'] = self.participant.vars['total_task'] + 1 self.total_just = self.participant.vars['total'] self.total_task = self.participant.vars['total_task'] print('total:', self.participant.vars['total']) print('total:', self.participant.vars['total_task']) print('suj count:', self.suj_count0) if self.round_number <= Constants.num_rounds: self.in_round(Constants.num_rounds).total_just1 = self.total_just self.in_round(Constants.num_rounds).total_task1 = self.total_task-1 self.in_round(Constants.num_rounds).Group_expe = self.participant.vars['Group'] self.time_reaction = self.participant.vars['expiry'] - time.time()