<commit_before>if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('/sw.js').then(function() {
    console.log('service worker is is all cool.');
  }).catch(function(e) {
    console.error('service worker is not so cool.', e);
    throw e;
  });
}

// bling.js
var $ = window.$ = document.querySelector.bind(document);
var $$ = window.$$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function(name, fn) {
  this.addEventListener(name, fn);
}
NodeList.prototype.__proto__ = Array.prototype;
NodeList.prototype.on = NodeList.prototype.addEventListener = (function(name, fn) {
  this.forEach(function(elem) {
    elem.on(name, fn);
  });
});


(function() {
  'use strict';

  var whenButtons;
  var locationSelects;
  var data = {};
  var opts = {
    amPM: true
  };

  function is_defined(obj) {
    return typeof (obj) !== 'undefined';
  }

  function hasLocalStorage() {
    try {
      localStorage.setItem('test', 'test');
      localStorage.removeItem('test');
      return true;
    } catch (e) {
      return false;
    }
  }

  function saveScheduleSelection() {
    if (!hasLocalStorage()) return;
    localStorage.setItem('caltrain-schedule-from', $('#from select').value);
    localStorage.setItem('caltrain-schedule-to', $('#to select').value);
    if (get_selected_schedule())
      localStorage.setItem('caltrain-schedule-when', get_selected_schedule());
    localStorage.setItem('opts', JSON.stringify(opts));
  }

  function select(elm, val) {
    elm.value = elm.querySelector('option[value="' + val + '"]').value;
  }

  function loadPreviousSettings() {
    if (!hasLocalStorage()) return;
    if (localStorage.getItem('caltrain-schedule-from'))
      select($('#from select'), localStorage.getItem('caltrain-schedule-from'));

    if (localStorage.getItem('caltrain-schedule-to'))
      select($('#to select'), localStorage.getItem('caltrain-schedule-to'));

    if (localStorage.getItem('caltrain-schedule-when')) {
      $$('.when-button').forEach(function(elem) {
        elem.classList.remove('selected');
      });
      var whenButton = $('.when-button[value="' + localStorage.getItem('caltrain-schedule-when') + '"]')
      if (whenButton)
        whenButton.classList.add('selected');
    }

    if (localStorage.getItem('opts'))
      opts = JSON.parse(localStorage.getItem('opts'));
  }

  String.prototype.repeat = function(num) {
    return (num <= 0) ? '' : this + this.repeat(num - 1);
  };

  String.prototype.rjust = function(width, padding) {
    padding = (padding || ' ').substr(0, 1); // one and only one char
    return padding.repeat(width - this.length) + this;
  };

  Object.extend = function(destination, source) {
    for (var property in source) {
      if (source.hasOwnProperty(property)) {
        destination[property] = source[property];
      }
    }
    return destination;
  };

  // now in seconds since the midnight
  function now() {
    var date = new Date();
    return date.getHours() * 60 * 60 +
           date.getMinutes() * 60 +
           date.getSeconds();
  }

  // now date in format YYYYMMDD
  function now_date() {
    return formatDate(new Date());
  }

  // format date to YYYYMMDD
  function formatDate (d) {
    // getMonth starts from 0
    return parseInt([d.getFullYear(), d.getMonth() + 1, d.getDate()].map(function(n) {
      return n.toString().rjust(2, '0');
    }).join(''), 10);
  }

  function second2str(seconds) {
    var minutes = Math.floor(seconds / 60);
    var hours = Math.floor(minutes / 60);
    var suffix = '';

    if (opts.amPM) {
      suffix = 12 <= hours && hours < 24 ? "PM" : "AM";
      hours = ((hours + 11) % 12 + 1);
    } else
      hours = (hours % 24).toString().rjust(2, '0');

    minutes = (minutes % 60).toString().rjust(2, '0');
    return [hours,':',minutes, suffix.small()].join('');
  }

  function time_relative(from, to) {
    return Math.round((to - from) / 60); // in minute
  }

  function is_now() {
    return get_selected_schedule() === 'now';
  }

  function get_selected_schedule() {
    var elem = $('.when-button.selected');
    if (!elem) return;
    return elem.value;
  }

  var DAY_OF_WEEK_MAP = {
    weekday: 1,
    saturday: 6,
    sunday: 0,
  };


  var bombardierIds = train_numbers
    .filter(train => bombardiers.includes(train.trip_short_name))
    .map(train => train.trip_id);


  function get_service_ids(calendar, calendar_dates) {
    console.assert(Object.keys(calendar).length === Object.keys(calendar_dates).length);
    console.assert(Object.keys(calendar).every(key => Object.keys(calendar_dates).includes(key)));

    var target_date = new Date();
    var today_day_of_week = new Date().getDay(); // getDay is "0 for Sunday"

    var selected_schedule = get_selected_schedule();
    var target_schedule = selected_schedule;
    if (target_schedule === 'now') {
      // when it's now, keep today's date and migrate target_schedule to real one
      switch (today_day_of_week) {
        case 1: case 2: case 3: case 4: case 5: target_schedule = 'weekday'; break;
        case 6: target_schedule = 'saturday'; break;
        case 0: target_schedule = 'sunday'; break;
        default: console.error('Unknown current day', today_day_of_week); return [];
      }
    } else {
      // when it's not, keep the schedule and migrate date to the next date matching the schedule
      var diff = (DAY_OF_WEEK_MAP[target_schedule] + 7 - today_day_of_week) % 7;
      target_date.setDate(target_date.getDate() + diff);
    }

    var service_ids = getValidServiceIdsForDate(calendar, target_date, target_schedule);

    // remove and add service_ids based on the calendar_dates.txt exceptions
    const {added, removed} = getCalendarExceptions(calendar_dates, target_date);
    service_ids = service_ids.filter(service_id => !removed.includes(service_id)).concat(added);

    if (service_ids.length === 0) {
      console.log("Can't get service for now.");<commit_msg>for weekday/etc schedules, iterate next_day until we have a non-holiday<commit_after>if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('/sw.js').then(function() {
    console.log('service worker is is all cool.');
  }).catch(function(e) {
    console.error('service worker is not so cool.', e);
    throw e;
  });
}

// bling.js
var $ = window.$ = document.querySelector.bind(document);
var $$ = window.$$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function(name, fn) {
  this.addEventListener(name, fn);
}
NodeList.prototype.__proto__ = Array.prototype;
NodeList.prototype.on = NodeList.prototype.addEventListener = (function(name, fn) {
  this.forEach(function(elem) {
    elem.on(name, fn);
  });
});


(function() {
  'use strict';

  var whenButtons;
  var locationSelects;
  var data = {};
  var opts = {
    amPM: true
  };

  function is_defined(obj) {
    return typeof (obj) !== 'undefined';
  }

  function hasLocalStorage() {
    try {
      localStorage.setItem('test', 'test');
      localStorage.removeItem('test');
      return true;
    } catch (e) {
      return false;
    }
  }

  function saveScheduleSelection() {
    if (!hasLocalStorage()) return;
    localStorage.setItem('caltrain-schedule-from', $('#from select').value);
    localStorage.setItem('caltrain-schedule-to', $('#to select').value);
    if (get_selected_schedule())
      localStorage.setItem('caltrain-schedule-when', get_selected_schedule());
    localStorage.setItem('opts', JSON.stringify(opts));
  }

  function select(elm, val) {
    elm.value = elm.querySelector('option[value="' + val + '"]').value;
  }

  function loadPreviousSettings() {
    if (!hasLocalStorage()) return;
    if (localStorage.getItem('caltrain-schedule-from'))
      select($('#from select'), localStorage.getItem('caltrain-schedule-from'));

    if (localStorage.getItem('caltrain-schedule-to'))
      select($('#to select'), localStorage.getItem('caltrain-schedule-to'));

    if (localStorage.getItem('caltrain-schedule-when')) {
      $$('.when-button').forEach(function(elem) {
        elem.classList.remove('selected');
      });
      var whenButton = $('.when-button[value="' + localStorage.getItem('caltrain-schedule-when') + '"]')
      if (whenButton)
        whenButton.classList.add('selected');
    }

    if (localStorage.getItem('opts'))
      opts = JSON.parse(localStorage.getItem('opts'));
  }

  String.prototype.repeat = function(num) {
    return (num <= 0) ? '' : this + this.repeat(num - 1);
  };

  String.prototype.rjust = function(width, padding) {
    padding = (padding || ' ').substr(0, 1); // one and only one char
    return padding.repeat(width - this.length) + this;
  };

  Object.extend = function(destination, source) {
    for (var property in source) {
      if (source.hasOwnProperty(property)) {
        destination[property] = source[property];
      }
    }
    return destination;
  };

  // now in seconds since the midnight
  function now() {
    var date = new Date();
    return date.getHours() * 60 * 60 +
           date.getMinutes() * 60 +
           date.getSeconds();
  }

  // now date in format YYYYMMDD
  function now_date() {
    return formatDate(new Date());
  }

  // format date to YYYYMMDD
  function formatDate (d) {
    // getMonth starts from 0
    return parseInt([d.getFullYear(), d.getMonth() + 1, d.getDate()].map(function(n) {
      return n.toString().rjust(2, '0');
    }).join(''), 10);
  }

  function second2str(seconds) {
    var minutes = Math.floor(seconds / 60);
    var hours = Math.floor(minutes / 60);
    var suffix = '';

    if (opts.amPM) {
      suffix = 12 <= hours && hours < 24 ? "PM" : "AM";
      hours = ((hours + 11) % 12 + 1);
    } else
      hours = (hours % 24).toString().rjust(2, '0');

    minutes = (minutes % 60).toString().rjust(2, '0');
    return [hours,':',minutes, suffix.small()].join('');
  }

  function time_relative(from, to) {
    return Math.round((to - from) / 60); // in minute
  }

  function is_now() {
    return get_selected_schedule() === 'now';
  }

  function get_selected_schedule() {
    var elem = $('.when-button.selected');
    if (!elem) return;
    return elem.value;
  }

  var DAY_OF_WEEK_MAP = {
    weekday: 1,
    saturday: 6,
    sunday: 0,
  };


  var bombardierIds = train_numbers
    .filter(train => bombardiers.includes(train.trip_short_name))
    .map(train => train.trip_id);


  function get_service_ids(calendar, calendar_dates) {
    console.assert(Object.keys(calendar).length === Object.keys(calendar_dates).length);
    console.assert(Object.keys(calendar).every(key => Object.keys(calendar_dates).includes(key)));

    var target_date = new Date();
    var today_day_of_week = new Date().getDay(); // getDay is "0 for Sunday"

    var target_schedule = get_selected_schedule();
    if (target_schedule === 'now') {
      // when it's now, keep today's date and migrate target_schedule to real one
      switch (today_day_of_week) {
        case 1: case 2: case 3: case 4: case 5: target_schedule = 'weekday'; break;
        case 6: target_schedule = 'saturday'; break;
        case 0: target_schedule = 'sunday'; break;
        default: console.error('Unknown current day', today_day_of_week); return [];
      }
    } else {
      // when it's not, keep the schedule and attempt the next that matches schedule and isn't a weird exception case.
      let found = false;
      for (var i = 0; found === false; i++) {
        var diff = (DAY_OF_WEEK_MAP[target_schedule] + 7 - today_day_of_week) % 7;
        target_date.setDate(target_date.getDate() + diff + i);

        const service_ids = getValidServiceIdsForDate(calendar, target_date, target_schedule);
        if (service_ids.length === 0) continue;

        const {added} = getCalendarExceptions(calendar_dates, target_date);
        found = added.length === 0;
      }
    }

    var service_ids = getValidServiceIdsForDate(calendar, target_date, target_schedule);

    // remove and add service_ids based on the calendar_dates.txt exceptions
    const {added, removed} = getCalendarExceptions(calendar_dates, target_date);
    service_ids = service_ids.filter(service_id => !removed.includes(service_id)).concat(added);

    if (service_ids.length === 0) {
      console.log("Can't get service for now.");
{'fraction_non_alphanumeric': 0.15298325475532434, 'fraction_numerical': 0.009022923101934645, 'mean_word_length': 3.3077731092436973, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '3911733', 'n_tokens_mistral': 3962, 'n_tokens_neox': 3772, 'n_words': 875}