meshstats.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. define(function () {
  2. return function () {
  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 totalClients = sum(d.nodes.all.filter(online).map( function (d) {
  9. return d.statistics.clients
  10. }))
  11. var totalGateways = sum(d.nodes.all.filter(online).filter( function (d) {
  12. return d.flags.gateway
  13. }).map(one))
  14. stats.textContent = "Insgesamt " + totalNodes + " Knoten, " +
  15. "davon " + totalOnlineNodes + " online, " +
  16. totalClients + " Clients, " +
  17. totalGateways + " Gateways"
  18. timestamp.textContent = "Diese Daten sind von " + d.timestamp.format("LLLL") + "."
  19. }
  20. self.render = function (el) {
  21. var h2 = document.createElement("h2")
  22. h2.textContent = "Übersicht"
  23. el.appendChild(h2)
  24. var p = document.createElement("p")
  25. el.appendChild(p)
  26. stats = document.createTextNode("")
  27. p.appendChild(stats)
  28. p.appendChild(document.createElement("br"))
  29. timestamp = document.createTextNode("")
  30. p.appendChild(timestamp)
  31. }
  32. return self
  33. }
  34. })