<commit_before>const PARTICIPATED = -1,
    NOT_PARTICIPATED = -2;

var participants = [
    {name: '<NAME>', results: [PARTICIPATED, PARTICIPATED]},
    {name: 'Ivar', results: [PARTICIPATED, PARTICIPATED]},
    {name: '<NAME>', results: [PARTICIPATED, PARTICIPATED]},
    {name: 'Herman', results: [NOT_PARTICIPATED, PARTICIPATED]},
    {name: 'Ole-André', results: [PARTICIPATED, PARTICIPATED]},
    {name: '<NAME>', results: [PARTICIPATED, PARTICIPATED]},
    {name: 'Håken', results: [PARTICIPATED, PARTICIPATED]},
    {name: 'Gustav', results: [PARTICIPATED, PARTICIPATED]},
    {name: 'Erlend', results: [NOT_PARTICIPATED, PARTICIPATED]},
    {name: 'Marius', results: [PARTICIPATED, PARTICIPATED]},
    {name: 'Erik', results: [PARTICIPATED, NOT_PARTICIPATED]},
    {name: 'Richard', results: [NOT_PARTICIPATED, 3]},
    {name: '<NAME>', results: [PARTICIPATED, NOT_PARTICIPATED]},
    {name: '<NAME>', results: [4, PARTICIPATED]},
    {name: '<NAME>', results: [NOT_PARTICIPATED, 4]},
    {name: 'Vetle', results: [PARTICIPATED, 2]},
    {name: 'Ken', results: [NOT_PARTICIPATED, PARTICIPATED]},
    {name: 'Seán', results: [2, PARTICIPATED]},
    {name: '<NAME>', results: [1, PARTICIPATED]},
    {name: 'Terje', results: [NOT_PARTICIPATED, PARTICIPATED]},
    {name: '<NAME>', results: [3, PARTICIPATED]},
    {name: 'Jarle', results: [PARTICIPATED, PARTICIPATED]},
    {name: '<NAME>', results: [NOT_PARTICIPATED, 1]},
    {name: 'Kristoffer', results: [NOT_PARTICIPATED, NOT_PARTICIPATED]},
];

var participantsTemplate = _.template(
    '<% _.forEach(participants, function(p,i) { %><tr><td><%= i+1 %></td><td><%- p.name %></td><td>[<%- p.resultList %>]</td><td><%- p.countingScore %></td><td style="opacity: .5"><%- p.score %></td></tr><% }); %>'
);

var rounds = [
    {head: "Lynsjakk", points: [500, 400, 300, 200], participationScore: 100},
    {head: "Darts", points: [500, 400, 300, 200], participationScore: 100},
];


$(document).ready(function() {
    renderScores();
});

function calcScore(participant) {
    // participation = -1, non-participation = -2

    var totalScore = 0;
    var scores = [];
    var scoreValues = [];
    _.each(participant.results, function(result, i) {
        var event = rounds[i];
        var numberOfScoredPlaces = event.points.length;

        if(result === PARTICIPATED || result > numberOfScoredPlaces) {
            totalScore += event.participationScore;
            scoreValues.push(event.participationScore);
            scores.push('D (' + event.participationScore + ')');
        } else if (result === NOT_PARTICIPATED) {
            totalScore += 0;
            scoreValues.push(0);
            scores.push('F (0)');
        } else {
            totalScore += event.points[result-1];
            scoreValues.push(event.points[result-1]);
            scores.push(result + ' (' + event.points[result-1] + ')');
        }
    });

    participant.resultList = scores.join(', ');
    participant.score = totalScore;
    participant.scoreValues = scoreValues;
}

function calcScoreDeductTwoWorst(participant) {
    // participation = -1, non-participation = -2
    var totalScore = 0;
    var scoreValuesList = participant.scoreValues.length >= 4
      ? participant.scoreValues.sort(compareNumbers).slice(2)
      : participant.scoreValues;

    _.each(scoreValuesList, function(result, i) {
        totalScore += result;
    });

    participant.countingScore = totalScore;
}

function renderScores() {
    var scoredAndSortedParticipants = _.chain(participants)
        .each(calcScore)
        .each(calcScoreDeductTwoWorst)
        .orderBy('countingScore', 'desc')
        .value();

    $('#results-table').html(participantsTemplate({participants: scoredAndSortedParticipants}));
}

function compareNumbers(a, b) {
    return a - b;
}<commit_msg>Update scup results for poker and sailing event<commit_after>const PARTICIPATED = -1,
  NOT_PARTICIPATED = -2;

var participants = [
  {
    name: '<NAME>',
    results: [PARTICIPATED, PARTICIPATED, PARTICIPATED, PARTICIPATED]
  },
  {
    name: 'Ivar',
    results: [PARTICIPATED, PARTICIPATED, PARTICIPATED, NOT_PARTICIPATED]
  },
  {
    name: '<NAME>',
    results: [PARTICIPATED, PARTICIPATED, PARTICIPATED, NOT_PARTICIPATED]
  },
  {
    name: 'Herman',
    results: [NOT_PARTICIPATED, PARTICIPATED, PARTICIPATED, NOT_PARTICIPATED]
  },
  { name: 'Ole-André', results: [PARTICIPATED, PARTICIPATED, PARTICIPATED, 1] },
  {
    name: '<NAME>',
    results: [PARTICIPATED, PARTICIPATED, PARTICIPATED, PARTICIPATED]
  },
  { name: 'Håken', results: [PARTICIPATED, PARTICIPATED, PARTICIPATED, 1] },
  { name: 'Gustav', results: [PARTICIPATED, PARTICIPATED, PARTICIPATED, 1] },
  {
    name: 'Erlend',
    results: [NOT_PARTICIPATED, PARTICIPATED, PARTICIPATED, NOT_PARTICIPATED]
  },
  {
    name: 'Marius',
    results: [PARTICIPATED, PARTICIPATED, PARTICIPATED, PARTICIPATED]
  },
  {
    name: 'Erik',
    results: [PARTICIPATED, NOT_PARTICIPATED, PARTICIPATED, NOT_PARTICIPATED]
  },
  {
    name: 'Richard',
    results: [NOT_PARTICIPATED, 3, PARTICIPATED, PARTICIPATED]
  },
  {
    name: '<NAME>',
    results: [PARTICIPATED, NOT_PARTICIPATED, PARTICIPATED, NOT_PARTICIPATED]
  },
  { name: '<NAME>', results: [4, PARTICIPATED, 1, 1] },
  {
    name: '<NAME>',
    results: [NOT_PARTICIPATED, 4, PARTICIPATED, NOT_PARTICIPATED]
  },
  { name: 'Vetle', results: [PARTICIPATED, 2, 3, NOT_PARTICIPATED] },
  { name: 'Ken', results: [NOT_PARTICIPATED, PARTICIPATED, PARTICIPATED, 1] },
  { name: 'Seán', results: [2, PARTICIPATED, PARTICIPATED, NOT_PARTICIPATED] },
  { name: '<NAME>', results: [1, PARTICIPATED, PARTICIPATED, PARTICIPATED] },
  {
    name: 'Terje',
    results: [NOT_PARTICIPATED, PARTICIPATED, PARTICIPATED, NOT_PARTICIPATED]
  },
  { name: '<NAME>', results: [3, PARTICIPATED, 4, PARTICIPATED] },
  {
    name: 'Jarle',
    results: [PARTICIPATED, PARTICIPATED, PARTICIPATED, PARTICIPATED]
  },
  {
    name: '<NAME>',
    results: [NOT_PARTICIPATED, 1, PARTICIPATED, PARTICIPATED]
  },
  {
    name: 'Kristoffer',
    results: [NOT_PARTICIPATED, NOT_PARTICIPATED, 2, PARTICIPATED]
  }
];

var participantsTemplate = _.template(
  '<% _.forEach(participants, function(p,i) { %><tr><td><%= i+1 %></td><td><%- p.name %></td><td>[<%- p.resultList %>]</td><td><%- p.countingScore %></td><td style="opacity: .5"><%- p.score %></td></tr><% }); %>'
);

var rounds = [
  { head: 'Lynsjakk', points: [500, 400, 300, 200], participationScore: 100 },
  { head: 'Darts', points: [500, 400, 300, 200], participationScore: 100 },
  { head: 'Poker', points: [500, 400, 300, 200], participationScore: 100 },
  { head: 'Seiling', points: [300, 0, 0, 0], participationScore: 100 }
];

$(document).ready(function() {
  renderScores();
});

function calcScore(participant) {
  // participation = -1, non-participation = -2

  var totalScore = 0;
  var scores = [];
  var scoreValues = [];
  _.each(participant.results, function(result, i) {
    var event = rounds[i];
    var numberOfScoredPlaces = event.points.length;

    if (result === PARTICIPATED || result > numberOfScoredPlaces) {
      totalScore += event.participationScore;
      scoreValues.push(event.participationScore);
      scores.push('D (' + event.participationScore + ')');
    } else if (result === NOT_PARTICIPATED) {
      totalScore += 0;
      scoreValues.push(0);
      scores.push('F (0)');
    } else {
      totalScore += event.points[result - 1];
      scoreValues.push(event.points[result - 1]);
      scores.push(result + ' (' + event.points[result - 1] + ')');
    }
  });

  participant.resultList = scores.join(', ');
  participant.score = totalScore;
  participant.scoreValues = scoreValues;
}

function calcScoreDeductTwoWorst(participant) {
  // participation = -1, non-participation = -2
  var totalScore = 0;
  var scoreValuesList =
    participant.scoreValues.length >= 4
      ? participant.scoreValues.sort(compareNumbers).slice(2)
      : participant.scoreValues;

  _.each(scoreValuesList, function(result, i) {
    totalScore += result;
  });

  participant.countingScore = totalScore;
}

function renderScores() {
  var scoredAndSortedParticipants = _.chain(participants)
    .each(calcScore)
    .each(calcScoreDeductTwoWorst)
    .orderBy('countingScore', 'desc')
    .value();

  $('#results-table').html(
    participantsTemplate({ participants: scoredAndSortedParticipants })
  );
}

function compareNumbers(a, b) {
  return a - b;
}
{'fraction_non_alphanumeric': 0.1686575990538143, 'fraction_numerical': 0.01714961561206387, 'mean_word_length': 3.8486238532110093, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 63, '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': '5848883', 'n_tokens_mistral': 3059, 'n_tokens_neox': 2905, 'n_words': 597}