<commit_before>var eventsRef = new Firebase('https://thebluealliance.firebaseio.com/events/');
var savedSnapshots = {};

function setActiveEvents(eventKeys) {
  // Remove old eventRefs
  for (eventKey in savedSnapshots) {
    if (!(eventKey in eventKeys)) {
      var eventKey = String(eventKey);
      eventsRef.child(eventKey).off();
      delete savedSnapshots[eventKey];
    }
  }

  // Add new eventRefs
  for (eventKey in eventKeys) {
    var eventKey = String(eventKey)
    if (eventKey in savedSnapshots) {
      updateMatchbar(eventKey, savedSnapshots[eventKey]);
    } else {
      eventsRef.child(eventKey).on('value', function(snapshot) {
        saveSnapshotAndUpdate(snapshot);
      });
    }
  }
}

function saveSnapshotAndUpdate(snapshot) {
  var eventKey = snapshot.key()
  savedSnapshots[eventKey] = snapshot;
  updateMatchbar(eventKey, snapshot);
}

function updateAllMatchbars() {
  for (eventKey in savedSnapshots) {
    updateMatchbar(eventKey, savedSnapshots[eventKey]);
  }
}

function updateMatchbar(event_key, snapshot) {
  var data = snapshot.val();
  var event_code = event_key.replace(/[0-9]/g, '').toUpperCase();

  var match_bar = $('.' + event_key + '_matches');

  if (data == null) {
    match_bar.each(function() {
      $(this).html($('<div>', {'class': 'match-number', text: event_code}));
      if (event_code != 'KICKOFF') {
        $(this).append($('<div>', {'class': 'match-bar-info', text: "No matches yet!"}));
      }
    });
    return;
  }

  var matchData = data.matches;

  var matches_list = [];<commit_msg>Fix issue where gameday matchbar crashes<commit_after>var eventsRef = new Firebase('https://thebluealliance.firebaseio.com/events/');
var savedSnapshots = {};

function setActiveEvents(eventKeys) {
  // Remove old eventRefs
  for (eventKey in savedSnapshots) {
    if (!(eventKey in eventKeys)) {
      var eventKey = String(eventKey);
      eventsRef.child(eventKey).off();
      delete savedSnapshots[eventKey];
    }
  }

  // Add new eventRefs
  for (eventKey in eventKeys) {
    var eventKey = String(eventKey)
    if (eventKey in savedSnapshots) {
      updateMatchbar(eventKey, savedSnapshots[eventKey]);
    } else {
      eventsRef.child(eventKey).on('value', function(snapshot) {
        saveSnapshotAndUpdate(snapshot);
      });
    }
  }
}

function saveSnapshotAndUpdate(snapshot) {
  var eventKey = snapshot.key()
  savedSnapshots[eventKey] = snapshot;
  updateMatchbar(eventKey, snapshot);
}

function updateAllMatchbars() {
  for (eventKey in savedSnapshots) {
    updateMatchbar(eventKey, savedSnapshots[eventKey]);
  }
}

function updateMatchbar(event_key, snapshot) {
  var data = snapshot.val();
  var event_code = event_key.replace(/[0-9]/g, '').toUpperCase();

  var match_bar = $('.' + event_key + '_matches');

  if (data == null || data.matches == null) {
    match_bar.each(function() {
      $(this).html($('<div>', {'class': 'match-number', text: event_code}));
      if (event_code != 'KICKOFF') {
        $(this).append($('<div>', {'class': 'match-bar-info', text: "No matches yet!"}));
      }
    });
    return;
  }

  var matchData = data.matches;

  var matches_list = [];
{'fraction_non_alphanumeric': 0.15323854660347552, 'fraction_numerical': 0.001263823064770932, 'mean_word_length': 3.7043090638930165, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '3511102', 'n_tokens_mistral': 1034, 'n_tokens_neox': 1030, 'n_words': 209}