<commit_before>var client = (function eveClient(window, api, dispatcher) {
  var ixer = api.ixer;

  function now() {
    if(window.performance) {
      return window.performance.now();
    }
    return (new Date()).getTime();
  }

  function formatTime(time) {
    time = time || new Date();
    return pad("", time.getHours(), "0", 2) + ":" + pad("", time.getMinutes(), "0", 2) + ":" + pad("", time.getSeconds(), "0", 2);
  }

  function pad(left, right, pad, length) {
    left = "" + left;
    right = "" + right;
    pad = (pad !== undefined) ? pad : " ";
    length = (length !== undefined) ? length : 120;

    var padding = "";
    var delta = length - left.length - right.length;
    if(delta > 0) {
      padding = new Array(delta + 1).join(pad);
    }
    return left + padding + right;
  }

  function writeDataToConsole(data, verbosity) {
    verbosity = +verbosity;
    data.changes.forEach(function(change) {
      if(change[2].length || change[3].length) {
        if(verbosity == 1) {
          console.log(" ", change[0], "+" + change[2].length + "/-" + change[3].length);
        }
        if(verbosity == 2) {
          console.log(" ", change[0], "+" + change[2].length + "/-" + change[3].length,
                      {fields: change[1], inserts: change[2], removes: change[3]});
        }
        if(verbosity == 3) {
          console.log(" ", change[0], "+" + change[2].length + "/-" + change[3].length);
          console.groupCollapsed("   inserts", change[1]);
          console.table(change[2]);
          console.groupEnd();
          console.groupCollapsed("   removes", change[1]);
          console.table(change[3]);
          console.groupEnd();
        }
      }
    });
  }

  function getDataStats(data) {
    var totalAdds = 0;
    var totalRemoves = 0;
    var malformedDiffs = [];
    data.changes.forEach(function(change) {
      totalAdds += change[2].length;
      totalRemoves += change[3].length;
      var hasMalformedDiffs = change[2].some(function(diff) {
        return (diff.length !== change[1].length);
      });
      hasMalformedDiffs = hasMalformedDiffs || change[3].some(function(diff) {
        return (diff.length !== change[1].length);
      });
      if(hasMalformedDiffs) {
        malformedDiffs.push(change[0]);
      }
    });

    return {adds: totalAdds, removes: totalRemoves, malformedDiffs: malformedDiffs};
  }

  function initialize(noFacts) {
    api.initIndexer(noFacts);
    sendToServer(ixer.dumpMapDiffs(), true);
  }

  var server = {connected: false, queue: [], initialized: false, lastSent: []};
  function connectToServer() {
    var queue = server.queue;
    var ws = new WebSocket('ws://localhost:2794', []);
    server.ws = ws;

    ws.onerror = function (error) {
      console.log('WebSocket Error ' + error);
      server.dead = true;
      if(!server.initialized) {
        console.warn("Starting in local only mode, the server is dead.");
        initialize();
        dispatcher.render();
      }
    };

    ws.onmessage = function (e) {
      var start = now();
      var data = JSON.parse(e.data);
      var time = now() - start;
      if(time > 5) {
        console.log("slow parse (> 5ms):", time);
      }

      if(!server.initialized && data.changes.length === 54) { // @FIXME: Why is this the check?
        initialize();
      } else if(!server.initialized) {
        server.initialized = true;
        initialize(true);
      }
      if(window.DEBUG.RECEIVE) {
        var stats = getDataStats(data);
        if(stats.adds || stats.removes) {
          var header = "[client:received][+" + stats.adds + "/-" + stats.removes + "]";
          console.group(pad(header, formatTime()));
          if(stats.malformedDiffs.length) {
            console.warn("The following views have malformed diffs:", stats.malformedDiffs);
          }
          writeDataToConsole(data, window.DEBUG.RECEIVE);
          console.groupEnd();
        }
      }
      var start = now();
      ixer.handleMapDiffs(data.changes);
      var time = now() - start;
      if(time > 5) {
        console.log("slow handleDiffs (> 5ms):", time);
      }

      if(server.initialized && data.changes.length) {
        var uiDiffs = {};
        var mapDiffs = {};
        for(var ix = 0, len = data.changes.length; ix < len; ix++) {
          var diff = data.changes[ix];
          if(diff[0] === "uiRenderedElement") {
            uiDiffs.element = diff;
          } else if(diff[0] === "uiRenderedAttr") {
            uiDiffs.attr = diff;
          } else if(diff[0] === "uiMap") {
            mapDiffs.element = diff;
          } else if(diff[0] === "uiMapAttr") {
            mapDiffs.attr = diff;
          } else if(diff[0] === "uiMapMarker") {
            mapDiffs.marker = diff;
          } else if(diff[0] === "uiComponentElement") {
            // @FIXME: Hacky. This needs to be called after each size change in dev and production for map controls.
            diff[1].forEach(function(cur) {
              if(cur[4] === "map") {
                var map = ixer.index("uiElementToMap")[cur[1]];
                var mapEl = uiMapEl[map[1]];
                if(mapEl) {
                  google.maps.event.trigger(mapEl, "resize");
                }
              }
            });
          }
        }

        if(uiDiffs.element || uiDiffs.attr) {<commit_msg>Compute primitive view on receipt of view diffs<commit_after>var client = (function eveClient(window, api, dispatcher) {
  var ixer = api.ixer;

  function now() {
    if(window.performance) {
      return window.performance.now();
    }
    return (new Date()).getTime();
  }

  function formatTime(time) {
    time = time || new Date();
    return pad("", time.getHours(), "0", 2) + ":" + pad("", time.getMinutes(), "0", 2) + ":" + pad("", time.getSeconds(), "0", 2);
  }

  function pad(left, right, pad, length) {
    left = "" + left;
    right = "" + right;
    pad = (pad !== undefined) ? pad : " ";
    length = (length !== undefined) ? length : 120;

    var padding = "";
    var delta = length - left.length - right.length;
    if(delta > 0) {
      padding = new Array(delta + 1).join(pad);
    }
    return left + padding + right;
  }

  function writeDataToConsole(data, verbosity) {
    verbosity = +verbosity;
    data.changes.forEach(function(change) {
      if(change[2].length || change[3].length) {
        if(verbosity == 1) {
          console.log(" ", change[0], "+" + change[2].length + "/-" + change[3].length);
        }
        if(verbosity == 2) {
          console.log(" ", change[0], "+" + change[2].length + "/-" + change[3].length,
                      {fields: change[1], inserts: change[2], removes: change[3]});
        }
        if(verbosity == 3) {
          console.log(" ", change[0], "+" + change[2].length + "/-" + change[3].length);
          console.groupCollapsed("   inserts", change[1]);
          console.table(change[2]);
          console.groupEnd();
          console.groupCollapsed("   removes", change[1]);
          console.table(change[3]);
          console.groupEnd();
        }
      }
    });
  }

  function getDataStats(data) {
    var totalAdds = 0;
    var totalRemoves = 0;
    var malformedDiffs = [];
    data.changes.forEach(function(change) {
      totalAdds += change[2].length;
      totalRemoves += change[3].length;
      var hasMalformedDiffs = change[2].some(function(diff) {
        return (diff.length !== change[1].length);
      });
      hasMalformedDiffs = hasMalformedDiffs || change[3].some(function(diff) {
        return (diff.length !== change[1].length);
      });
      if(hasMalformedDiffs) {
        malformedDiffs.push(change[0]);
      }
    });

    return {adds: totalAdds, removes: totalRemoves, malformedDiffs: malformedDiffs};
  }

  function initialize(noFacts) {
    api.initIndexer(noFacts);
    sendToServer(ixer.dumpMapDiffs(), true);
  }

  var server = {connected: false, queue: [], initialized: false, lastSent: []};
  function connectToServer() {
    var queue = server.queue;
    var ws = new WebSocket('ws://localhost:2794', []);
    server.ws = ws;

    ws.onerror = function (error) {
      console.log('WebSocket Error ' + error);
      server.dead = true;
      if(!server.initialized) {
        console.warn("Starting in local only mode, the server is dead.");
        initialize();
        dispatcher.render();
      }
    };

    ws.onmessage = function (e) {
      var start = now();
      var data = JSON.parse(e.data);
      var time = now() - start;
      if(time > 5) {
        console.log("slow parse (> 5ms):", time);
      }

      if(!server.initialized && data.changes.length === 54) { // @FIXME: Why is this the check?
        initialize();
      } else if(!server.initialized) {
        server.initialized = true;
        initialize(true);
      }
      if(window.DEBUG.RECEIVE) {
        var stats = getDataStats(data);
        if(stats.adds || stats.removes) {
          var header = "[client:received][+" + stats.adds + "/-" + stats.removes + "]";
          console.group(pad(header, formatTime()));
          if(stats.malformedDiffs.length) {
            console.warn("The following views have malformed diffs:", stats.malformedDiffs);
          }
          writeDataToConsole(data, window.DEBUG.RECEIVE);
          console.groupEnd();
        }
      }
      var start = now();
      ixer.handleMapDiffs(data.changes);
      var time = now() - start;
      if(time > 5) {
        console.log("slow handleDiffs (> 5ms):", time);
      }

      if(server.initialized && data.changes.length) {
        var uiDiffs = {};
        var mapDiffs = {};
        for(var ix = 0, len = data.changes.length; ix < len; ix++) {
          var diff = data.changes[ix];
          if(diff[0] === "uiRenderedElement") {
            uiDiffs.element = diff;
          } else if(diff[0] === "uiRenderedAttr") {
            uiDiffs.attr = diff;
          } else if(diff[0] === "uiMap") {
            mapDiffs.element = diff;
          } else if(diff[0] === "uiMapAttr") {
            mapDiffs.attr = diff;
          } else if(diff[0] === "uiMapMarker") {
            mapDiffs.marker = diff;
          } else if(diff[0] === "uiComponentElement") {
            // @FIXME: Hacky. This needs to be called after each size change in dev and production for map controls.
            diff[1].forEach(function(cur) {
              if(cur[4] === "map") {
                var map = ixer.index("uiElementToMap")[cur[1]];
                var mapEl = uiMapEl[map[1]];
                if(mapEl) {
                  google.maps.event.trigger(mapEl, "resize");
                }
              }
            });
          } else if(diff[0] === "view") {
            ixer.handleDiffs(api.diff.computePrimitives());
          }
        }

        if(uiDiffs.element || uiDiffs.attr) {
{'fraction_non_alphanumeric': 0.16277993707199703, 'fraction_numerical': 0.011567647603183417, 'mean_word_length': 2.1452270081490106, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 13, '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': '1408326', 'n_tokens_mistral': 3452, 'n_tokens_neox': 3329, 'n_words': 693}