<commit_before>var m = require('mithril');
var classSet = require('common').classSet;
var button = require('../view/button');
var game = require('game').game;

function renderClock(ctrl, player, position) {
  var time = ctrl.clock.data[player.color];
  var running = ctrl.isClockRunning() && ctrl.data.game.player === player.color;
  var isPlayer = ctrl.data.player.color === player.color;
  return [
    m('div', {
      class: 'clock clock_' + player.color + ' clock_' + position + ' ' + classSet({
        'outoftime': !time,
        'running': running,
        'emerg': time < ctrl.clock.data.emerg
      })
    }, [
      showBar(ctrl.clock, player.color, time, ctrl.vm.goneBerserk[player.color]),
      m('div.time', {
        config: function(el, isUpdate, ctx) {
          if (player.color !== ctx.color) {
            ctrl.clock.elements[player.color].time = el;
            ctx.color = player.color;
          }
          ctrl.clock.elements[player.color].time.innerHTML = formatClockTime(ctrl.clock.data, time * 1000, running);
        }
      }),
      renderBerserk(ctrl, player.color, position),
      isPlayer ? goBerserk(ctrl) : button.moretime(ctrl),
      tourRank(ctrl, player.color, position)
    ])
  ];
}

function prefixInteger(num, length) {
  return (num / Math.pow(10, length)).toFixed(length).substr(2);
}

var sepHigh = '<sep>:</sep>';
var sepLow = '<sep class="low">:</sep>';

function formatClockTime(data, time, running) {
  var date = new Date(time);
  var minutes = prefixInteger(date.getUTCMinutes(), 2);
  var secs = date.getSeconds();
  var seconds = prefixInteger(secs, 2);
  var tenths = Math.floor(date.getMilliseconds() / 100);
  var hundredths = function() {
    return Math.floor(date.getMilliseconds() / 10) - tenths * 10;
  };
  var sep = (running && tenths < 5) ? sepLow : sepHigh;
  if ((data.showTenths == 2 && time < 3600000) || (data.showTenths == 1 && time < 10000)) {
    var showHundredths = !running && secs < 1;
    return minutes + sep + seconds +
    '<tenths><sep>.</sep>' + tenths + (showHundredths ? '<huns>' + hundredths() + '</huns>' : '') + '</tenths>';
  } else if (time >= 3600000) {
    var hours = prefixInteger(date.getUTCHours(), 2);
    return hours + sepHigh + minutes + sep + seconds;
  } else
  return minutes + sep + seconds;
}

function barWidth(data, time) {
  return Math.max(0, Math.min(100, (time / data.barTime) * 100)) + '%';
}

function showBar(ctrl, color, time, berserk) {
  return ctrl.data.showBar ? m('div', {
    class: 'bar' + (berserk ? ' berserk' : '')<commit_msg>Clean up game clock fun<commit_after>var m = require('mithril');
var classSet = require('common').classSet;
var button = require('../view/button');
var game = require('game').game;

function renderClock(ctrl, player, position) {
  var time = ctrl.clock.data[player.color];
  var running = ctrl.isClockRunning() && ctrl.data.game.player === player.color;
  var isPlayer = ctrl.data.player.color === player.color;
  return [
    m('div', {
      class: 'clock clock_' + player.color + ' clock_' + position + ' ' + classSet({
        'outoftime': !time,
        'running': running,
        'emerg': time < ctrl.clock.data.emerg
      })
    }, [
      showBar(ctrl.clock, player.color, time, ctrl.vm.goneBerserk[player.color]),
      m('div.time', {
        config: function(el, isUpdate, ctx) {
          if (player.color !== ctx.color) {
            ctrl.clock.elements[player.color].time = el;
            ctx.color = player.color;
          }
          ctrl.clock.elements[player.color].time.innerHTML = formatClockTime(ctrl.clock.data, time * 1000, running);
        }
      }),
      renderBerserk(ctrl, player.color, position),
      isPlayer ? goBerserk(ctrl) : button.moretime(ctrl),
      tourRank(ctrl, player.color, position)
    ])
  ];
}

function _pad2(num) {
  return (num < 10 ? '0' : '') + num;
}

var sepHigh = '<sep>:</sep>';
var sepLow = '<sep class="low">:</sep>';

function formatClockTime(data, time, running) {
  var date = new Date(time);
  var millis = date.getUTCMilliseconds();
  var sep = (running && millis < 500) ? sepLow : sepHigh;
  var baseStr = _pad2(date.getUTCMinutes()) + sep + _pad2(date.getUTCSeconds());
  if (time >= 3600000) {
    var hours = _pad2(Math.floor(time / 3600000));
    return hours + sepHigh + baseStr;
  } else if (time >= 10000 && date.showTenths != 2 || data.showTenths == 0) {
    return baseStr;
  } else {
    var tenthsStr = Math.floor(millis / 100).toString();
    if (!running && time < 1000) {
      tenthsStr += '<huns>' + (Math.floor(millis / 10) % 10) + '</huns>';
    }

    return baseStr + '<tenths><sep>.</sep>' + tenthsStr + '</tenths>';
  }
}

function barWidth(data, time) {
  return Math.max(0, Math.min(100, (time / data.barTime) * 100)) + '%';
}

function showBar(ctrl, color, time, berserk) {
  return ctrl.data.showBar ? m('div', {
    class: 'bar' + (berserk ? ' berserk' : '')
{'fraction_non_alphanumeric': 0.1755243331297088, 'fraction_numerical': 0.020362451639177357, 'mean_word_length': 3.1346801346801345, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 26, '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': '91460', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1631, 'n_words': 368}