<commit_before>/* Copyright 2017 UMass Transit Services
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Javascript for parsing and displaying departure information
var routes = {};
// Store all the routes we find running at the given stops
var all_route_ids = [];

// Specify a URL here to load settings first from a configuration file
var config_url;

var options =
{
  url: "https://bustracker.pvta.com/InfoPoint/rest/",
  title: "",                      // title to display at top of page
  stops: [],
  routes: [],
  excluded_trips: [],
  sort: "route",                  // default way to sort departures
  interval: 30000,                // default time in ms between refreshes
  work_day_start: 4,              // default time a new transit day starts
  start_animation: 'fadeInDown',  // default animate CSS for each row to be added with
  end_animation: 'fadeOut',       // default animate CSS for everything to be removed with at once
  alternateInterval: 3000,        // default time in ms between alternating time and interval
  disableAlternation: false,      // whether alternation should be disabled
  showMessages: 'yes',            // whether to show messages - 'yes', 'no', or 'only' for no departures
}

var container;
var sort_function;
var refresh_id;
var messages;
var stop_index = 0;

var MINIMUM_REFRESH_TIME = 5; // minimum number of seconds allowed for user input
var CASCADE_SPEED = 75; // time in ms which each row will take to cascade
var END_ANIMATION_TIME = 500; // the amount of time we give the ending animate CSS to work

// The timezone at the beginning of the current day, used for making sure ETAs don't become
// incorrect when switching between DST and...not DST.
var dst_at_start;

// Whether we're currently displaying the departure interval or the departure time.
var currentTimeDisplay = 'interval';
// The ID of the interval process which is alternating the display.
var alternateID;

function QueryStringAsObject() {
  var pairs = location.search.slice(1).split('&');
  
  var result = {};
  for(var i = 0; i < pairs.length; i++) {
      var pair = pairs[i].split('=');
      result[pair[0]] = decodeURIComponent(pair[1] || '');
  }

  return result;
}

$(function(){
  container = $('.main-content');
  updateOptions();
  initTitle();
  initBoard();
});

function startErrorRoutine() {
  stopRefreshing();
  // We don't have a connectivity notice into the DOM at the moment
  if (container.find('.connectivity_note').length == 0){
    container.append('<div class="connectivity_note">No Bus Information Available</div>');
  }
  $.ajax({
    url: options.url + "PublicMessages/GetCurrentMessages",
    success: function(route_data) {
      container.empty();
      initBoard();
    },
    timeout: 1000,
    error: function(){
      setTimeout(function(){startErrorRoutine()}, 5000)
    }
  });
}

function updateOptions() {
  // First load from a config_url if one is specified
  if (typeof config_url !== "undefined") {
    $.ajax({
      url: config_url,
      dataType: 'json',
      success: function(new_options) {
        // Copy all attributes from new_options to options, replacing existing
        // parameters with the new ones
        $.extend(options, new_options);
      },
      async: false,
      timeout: 1000
    });
  }

  var query = QueryStringAsObject();

  var title_string = query.title;
  if (typeof title_string !== "undefined") {
    // To handle browsers adding a slash after the query string
    if (title_string.slice(-1) == "/") {
      title_string = title_string.slice(0,-1);
    }
    options.title = title_string;
  }

  var stop_query_string = query.stops;
  // Check if a query string has been specified
  if (typeof stop_query_string !== "undefined") {
    var query_parts = stop_query_string.split("+");
    for (var i = 0; i < query_parts.length; i++) {
      if (query_parts[i]) {
        options.stops.push(query_parts[i]);
      }
    }
  }
  // If they didn't enter any stops, or they screwed up, default to stop ID 64, the Integrative Learning Center
  if (options.stops.length == 0) {
    options.stops = [64];
  }

  var route_query_string = query.routes;
  if (typeof route_query_string !== "undefined") {
    var query_parts = route_query_string.split("+");
    for (var i = 0; i < query_parts.length; i++) {
      if (query_parts[i]) {
        options.routes.push(query_parts[i]);
      }
    }
  }

  var excluded_query_string = query.excluded_trips;
  // Check if a query string has been specified
  if (typeof excluded_query_string !== "undefined") {
    var query_parts = excluded_query_string.split("+");
    for (var i = 0; i < query_parts.length; i++) {
      if (query_parts[i]) {
        options.excluded_trips.push(query_parts[i]);
      }
    }
  }

  var sort_query_string = query.sort;
  if (typeof sort_query_string !== "undefined") {
    options.sort = sort_query_string;
  }
  if (options.sort == "time") {
    sort_function = function(a, b) {
      return a.Departure.EDT < b.Departure.EDT ? -1 : 1;
    }
  } else {
    sort_function = function(a, b) {
      return a.Route.RouteAbbreviation > b.Route.RouteAbbreviation;
    }
  }

  // Expected value is in seconds, we convert to ms
  // Minimum allowed is MINIMUM_REFRESH_TIME seconds
  var interval_query_string = query.interval;
  if (typeof interval_query_string !== 'undefined'){
    options.interval = Math.max(MINIMUM_REFRESH_TIME, parseInt(interval_query_string)) * 1000;
  }

  // Bound alternateInterval between 1 second and half of the refresh interval.
  var alternateIntervalQueryString = query.alternate_interval;
  if (typeof alternateIntervalQueryString !== 'undefined'){
    var alternateInterval = parseInt(alternateIntervalQueryString) * 1000;
    alternateInterval = Math.max(1000, alternateInterval);
    alternateInterval = Math.min(alternateInterval, options.interval / 2);
    options.alternateInterval = alternateInterval;
  }

  var work_day_start_string = query.work_day_start;
  if (typeof work_day_start_string !== "undefined") {
    options.work_day_start = parseInt(work_day_start_string) % 24;
  }

  var start_animation_query_string = query.start_animation;
  if (typeof start_animation_query_string !== 'undefined'){
    options.start_animation = start_animation_query_string
  }

  var end_animation_query_string = query.end_animation;
  if (typeof end_animation_query_string !== 'undefined'){<commit_msg>Sort by the digits in a route<commit_after>/* Copyright 2017 UMass Transit Services
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Javascript for parsing and displaying departure information
var routes = {};
// Store all the routes we find running at the given stops
var all_route_ids = [];

// Specify a URL here to load settings first from a configuration file
var config_url;

var options =
{
  url: "https://bustracker.pvta.com/InfoPoint/rest/",
  title: "",                      // title to display at top of page
  stops: [],
  routes: [],
  excluded_trips: [],
  sort: "route",                  // default way to sort departures
  interval: 30000,                // default time in ms between refreshes
  work_day_start: 4,              // default time a new transit day starts
  start_animation: 'fadeInDown',  // default animate CSS for each row to be added with
  end_animation: 'fadeOut',       // default animate CSS for everything to be removed with at once
  alternateInterval: 3000,        // default time in ms between alternating time and interval
  disableAlternation: false,      // whether alternation should be disabled
  showMessages: 'yes',            // whether to show messages - 'yes', 'no', or 'only' for no departures
}

var container;
var sort_function;
var refresh_id;
var messages;
var stop_index = 0;

var MINIMUM_REFRESH_TIME = 5; // minimum number of seconds allowed for user input
var CASCADE_SPEED = 75; // time in ms which each row will take to cascade
var END_ANIMATION_TIME = 500; // the amount of time we give the ending animate CSS to work

// The timezone at the beginning of the current day, used for making sure ETAs don't become
// incorrect when switching between DST and...not DST.
var dst_at_start;

// Whether we're currently displaying the departure interval or the departure time.
var currentTimeDisplay = 'interval';
// The ID of the interval process which is alternating the display.
var alternateID;

function QueryStringAsObject() {
  var pairs = location.search.slice(1).split('&');
  
  var result = {};
  for(var i = 0; i < pairs.length; i++) {
      var pair = pairs[i].split('=');
      result[pair[0]] = decodeURIComponent(pair[1] || '');
  }

  return result;
}

$(function(){
  container = $('.main-content');
  updateOptions();
  initTitle();
  initBoard();
});

function startErrorRoutine() {
  stopRefreshing();
  // We don't have a connectivity notice into the DOM at the moment
  if (container.find('.connectivity_note').length == 0){
    container.append('<div class="connectivity_note">No Bus Information Available</div>');
  }
  $.ajax({
    url: options.url + "PublicMessages/GetCurrentMessages",
    success: function(route_data) {
      container.empty();
      initBoard();
    },
    timeout: 1000,
    error: function(){
      setTimeout(function(){startErrorRoutine()}, 5000)
    }
  });
}

function updateOptions() {
  // First load from a config_url if one is specified
  if (typeof config_url !== "undefined") {
    $.ajax({
      url: config_url,
      dataType: 'json',
      success: function(new_options) {
        // Copy all attributes from new_options to options, replacing existing
        // parameters with the new ones
        $.extend(options, new_options);
      },
      async: false,
      timeout: 1000
    });
  }

  var query = QueryStringAsObject();

  var title_string = query.title;
  if (typeof title_string !== "undefined") {
    // To handle browsers adding a slash after the query string
    if (title_string.slice(-1) == "/") {
      title_string = title_string.slice(0,-1);
    }
    options.title = title_string;
  }

  var stop_query_string = query.stops;
  // Check if a query string has been specified
  if (typeof stop_query_string !== "undefined") {
    var query_parts = stop_query_string.split("+");
    for (var i = 0; i < query_parts.length; i++) {
      if (query_parts[i]) {
        options.stops.push(query_parts[i]);
      }
    }
  }
  // If they didn't enter any stops, or they screwed up, default to stop ID 64, the Integrative Learning Center
  if (options.stops.length == 0) {
    options.stops = [64];
  }

  var route_query_string = query.routes;
  if (typeof route_query_string !== "undefined") {
    var query_parts = route_query_string.split("+");
    for (var i = 0; i < query_parts.length; i++) {
      if (query_parts[i]) {
        options.routes.push(query_parts[i]);
      }
    }
  }

  var excluded_query_string = query.excluded_trips;
  // Check if a query string has been specified
  if (typeof excluded_query_string !== "undefined") {
    var query_parts = excluded_query_string.split("+");
    for (var i = 0; i < query_parts.length; i++) {
      if (query_parts[i]) {
        options.excluded_trips.push(query_parts[i]);
      }
    }
  }

  var sort_query_string = query.sort;
  if (typeof sort_query_string !== "undefined") {
    options.sort = sort_query_string;
  }
  if (options.sort == "time") {
    sort_function = function(a, b) {
      return a.Departure.EDT < b.Departure.EDT ? -1 : 1;
    }
  } else {
    sort_function = function(a, b) {
      return a.Route.RouteAbbreviation.replace(/\D+/, '') > b.Route.RouteAbbreviation.replace(/\D+/, '');
    }
  }

  // Expected value is in seconds, we convert to ms
  // Minimum allowed is MINIMUM_REFRESH_TIME seconds
  var interval_query_string = query.interval;
  if (typeof interval_query_string !== 'undefined'){
    options.interval = Math.max(MINIMUM_REFRESH_TIME, parseInt(interval_query_string)) * 1000;
  }

  // Bound alternateInterval between 1 second and half of the refresh interval.
  var alternateIntervalQueryString = query.alternate_interval;
  if (typeof alternateIntervalQueryString !== 'undefined'){
    var alternateInterval = parseInt(alternateIntervalQueryString) * 1000;
    alternateInterval = Math.max(1000, alternateInterval);
    alternateInterval = Math.min(alternateInterval, options.interval / 2);
    options.alternateInterval = alternateInterval;
  }

  var work_day_start_string = query.work_day_start;
  if (typeof work_day_start_string !== "undefined") {
    options.work_day_start = parseInt(work_day_start_string) % 24;
  }

  var start_animation_query_string = query.start_animation;
  if (typeof start_animation_query_string !== 'undefined'){
    options.start_animation = start_animation_query_string
  }

  var end_animation_query_string = query.end_animation;
  if (typeof end_animation_query_string !== 'undefined'){
{'fraction_non_alphanumeric': 0.10877697841726619, 'fraction_numerical': 0.010215827338129497, 'mean_word_length': 3.3481388802001875, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4277102', 'n_tokens_mistral': 4208, 'n_tokens_neox': 4024, 'n_words': 1319}