meshstats.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. define(function () {
  2. return function (config) {
  3. var self = this
  4. var stats, timestamp
  5. self.setData = function (d) {
  6. var totalNodes = sum(d.nodes.all.map(one))
  7. var totalOnlineNodes = sum(d.nodes.all.filter(online).map(one))
  8. var totalNewNodes = sum(d.nodes.new.map(one))
  9. var totalLostNodes = sum(d.nodes.lost.map(one))
  10. var totalClients = sum(d.nodes.all.filter(online).map( function (d) {
  11. return d.statistics.clients
  12. }))
  13. var nodetext = [{ count: totalOnlineNodes, label: "online" },
  14. { count: totalNewNodes, label: "neu" },
  15. { count: totalLostNodes, label: "verschwunden" }
  16. ].filter( function (d) { return d.count > 0 } )
  17. .map( function (d) { return [d.count, d.label].join(" ") } )
  18. .join(", ")
  19. stats.textContent = totalNodes + " Knoten " +
  20. "(" + nodetext + ") mit " +
  21. totalClients + " Clients"
  22. timestamp.textContent = "Diese Daten sind von " + d.timestamp.format("LLLL") + "."
  23. }
  24. self.render = function (el) {
  25. var h2 = document.createElement("h2")
  26. h2.textContent = config.siteName
  27. el.appendChild(h2)
  28. var p = document.createElement("p")
  29. el.appendChild(p)
  30. stats = document.createTextNode("")
  31. p.appendChild(stats)
  32. p.appendChild(document.createElement("br"))
  33. timestamp = document.createTextNode("")
  34. p.appendChild(timestamp)
  35. }
  36. return self
  37. }
  38. })