<commit_before>
function createFile(graph) {
  var self = {};

  function offerDownload(filename, text) {
    var a = document.createElement('a');
    a.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
    a.setAttribute('download', filename);

    a.style.display = 'none';
    document.body.appendChild(a);

    a.click();
    document.body.removeChild(a);
  }

  function readFileContent(id, callback) {
    var file = document.getElementById(id).files[0];
    if (file) {
      var r = new FileReader();
      r.onload = function(e) {
        callback(e.target.result);
      }
      r.readAsText(file);
    } else {
      alert('No file selected.');
    }
  }

  function reloadJavaScriptFile(id, src) {
    // Remove old script
    var e = document.getElementById(id);
    e.parentNode.removeChild(e);

    // Load new script
    var s = document.createElement('script');
    s.id = id;
    if (src.indexOf('\n') === -1) {
      s.src = src;
    } else {
      s.textContent = src;
    }
    document.head.appendChild(s);
  }

  self.reloadNodeImplementation = function reloadNodeImplementation (id) {
    function changeImpl() {
      var nodeMap = {};

      // Recreate all Node objects 
      var intNodes = graph.getIntNodes();
      for (var i = 0; i < intNodes.length; i++) {
        var intNode = intNodes[i];
        var oldNode = intNode.o;
        var newNode = new Node(oldNode.mac, oldNode.meta);

        // Copy over fields
        if (typeof Node.prototype.copyFromOldImplementation !== "function") {
          copyExistingFields(oldNode, newNode);
        } else {
          newNode.copyFromOldImplementation(oldNode);
        }

        // Replace old node instance
        intNode.o = newNode;

        nodeMap[newNode.mac] = newNode;
      }

      graph.redraw();
    }

    if ($(id).files.length) {
      readFileContent(id, function(content) {
        reloadJavaScriptFile('node_js', content);
        changeImpl();
      });
    } else {
      reloadJavaScriptFile('node_js', 'src/node.js');
      changeImpl();
    }
  }

  self.reloadPacketImplementation = function reloadPacketImplementation (id) {
    function changeImpl() {
      function renewPackets(packets) {
        for (var i = 0; i < packets.length; i++) {
          var oldPacket = packets[i];
          var newPacket = new Packet(
            oldPacket.transmitterAddress,
            oldPacket.receiverAddress,
            oldPacket.sourceAddress,
            oldPacket.destinationAddress
          );

          // Copy over fields
          if (typeof Packet.prototype.copyFromOldImplementation !== "function") {
            copyExistingFields(oldPacket, newPacket);
          } else {
            newPacket.copyFromOldImplementation(oldPacket);
          }

          // Replace old packet instance
          packets[i] = newPacket;
        }
      }

      var intNodes = graph.getIntNodes();
      for (var i = 0; i < intNodes.length; i++) {
        var intNode = intNodes[i];
        renewPackets(intNode.o.incoming);
        renewPackets(intNode.o.outgoing);
      }

      graph.redraw();
    }

    if ($(id).files.length) {
      readFileContent(id, function(content) {
        reloadJavaScriptFile('packet_js', content);
        changeImpl();
      });
    } else {
      reloadJavaScriptFile('packet_js', 'src/packet.js');
      changeImpl();
    }
  }

  self.reloadLinkImplementation = function reloadLinkImplementation (id) {
    function changeImpl() {
      // Recreate all link objects
      var intLinks = graph.getIntLinks();
      for (var i = 0; i < intLinks.length; i++) {
        var intLink = intLinks[i];
        var oldLink = intLink.o;
        var newLink = new Link(oldLink.quality, oldLink.bandwidth, oldLink.channel);

        // Copy over fields
        if (typeof Link.prototype.copyFromOldImplementation !== "function") {
          copyExistingFields(oldLink, newLink);
        } else {
          newLink.copyFromOldImplementation(oldLink);
        }

        // Replace old link instance
        intLink.o = newLink;
      }

      graph.redraw();
    }

    if ($(id).files.length) {
      readFileContent(id, function(content) {
        reloadJavaScriptFile('link_js', content);
        changeImpl();
      });
    } else {
      reloadJavaScriptFile('link_js', 'src/link.js');
      changeImpl();<commit_msg>fix implementation reloading<commit_after>
function createFile(graph) {
  var self = {};

  function offerDownload(filename, text) {
    var a = document.createElement('a');
    a.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
    a.setAttribute('download', filename);

    a.style.display = 'none';
    document.body.appendChild(a);

    a.click();
    document.body.removeChild(a);
  }

  function readFileContent(id, callback) {
    var file = document.getElementById(id).files[0];
    if (file) {
      var r = new FileReader();
      r.onload = function(e) {
        callback(e.target.result);
      }
      r.readAsText(file);
    } else {
      alert('No file selected.');
    }
  }

  function reloadJavaScriptFile(id, src) {
    // Remove old script
    var e = document.getElementById(id);
    e.parentNode.removeChild(e);

    // Load new script
    var s = document.createElement('script');
    s.id = id;
    if (src.indexOf('\n') === -1) {
      s.src = src;
    } else {
      s.textContent = src;
    }
    document.head.appendChild(s);
  }

  self.reloadNodeImplementation = function reloadNodeImplementation (id) {
    function changeNodeImplementation() {
      var nodeMap = {};

      // Recreate all Node objects 
      var intNodes = graph.getIntNodes();
      for (var i = 0; i < intNodes.length; i += 1) {
        var intNode = intNodes[i];
        var oldNode = intNode.o;
        var newNode = new Node(oldNode.mac, oldNode.meta);

        // Copy over fields
        if (typeof Node.prototype.copyFromOldImplementation !== "function") {
          copyExistingFields(oldNode, newNode);
        } else {
          newNode.copyFromOldImplementation(oldNode);
        }

        // Replace old node instance
        intNode.o = newNode;

        nodeMap[newNode.mac] = newNode;
      }

      graph.redraw();
    }

    if ($(id).files.length) {
      readFileContent(id, function(content) {
        reloadJavaScriptFile('node_js', content);
        setTimeout(changeNodeImplementation, 10);
      });
    } else {
      reloadJavaScriptFile('node_js', 'src/node.js');
      setTimeout(changeNodeImplementation, 10);
    }
  }

  self.reloadPacketImplementation = function reloadPacketImplementation (id) {
    function changePacketImplementation() {
      function renewPackets(packets) {
        for (var i = 0; i < packets.length; i += 1) {
          var oldPacket = packets[i];
          var newPacket = new Packet(
            oldPacket.transmitterAddress,
            oldPacket.receiverAddress,
            oldPacket.sourceAddress,
            oldPacket.destinationAddress
          );

          // Copy over fields
          if (typeof Packet.prototype.copyFromOldImplementation !== "function") {
            copyExistingFields(oldPacket, newPacket);
          } else {
            newPacket.copyFromOldImplementation(oldPacket);
          }

          // Replace old packet instance
          packets[i] = newPacket;
        }
      }

      var intNodes = graph.getIntNodes();
      for (var i = 0; i < intNodes.length; i += 1) {
        var intNode = intNodes[i];
        renewPackets(intNode.o.incoming);
        renewPackets(intNode.o.outgoing);
      }

      graph.redraw();
    }

    if ($(id).files.length) {
      readFileContent(id, function(content) {
        reloadJavaScriptFile('packet_js', content);
        setTimeout(changePacketImplementation, 10);
      });
    } else {
      reloadJavaScriptFile('packet_js', 'src/packet.js');
      setTimeout(changePacketImplementation, 10);
    }
  }

  self.reloadLinkImplementation = function reloadLinkImplementation (id) {
    function changeLinkImplementation() {
      // Recreate all link objects
      var intLinks = graph.getIntLinks();
      for (var i = 0; i < intLinks.length; i += 1) {
        var intLink = intLinks[i];
        var oldLink = intLink.o;
        var newLink = new Link(oldLink.quality, oldLink.bandwidth, oldLink.channel);

        // Copy over fields
        if (typeof Link.prototype.copyFromOldImplementation !== "function") {
          copyExistingFields(oldLink, newLink);
        } else {
          newLink.copyFromOldImplementation(oldLink);
        }

        // Replace old link instance
        intLink.o = newLink;
      }

      graph.redraw();
    }

    if ($(id).files.length) {
      readFileContent(id, function(content) {
        reloadJavaScriptFile('link_js', content);
        setTimeout(changeLinkImplementation, 10);
      });
    } else {
      reloadJavaScriptFile('link_js', 'src/link.js');
      setTimeout(changeLinkImplementation, 10);
{'fraction_non_alphanumeric': 0.1229298655107258, 'fraction_numerical': 0.003334444814938313, 'mean_word_length': 2.326432532347505, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '286013', 'n_tokens_mistral': 2686, 'n_tokens_neox': 2585, 'n_words': 537}