<commit_before>from __future__ import division
import random
import os
import numpy as np
import pickle
import datetime

class Decision(object):
    def __init__(self, pair, result, reviewer, time):
        self.pair = pair
        self.result = result
        self.reviewer = reviewer
        self.time = time

def ACJ(data, maxRounds, noOfChoices = 1, logPath = None, optionNames = None):
    if noOfChoices < 2:
        return UniACJ(data, maxRounds, logPath, optionNames)
    else:
        return MultiACJ(data, maxRounds, noOfChoices, logPath, optionNames)

class MultiACJ(object):
    '''Holds multiple ACJ objects for running comparisons with multiple choices.
    The first element of the list of acj objects keeps track of the used pairs.'''
    def __init__(self, data, maxRounds, noOfChoices, logPath = None, optionNames = None):
        self.data = list(data)
        self.n = len(data)
        self.round = 0
        self.step = 0
        self.noOfChoices = noOfChoices
        self.acjs = [ACJ(data, maxRounds) for _ in range(noOfChoices)]
        self.logPath = logPath
        if optionNames == None:
            self.optionNames = [str(i) for i in range(noOfChoices)]
        else:
            self.optionNames = optionNames
            self.nextRound()

    def getScript(self, ID):
        '''Gets script with ID'''
        return self.acjs[0].getScript(ID)

    def getID(self, script):
        '''Gets ID of script'''
        return self.acjs[0].getID(script)

    def infoPairs(self):
        '''Returns pairs based on summed selection arrays from Progressive Adaptive Comparitive Judgement
        Politt(2012) + Barrada, Olea, Ponsoda, and Abad (2010)'''
        pairs = []
        #Create
        sA = np.zeros((self.n, self.n))
        for acj in self.acjs:
            sA = sA+acj.selectionArray()
        while(np.max(sA)>0):
            iA, iB = np.unravel_index(sA.argmax(), sA.shape)
            pairs.append([self.data[iA], self.data[iB]])
            sA[iA,:] = 0
            sA[iB,:] = 0
            sA[:,iA] = 0
            sA[:,iB] = 0
        return pairs

    def nextRound(self):
        '''Returns next round of pairs'''
        roundList = self.infoPairs()
        for acj in self.acjs:
            acj.nextRound(roundList)
            acj.step = 0
        self.round = self.acjs[0].round
        self.step = self.acjs[0].step
        return self.acjs[0].roundList

    def nextPair(self):
        '''gets next pair from main acj'''
        p = self.acjs[0].nextPair(startNext=False)
        if p == -1:
            if self.nextRound() != None:
                p = self.acjs[0].nextPair(startNext=False)
            else:
                return None
        self.step = self.acjs[0].step
        return p

    def nextIDPair(self):
        '''Gets ID of next pair'''
        pair = self.nextPair()
        if pair == None:
            return None
        idPair = []
        for p in pair:
            idPair.append(self.getID(p))
        return idPair

    def WMS(self):
        ret = []
        for acj in self.acjs:
            ret.append(acj.WMS())
        return ret


    def comp(self, pair, result = None, update = None, reviewer = 'Unknown', time = 0):
        '''Adds in a result between a and b where true is a wins and False is b wins'''
        if result == None:
            result = [True for _ in range(self.noOfChoices)]
        if self.noOfChoices != len(result):
            raise StandardError('Results list needs to be noOfChoices in length')
        for i in range(self.noOfChoices):
            self.acjs[i].comp(pair, result[i], update, reviewer, time)
        if self.logPath != None:
            self.log(self.logPath, pair, result, reviewer, time)

    def IDComp(self, idPair, result = None, update = None, reviewer = 'Unknown', time = 0):
        '''Adds in a result between a and b where true is a wins and False is b wins. Uses IDs'''
        pair = []
        for p in idPair:
            pair.append(self.getScript(p))
        self.comp(pair, result, update, reviewer)

    def rankings(self, value=True):
        '''Returns current rankings
        Default is by value but score can be used'''
        rank = []
        for acj in self.acjs:
            rank.append(acj.rankings(value))
        return rank

    def reliability(self):
        '''Calculates reliability'''
        rel = []
        for acj in self.acjs:
            rel.append(acj.reliability()[0])
        return rel<commit_msg>Fixed IDComp not passing time<commit_after>from __future__ import division
import random
import os
import numpy as np
import pickle
import datetime

class Decision(object):
    def __init__(self, pair, result, reviewer, time):
        self.pair = pair
        self.result = result
        self.reviewer = reviewer
        self.time = time

def ACJ(data, maxRounds, noOfChoices = 1, logPath = None, optionNames = None):
    if noOfChoices < 2:
        return UniACJ(data, maxRounds, logPath, optionNames)
    else:
        return MultiACJ(data, maxRounds, noOfChoices, logPath, optionNames)

class MultiACJ(object):
    '''Holds multiple ACJ objects for running comparisons with multiple choices.
    The first element of the list of acj objects keeps track of the used pairs.'''
    def __init__(self, data, maxRounds, noOfChoices, logPath = None, optionNames = None):
        self.data = list(data)
        self.n = len(data)
        self.round = 0
        self.step = 0
        self.noOfChoices = noOfChoices
        self.acjs = [ACJ(data, maxRounds) for _ in range(noOfChoices)]
        self.logPath = logPath
        if optionNames == None:
            self.optionNames = [str(i) for i in range(noOfChoices)]
        else:
            self.optionNames = optionNames
            self.nextRound()

    def getScript(self, ID):
        '''Gets script with ID'''
        return self.acjs[0].getScript(ID)

    def getID(self, script):
        '''Gets ID of script'''
        return self.acjs[0].getID(script)

    def infoPairs(self):
        '''Returns pairs based on summed selection arrays from Progressive Adaptive Comparitive Judgement
        Politt(2012) + Barrada, Olea, Ponsoda, and Abad (2010)'''
        pairs = []
        #Create
        sA = np.zeros((self.n, self.n))
        for acj in self.acjs:
            sA = sA+acj.selectionArray()
        while(np.max(sA)>0):
            iA, iB = np.unravel_index(sA.argmax(), sA.shape)
            pairs.append([self.data[iA], self.data[iB]])
            sA[iA,:] = 0
            sA[iB,:] = 0
            sA[:,iA] = 0
            sA[:,iB] = 0
        return pairs

    def nextRound(self):
        '''Returns next round of pairs'''
        roundList = self.infoPairs()
        for acj in self.acjs:
            acj.nextRound(roundList)
            acj.step = 0
        self.round = self.acjs[0].round
        self.step = self.acjs[0].step
        return self.acjs[0].roundList

    def nextPair(self):
        '''gets next pair from main acj'''
        p = self.acjs[0].nextPair(startNext=False)
        if p == -1:
            if self.nextRound() != None:
                p = self.acjs[0].nextPair(startNext=False)
            else:
                return None
        self.step = self.acjs[0].step
        return p

    def nextIDPair(self):
        '''Gets ID of next pair'''
        pair = self.nextPair()
        if pair == None:
            return None
        idPair = []
        for p in pair:
            idPair.append(self.getID(p))
        return idPair

    def WMS(self):
        ret = []
        for acj in self.acjs:
            ret.append(acj.WMS())
        return ret


    def comp(self, pair, result = None, update = None, reviewer = 'Unknown', time = 0):
        '''Adds in a result between a and b where true is a wins and False is b wins'''
        if result == None:
            result = [True for _ in range(self.noOfChoices)]
        if self.noOfChoices != len(result):
            raise StandardError('Results list needs to be noOfChoices in length')
        for i in range(self.noOfChoices):
            self.acjs[i].comp(pair, result[i], update, reviewer, time)
        if self.logPath != None:
            self.log(self.logPath, pair, result, reviewer, time)

    def IDComp(self, idPair, result = None, update = None, reviewer = 'Unknown', time = 0):
        '''Adds in a result between a and b where true is a wins and False is b wins. Uses IDs'''
        pair = []
        for p in idPair:
            pair.append(self.getScript(p))
        self.comp(pair, result, update, reviewer, time)

    def rankings(self, value=True):
        '''Returns current rankings
        Default is by value but score can be used'''
        rank = []
        for acj in self.acjs:
            rank.append(acj.rankings(value))
        return rank

    def reliability(self):
        '''Calculates reliability'''
        rel = []
        for acj in self.acjs:
            rel.append(acj.reliability()[0])
        return rel
{'fraction_non_alphanumeric': 0.10990850256639143, 'fraction_numerical': 0.006694934166480696, 'mean_word_length': 2.0321380243572396, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1471116', 'n_tokens_mistral': 2830, 'n_tokens_neox': 2705, 'n_words': 826}