<commit_before>﻿define(['jquery', 'knockout', 'Common'], function ($, ko, Common) {


    return function PointsVote(options, pollData) {

        self = this;
        self.options = ko.observableArray(options);
        self.pointsArray = ko.observableArray();
        self.maxPerVote = ko.observable(pollData.MaxPerVote);
        self.maxPoints = ko.observable(pollData.MaxPoints);

        self.pointsRemaining = ko.computed(function () {
            var total = 0;
            ko.utils.arrayForEach(self.pointsArray(), function (item) {
                total += item;
            });
            var remaining = self.maxPoints() - total;
            return remaining;
        });

        self.percentRemaining = ko.computed(function () {
            return (self.pointsRemaining() / self.maxPoints()) * 100;
        });

        var resetVote = function () {
            //Populate with an array of options.length number of 0-values
            self.pointsArray(Array.apply(null, Array(options.length)).map(Boolean).map(Number));
            updateAllButtons();
        };

        var updateAllButtons = function () {
            var allButtonGroups = $("#optionTable span");
            for (var i = 0; i < allButtonGroups.length; i++) {
                var buttonGroup = allButtonGroups[i];
                updateButtons(buttonGroup);
            }
        }

        var countVotes = function (votes) {
            var totalCounts = [];
            votes.forEach(function (vote) {
                var optionName = vote.Option.Name;
                var voter = "Anonymous User";
                var voteValue = vote.PollValue;
                var voteString = voter + " (" + voteValue + ")";

                if (vote.User) {
                    voter = vote.User.Name;
                }

                // Find a vote with the same Option.Name, if it exists.
                var existingOption = totalCounts.filter(function (vote) { return vote.Name == optionName; }).pop();

                if (existingOption) {
                    existingOption.Sum += vote.PollValue;
                    existingOption.Voters.push(voteString);
                }
                else {
                    totalCounts.push({
                        Name: optionName,
                        Sum: vote.PollValue,
                        Voters: [voteString]
                    });
                }
            });
            return totalCounts;
        };

        var drawChart = function (data) {
            // Hack to fix insight's lack of data reloading
            $('#results').html('');
            var voteData = new insight.DataSet(data);

            var chart = new insight.Chart('', '#results')
            .width($("#results").width())
            .height(data.length * 50 + 100);<commit_msg>Fix for non-anonymous points votes having anonymous names<commit_after>﻿define(['jquery', 'knockout', 'Common'], function ($, ko, Common) {


    return function PointsVote(options, pollData) {

        self = this;
        self.options = ko.observableArray(options);
        self.pointsArray = ko.observableArray();
        self.maxPerVote = ko.observable(pollData.MaxPerVote);
        self.maxPoints = ko.observable(pollData.MaxPoints);

        self.pointsRemaining = ko.computed(function () {
            var total = 0;
            ko.utils.arrayForEach(self.pointsArray(), function (item) {
                total += item;
            });
            var remaining = self.maxPoints() - total;
            return remaining;
        });

        self.percentRemaining = ko.computed(function () {
            return (self.pointsRemaining() / self.maxPoints()) * 100;
        });

        var resetVote = function () {
            //Populate with an array of options.length number of 0-values
            self.pointsArray(Array.apply(null, Array(options.length)).map(Boolean).map(Number));
            updateAllButtons();
        };

        var updateAllButtons = function () {
            var allButtonGroups = $("#optionTable span");
            for (var i = 0; i < allButtonGroups.length; i++) {
                var buttonGroup = allButtonGroups[i];
                updateButtons(buttonGroup);
            }
        }

        var countVotes = function (votes) {
            var totalCounts = [];
            votes.forEach(function (vote) {
                var optionName = vote.Option.Name;
                var voter = "Anonymous User";
                var voteValue = vote.PollValue;

                if (vote.User) {
                    voter = vote.User.Name;
                }

                var voteString = voter + " (" + voteValue + ")";

                // Find a vote with the same Option.Name, if it exists.
                var existingOption = totalCounts.filter(function (vote) { return vote.Name == optionName; }).pop();

                if (existingOption) {
                    existingOption.Sum += vote.PollValue;
                    existingOption.Voters.push(voteString);
                }
                else {
                    totalCounts.push({
                        Name: optionName,
                        Sum: vote.PollValue,
                        Voters: [voteString]
                    });
                }
            });
            return totalCounts;
        };

        var drawChart = function (data) {
            // Hack to fix insight's lack of data reloading
            $('#results').html('');
            var voteData = new insight.DataSet(data);

            var chart = new insight.Chart('', '#results')
            .width($("#results").width())
            .height(data.length * 50 + 100);
{'fraction_non_alphanumeric': 0.11516009198655582, 'fraction_numerical': 0.0038917388996992748, 'mean_word_length': 1.5218554861730598, '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': '4233776', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1388, 'n_words': 326}