<commit_before>import Rx from 'rx';
import _ from 'lodash';

import {hasGoalBeenScored} from './utils';

const advanceClockStep = 3;

export default function periodClock(period, durationInMinutes, endTime, goalScoringTimes, interval, scheduler) {
  const elements = generateSequence(period, durationInMinutes, endTime, goalScoringTimes);
  return Rx.Observable.interval(interval, scheduler)
    .takeWhile(index => index < elements.length)
    .map(index => elements[index]);
}

function generateSequence(period, durationInMinutes, endTime, goalScoringTimes) {
  const lastMinute = (endTime && endTime.minute) || -1;
  const lastSecond = (endTime && endTime.second) || -1;

  // Advance clock by second for all minutes but the last one of the 3rd period
  const allSecondElements = generateSecondElements(period, durationInMinutes, lastMinute, lastSecond);
  const secondElements = (period === 3) ? _.dropRight(allSecondElements, 60) : allSecondElements;

  // Advance clock by tenth of a second for the last minute of the 3rd period
  const tenthOfASecondElements = (period === 3) && (lastMinute < 1) ?
    generateTenthOfASecondElements(period, lastMinute, lastSecond) :
    [];

  const firstElement = { period, minute: durationInMinutes, second: 0 };<commit_msg>Show correct seconds if last OT goal is scored at zero seconds (e.g. 4:00)<commit_after>import Rx from 'rx';
import _ from 'lodash';

import {hasGoalBeenScored} from './utils';

const advanceClockStep = 3;

export default function periodClock(period, durationInMinutes, endTime, goalScoringTimes, interval, scheduler) {
  const elements = generateSequence(period, durationInMinutes, endTime, goalScoringTimes);
  return Rx.Observable.interval(interval, scheduler)
    .takeWhile(index => index < elements.length)
    .map(index => elements[index]);
}

function generateSequence(period, durationInMinutes, endTime, goalScoringTimes) {
  const lastMinute = endTime ? endTime.minute : -1;
  const lastSecond = endTime ? endTime.second : -1;

  // Advance clock by second for all minutes but the last one of the 3rd period
  const allSecondElements = generateSecondElements(period, durationInMinutes, lastMinute, lastSecond);
  const secondElements = (period === 3) ? _.dropRight(allSecondElements, 60) : allSecondElements;

  // Advance clock by tenth of a second for the last minute of the 3rd period
  const tenthOfASecondElements = (period === 3) && (lastMinute < 1) ?
    generateTenthOfASecondElements(period, lastMinute, lastSecond) :
    [];

  const firstElement = { period, minute: durationInMinutes, second: 0 };
{'fraction_non_alphanumeric': 0.10096711798839458, 'fraction_numerical': 0.009671179883945842, 'mean_word_length': 5.186602870813397, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1268444', 'n_tokens_mistral': 772, 'n_tokens_neox': 735, 'n_words': 235}