meshstats.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 totalGateways = sum(d.nodes.all.filter(online).filter( function (d) {
  14. return d.flags.gateway
  15. }).map(one))
  16. var nodetext = [{ count: totalOnlineNodes, label: "online" },
  17. { count: totalNewNodes, label: "neu" },
  18. { count: totalLostNodes, label: "verschwunden" }
  19. ].filter( function (d) { return d.count > 0 } )
  20. .map( function (d) { return [d.count, d.label].join(" ") } )
  21. .join(", ")
  22. stats.textContent = totalNodes + " Knoten " +
  23. "(" + nodetext + "), " +
  24. totalClients + " Clients, " +
  25. totalGateways + " Gateways"
  26. timestamp.textContent = "Diese Daten sind von " + d.timestamp.format("LLLL") + "."
  27. }
  28. self.render = function (el) {
  29. var h2 = document.createElement("h2")
  30. h2.textContent = config.siteName
  31. el.appendChild(h2)
  32. var p = document.createElement("p")
  33. el.appendChild(p)
  34. stats = document.createTextNode("")
  35. p.appendChild(stats)
  36. p.appendChild(document.createElement("br"))
  37. timestamp = document.createTextNode("")
  38. p.appendChild(timestamp)
  39. }
  40. return self
  41. }
  42. })