<commit_before>define(["moment", "router", "leaflet", "gui", "numeral"],
function (moment, Router, L, GUI, numeral) {
  return function (config) {
    function handleData(data) {
      var dataNodes = {}
      dataNodes.nodes = []
      var dataGraph = {}
      dataGraph.batadv = {}
      dataGraph.batadv.nodes = []
      dataGraph.batadv.links = []


      function rearrangeLinks(d) {
        d.source += dataGraph.batadv.nodes.length
        d.target += dataGraph.batadv.nodes.length
      }

      for (var i = 0; i < data.length; ++i) {
        var vererr
        if(i % 2)
          if (data[i].version !== 1) {
            vererr = "Unsupported graph version: " + data[i].version
            console.log(vererr) //silent fail
          } else {
            data[i].batadv.links.forEach(rearrangeLinks)
            dataGraph.batadv.nodes = dataGraph.batadv.nodes.concat(data[i].batadv.nodes)
            dataGraph.batadv.links = dataGraph.batadv.links.concat(data[i].batadv.links)
            dataGraph.timestamp = data[i].timestamp
          }
        else
          if (data[i].version !== 2) {
            vererr = "Unsupported nodes version: " + data[i].version
            console.log(vererr) //silent fail
          } else {
            dataNodes.nodes = dataNodes.nodes.concat(data[i].nodes)
            dataNodes.timestamp = data[i].timestamp
          }
      }

      var nodes = dataNodes.nodes.filter( function (d) {
        return "firstseen" in d && "lastseen" in d
      })

      nodes.forEach( function(node) {
        node.firstseen = moment.utc(node.firstseen).local()
        node.lastseen = moment.utc(node.lastseen).local()
      })

      var now = moment()
      var age = moment(now).subtract(config.maxAge, "days")

      var newnodes = limit("firstseen", age, sortByKey("firstseen", nodes).filter(online))
      var lostnodes = limit("lastseen", age, sortByKey("lastseen", nodes).filter(offline))

      var graphnodes = {}

      dataNodes.nodes.forEach( function (d) {
        graphnodes[d.nodeinfo.node_id] = d
      })

      var graph = dataGraph.batadv

      graph.nodes.forEach( function (d) {
        if (d.node_id in graphnodes)
          d.node = graphnodes[d.node_id]
      })

      graph.links.forEach( function (d) {
        if (graph.nodes[d.source].node)
          d.source = graph.nodes[d.source]
        else
          d.source = undefined

        if (graph.nodes[d.target].node)
          d.target = graph.nodes[d.target]
        else
          d.target = undefined
      })

      var links = graph.links.filter( function (d) {
        return d.source !== undefined && d.target !== undefined
      })

      links.forEach( function (d) {
        var ids = [d.source.node.nodeinfo.node_id, d.target.node.nodeinfo.node_id]
        d.id = ids.sort().join("-")

        if (!("location" in d.source.node.nodeinfo && "location" in d.target.node.nodeinfo))
          return

        d.latlngs = []
        d.latlngs.push(L.latLng(d.source.node.nodeinfo.location.latitude, d.source.node.nodeinfo.location.longitude))
        d.latlngs.push(L.latLng(d.target.node.nodeinfo.location.latitude, d.target.node.nodeinfo.location.longitude))

        d.distance = d.latlngs[0].distanceTo(d.latlngs[1])
      })

      nodes.forEach( function (d) {
        d.neighbours = []
      })

      links.forEach( function (d) {
        d.source.node.neighbours.push({ node: d.target.node, link: d, incoming: false })
        d.target.node.neighbours.push({ node: d.source.node, link: d, incoming: true })
        if (!d.type === "tunnel") {
          d.source.node.meshlinks = d.source.node.meshlinks ? d.source.node.meshlinks + 1 : 1
          d.target.node.meshlinks = d.target.node.meshlinks ? d.target.node.meshlinks + 1 : 1
        }
        if (d.type === "tunnel")
          d.type = "VPN"
        else if (d.type === "wireless")
          d.type = "Wifi"
        else if (d.type === "other")
          d.type = "Kabel"
        else
          d.type = "NaN"
      })

      links.sort( function (a, b) {
        return a.tq - b.tq
      })

      return { now: now,
               timestamp: moment.utc(dataNodes.timestamp).local(),
               nodes: {
                 all: nodes,
                 new: newnodes,
                 lost: lostnodes
               },
               graph: {
                 links: links,
                 nodes: graph.nodes
               }
             }<commit_msg>main: reverse link sorting<commit_after>define(["moment", "router", "leaflet", "gui", "numeral"],
function (moment, Router, L, GUI, numeral) {
  return function (config) {
    function handleData(data) {
      var dataNodes = {}
      dataNodes.nodes = []
      var dataGraph = {}
      dataGraph.batadv = {}
      dataGraph.batadv.nodes = []
      dataGraph.batadv.links = []


      function rearrangeLinks(d) {
        d.source += dataGraph.batadv.nodes.length
        d.target += dataGraph.batadv.nodes.length
      }

      for (var i = 0; i < data.length; ++i) {
        var vererr
        if(i % 2)
          if (data[i].version !== 1) {
            vererr = "Unsupported graph version: " + data[i].version
            console.log(vererr) //silent fail
          } else {
            data[i].batadv.links.forEach(rearrangeLinks)
            dataGraph.batadv.nodes = dataGraph.batadv.nodes.concat(data[i].batadv.nodes)
            dataGraph.batadv.links = dataGraph.batadv.links.concat(data[i].batadv.links)
            dataGraph.timestamp = data[i].timestamp
          }
        else
          if (data[i].version !== 2) {
            vererr = "Unsupported nodes version: " + data[i].version
            console.log(vererr) //silent fail
          } else {
            dataNodes.nodes = dataNodes.nodes.concat(data[i].nodes)
            dataNodes.timestamp = data[i].timestamp
          }
      }

      var nodes = dataNodes.nodes.filter( function (d) {
        return "firstseen" in d && "lastseen" in d
      })

      nodes.forEach( function(node) {
        node.firstseen = moment.utc(node.firstseen).local()
        node.lastseen = moment.utc(node.lastseen).local()
      })

      var now = moment()
      var age = moment(now).subtract(config.maxAge, "days")

      var newnodes = limit("firstseen", age, sortByKey("firstseen", nodes).filter(online))
      var lostnodes = limit("lastseen", age, sortByKey("lastseen", nodes).filter(offline))

      var graphnodes = {}

      dataNodes.nodes.forEach( function (d) {
        graphnodes[d.nodeinfo.node_id] = d
      })

      var graph = dataGraph.batadv

      graph.nodes.forEach( function (d) {
        if (d.node_id in graphnodes)
          d.node = graphnodes[d.node_id]
      })

      graph.links.forEach( function (d) {
        if (graph.nodes[d.source].node)
          d.source = graph.nodes[d.source]
        else
          d.source = undefined

        if (graph.nodes[d.target].node)
          d.target = graph.nodes[d.target]
        else
          d.target = undefined
      })

      var links = graph.links.filter( function (d) {
        return d.source !== undefined && d.target !== undefined
      })

      links.forEach( function (d) {
        var ids = [d.source.node.nodeinfo.node_id, d.target.node.nodeinfo.node_id]
        d.id = ids.sort().join("-")

        if (!("location" in d.source.node.nodeinfo && "location" in d.target.node.nodeinfo))
          return

        d.latlngs = []
        d.latlngs.push(L.latLng(d.source.node.nodeinfo.location.latitude, d.source.node.nodeinfo.location.longitude))
        d.latlngs.push(L.latLng(d.target.node.nodeinfo.location.latitude, d.target.node.nodeinfo.location.longitude))

        d.distance = d.latlngs[0].distanceTo(d.latlngs[1])
      })

      nodes.forEach( function (d) {
        d.neighbours = []
      })

      links.forEach( function (d) {
        d.source.node.neighbours.push({ node: d.target.node, link: d, incoming: false })
        d.target.node.neighbours.push({ node: d.source.node, link: d, incoming: true })
        if (!d.type === "tunnel") {
          d.source.node.meshlinks = d.source.node.meshlinks ? d.source.node.meshlinks + 1 : 1
          d.target.node.meshlinks = d.target.node.meshlinks ? d.target.node.meshlinks + 1 : 1
        }
        if (d.type === "tunnel")
          d.type = "VPN"
        else if (d.type === "wireless")
          d.type = "Wifi"
        else if (d.type === "other")
          d.type = "Kabel"
        else
          d.type = "NaN"
      })

      links.sort( function (a, b) {
        return b.tq - a.tq
      })

      return { now: now,
               timestamp: moment.utc(dataNodes.timestamp).local(),
               nodes: {
                 all: nodes,
                 new: newnodes,
                 lost: lostnodes
               },
               graph: {
                 links: links,
                 nodes: graph.nodes
               }
             }
{'fraction_non_alphanumeric': 0.1405144333370774, 'fraction_numerical': 0.002246433786364147, 'mean_word_length': 1.859344894026975, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1395691', 'n_tokens_mistral': 2844, 'n_tokens_neox': 2789, 'n_words': 527}