<commit_before>require('./utils');

function VoteManager(candidates, vacantCandidates, maximumNbrOfVotes) {
    this.voteCount = createEmptyVoteResults(candidates, vacantCandidates);
    this.maximumNbrOfVotes = maximumNbrOfVotes;
    this.isOpen = true;
}

VoteManager.prototype.closeVotingSession = function() {
    this.isOpen = false;
    var that = this;

    return Object.keys(that.voteCount).map(function(k) {
        return that.voteCount[k];
    });
};

function createEmptyVoteResults(candidates, vacantCandidates) {
    var voteCount = {};
    candidates.concat(vacantCandidates).forEach(function(candidate) {
        voteCount[candidate.id] = {
            value: 0,
            item: candidate
        };
    });
    return voteCount;
}

VoteManager.prototype.getTotalVoteCount = function() {
    var that = this;

    return Object.keys(this.voteCount).map(function(key) { return that.voteCount[key].value; })
        .reduce(function(sum, value) {
            return sum + value;
        }, 0);
};

VoteManager.prototype.castVote = function(vote) {
    var that = this;
    this.validateVote(vote);

    vote.forEach(function(key) {
        that.increaseVoteForCandidate(key);
    });
};

VoteManager.prototype.validateVote = function(vote) {
    if (!this.isOpen) {
        throw 'Voting is closed';
    }
    if (!this.isValidAmountOfVotes(vote)) {
        throw 'Invalid amount of votes';
    }
    if (!this.allVotesUnique(vote)) {
        throw 'Duplicate votes';
    }
    if (!this.checkIfAllCandidatesInVoteAreValid(vote)) {
        throw 'Invalid option voted for';
    }
};

VoteManager.prototype.isValidAmountOfVotes = function(vote) {
    return vote.length <= this.maximumNbrOfVotes;
};

VoteManager.prototype.allVotesUnique = function(vote) {
    var unique = vote.filter(function(value, index, self) {
        return self.indexOf(value) === index;
    });<commit_msg>count votes per user<commit_after>require('./utils');

function VoteManager(candidates, vacantCandidates, maximumNbrOfVotes) {
    this.voteCount = createEmptyVoteResults(candidates, vacantCandidates);
    this.maximumNbrOfVotes = maximumNbrOfVotes;
    this.isOpen = true;
    this.numberOfVotes = 0;
}

VoteManager.prototype.closeVotingSession = function() {
    this.isOpen = false;
    var that = this;

    return Object.keys(that.voteCount).map(function(k) {
        return that.voteCount[k];
    });
};

function createEmptyVoteResults(candidates, vacantCandidates) {
    var voteCount = {};
    candidates.concat(vacantCandidates).forEach(function(candidate) {
        voteCount[candidate.id] = {
            value: 0,
            item: candidate
        };
    });
    return voteCount;
}

VoteManager.prototype.getTotalVoteCount = function() {
    return this.numberOfVotes;
};

VoteManager.prototype.castVote = function(vote) {
    var that = this;
    this.validateVote(vote);

    this.numberOfVotes++;

    vote.forEach(function(key) {
        that.increaseVoteForCandidate(key);
    });
};

VoteManager.prototype.validateVote = function(vote) {
    if (!this.isOpen) {
        throw 'Voting is closed';
    }
    if (!this.isValidAmountOfVotes(vote)) {
        throw 'Invalid amount of votes';
    }
    if (!this.allVotesUnique(vote)) {
        throw 'Duplicate votes';
    }
    if (!this.checkIfAllCandidatesInVoteAreValid(vote)) {
        throw 'Invalid option voted for';
    }
};

VoteManager.prototype.isValidAmountOfVotes = function(vote) {
    return vote.length <= this.maximumNbrOfVotes;
};

VoteManager.prototype.allVotesUnique = function(vote) {
    var unique = vote.filter(function(value, index, self) {
        return self.indexOf(value) === index;
    });
{'fraction_non_alphanumeric': 0.12401628222523745, 'fraction_numerical': 0.001085481682496608, 'mean_word_length': 3.30607476635514, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4182735', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1148, 'n_words': 197}