<commit_before>﻿<h1>Test</h1>

<div id="list">
    <ul data-bind="foreach: { data: members}">
        <li>
            <img data-bind="attr: { src: Photo}" style="width: 69px;height: 78px;" />
            <span data-bind="text: $index"></span>
            <span data-bind="text: Name"></span>
            <span data-bind="text: MemberId"></span>
            <span data-bind="text: SwagCompany"></span>
            <span data-bind="text: SwagThing"></span>
        </li>
    </ul>

    <button data-bind="click: getNextWinner">Swag</button>

    @Html.ActionLink("Reset and shuffle", "Reset")
    
    <div id="winner">
        <h2 data-bind="text: name"></h2>
    </div>

</div>



@section scripts
{
    <script>
        $(function() {

            function memberViewodel(data) {
                this.Id = data.MemberId;
                this.MemberId = ko.observable(data.MemberId);
                this.Name = ko.observable(data.Name);
                this.SwagCompany = ko.observable("");
                this.SwagThing = ko.observable("");
                this.Photo = ko.observable(data.Photo);
            }

            function winnerViewModel() {
                this.name = ko.observable("sas");
            }

            $.getJSON("/home/memberlist")
                .then(function (rawData) {
                    return ko.utils.arrayMap(rawData, function(instanceData) {
                        return new memberViewodel(instanceData);
                    });
                })
                .done(function (mappedData) {
                    doit(mappedData);
            });

            function doit(mappedData) {
                ko.applyBindings({
                    members: ko.observableArray(mappedData),
                    getNextWinner: function () {
                        var members = this.members();
                        $.getJSON("/home/nextwinner")
                            .then(function (rawData) {
                                var winner = ko.utils.arrayFirst(members, function (member) {
                                    return member.Id === rawData.Winner.MemberId;
                                });
                                winner.SwagThing(rawData.WonSwag.Thing);
                                winner.SwagCompany(rawData.WonSwag.Company);
                                console.log(rawData.Winner.Name);
                                //WinnerViewModel.Name("sds");
                                //console.log(WinnerViewModel.Name());
                            });
                    }
                }, $("#list")[0]);

            }

        });
    </script>
}


<commit_msg>Working copy based on http://plnkr.co/edit/EwhMaORuOSsAXhfJMnsj?p=preview<commit_after>﻿<h1>Test</h1>

<div id="list">
    <ul data-bind="foreach: { data: Members}">
        <li>
            <img data-bind="attr: { src: Photo}" style="width: 69px;height: 78px;" />
            <span data-bind="text: $index"></span>
            <span data-bind="text: Name"></span>
            <span data-bind="text: MemberId"></span>
            <span data-bind="text: SwagCompany"></span>
            <span data-bind="text: SwagThing"></span>
        </li>
    </ul>

    <button data-bind="click: GetNextWinner">Swag</button>

    @Html.ActionLink("Reset and shuffle", "Reset")

    <div id="winner">
        <span data-bind="text: Winner">Hit the swag button</span>
        <span data-bind="text: WinnerSwagThing"></span>
    </div>

</div>



@section scripts
{
    <script>
        var memberViewModel = function memberViewModel(data) {
            var self = this;
            self.Id = data.MemberId;
            self.MemberId = ko.observable(data.MemberId);
            self.Name = ko.observable(data.Name);
            self.Photo = ko.observable(data.Photo);
            self.SwagCompany = ko.observable(data.SwagCompany);
            self.SwagThing = ko.observable(data.SwagThing);
        };

        $.getJSON("/home/memberlist")
            .then(function (rawData) {
                return ko.utils.arrayMap(rawData, function (instanceData) {
                    return new memberViewModel(instanceData);
                });
            })
            .done(function (mappedData) {
                applyBindings(mappedData);
            });

        function applyBindings(data) {
            var masterViewModel = function () {
                var self = this;
                self.Members = ko.observableArray(data);

                self.Winner = ko.observable("Hit the swag button..");
                self.WinnerSwagThing = ko.observable();

                self.GetNextWinner = function () {
                    loadNextWinner(self);
                };
            };
            
            ko.applyBindings(new masterViewModel());
        }

        function loadNextWinner(model) {
            $.getJSON("/home/nextwinner")
            .then(function (rawData) {
                var nextWinner = ko.utils.arrayFirst(model.Members(), function (member) {
                    return member.Id === rawData.Winner.MemberId;
                });
                nextWinner.SwagThing(rawData.WonSwag.Thing);

                model.Winner(rawData.Winner.Name);
                model.WinnerSwagThing(rawData.WonSwag.Thing);
            });
        }
    </script>

}


{'fraction_non_alphanumeric': 0.13501316284317413, 'fraction_numerical': 0.0028206092515983454, 'mean_word_length': 1.4762569832402235, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4210979', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1458, 'n_words': 238}