from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'task_second' players_per_group = None num_rounds = 45 unit = 60 allowedTime = 15 * unit piece_rate = 0.005 penalty_rate = 0.02 piece_rate_alt = 0.008 penalty_rate_alt = 0.32 import pandas as pd df = pd.read_csv("task/Barcode_Grading_40_Digits_2021_12_31.csv", encoding='utf-8', header=None) df.set_index(0, inplace=True) correctArray = df[1] class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): def CountMistakes(self, seq1, seq2): import numpy as np try: len(seq1) except: seq1 = "" try: len(seq2) except: seq2 = "" size_x = len(seq1) + 1 size_y = len(seq2) + 1 matrix = np.zeros((size_x, size_y)) for x in range(size_x): matrix[x, 0] = x for y in range(size_y): matrix[0, y] = y for x in range(1, size_x): for y in range(1, size_y): if seq1[x - 1] == seq2[y - 1]: matrix[x, y] = min( matrix[x - 1, y] + 1, matrix[x - 1, y - 1], matrix[x, y - 1] + 1 ) else: matrix[x, y] = min( matrix[x - 1, y] + 1, matrix[x - 1, y - 1] + 1, matrix[x, y - 1] + 1 ) mistakes = (matrix[size_x - 1, size_y - 1]) mistakes = int(mistakes) if len(seq1) <= 40: correct = len(seq2) - mistakes else: correct = len(seq1) - mistakes if correct < 0: correct = 0 return mistakes, correct showInterruption = models.BooleanField(initial=False) showScreen = models.BooleanField(initial=False) interruptionResponse = models.StringField(blank=False, label="", initial='NA') barcodeThisRound = models.IntegerField() actualCorrectAnswer = models.LongStringField() barcodeInput = models.LongStringField( blank=False, label="" ) mistakesThisRound = models.IntegerField() correctsThisRound = models.IntegerField() timeThisRound = models.FloatField() timeOnInterruption = models.FloatField(initial=0) earningThisRound = models.FloatField() # only for round 1 mistakesTally = models.IntegerField(initial=0) correctsTally = models.IntegerField(initial=0) earningFromTask = models.FloatField(initial=0) timePlaceholder = models.FloatField(initial=0)