property.eta 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <% layout("/en/history/layout", { title: `history` }) %>
  2. <%~ include("/en/partials/topbar") %>
  3. <% const backIcon = `
  4. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  5. <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m12 19l-7-7l7-7m7 7H5" />
  6. </svg>
  7. ` %>
  8. <div class="container-row">
  9. <a role="button" href="/en/history"><%~ backIcon %> history</a>
  10. <h2><%~ it?.lang?.history.properties?.[it?.property]() %></h2>
  11. </div>
  12. <div class="historyLinks">
  13. <a role="button" href="/en/history/<%= it.property %>/daily">day</a>
  14. <a role="button" href="/en/history/<%= it.property %>/monthly">month</a>
  15. <a role="button" href="/en/history/<%= it.property %>/yearly">year</a>
  16. <a role="button" href="/en/history/<%= it.property %>/allTime">all time</a>
  17. </div>
  18. <% if (it?.dateMap?.years) { %>
  19. <form id="historyForm">
  20. <% if (it?.dateMap?.days) { %>
  21. <div>
  22. <label for="day">day</label>
  23. <select id="day" name="day">
  24. <% for (const item of it?.dateMap?.days) { %>
  25. <option value="<%= item %>" <%= item === it?.dateMap?.days[it?.dateMap?.days.length - 1] ? `selected` : `` %> ><%= item %></option>
  26. <% } %>
  27. </select>
  28. </div>
  29. <% } %>
  30. <% if (it?.dateMap?.months) { %>
  31. <div>
  32. <label for="month">month</label>
  33. <select id="month" name="month">
  34. <% for (const item of it?.dateMap?.months) { %>
  35. <option value="<%= item %>" <%= item === it?.dateMap?.months[it?.dateMap?.months.length - 1] ? `selected` : `` %> > <%= it?.lang?.history.dateFormats.months?.[item]() %></option>
  36. <% } %>
  37. </select>
  38. </div>
  39. <% } %>
  40. <div>
  41. <label for="year">year</label>
  42. <select id="year" name="year">
  43. <% for (const item of it?.dateMap?.years) { %>
  44. <option value="<%= item %>" <%= item === it?.dateMap?.years[it?.dateMap?.years.length - 1] ? `selected` : `` %> > <%= item %></option>
  45. <% } %>
  46. </select>
  47. </div>
  48. <button type="submit">load</button>
  49. </form>
  50. <% } %>
  51. <% const time = [] %>
  52. <% const data = [] %>
  53. <% for (const item of it.data) { %>
  54. <% time.push(item.timeMark) %>
  55. <% if (it.property === "outdoorConnected") {%>
  56. <% data.push(item.value) %>
  57. <% continue %>
  58. <% } %>
  59. <% data.push(item.value / 100) %>
  60. <% } %>
  61. <div>
  62. <canvas id="historyChart"></canvas>
  63. </div>
  64. <script>
  65. const ctx = document.getElementById('historyChart');
  66. new Chart(ctx, {
  67. type: 'bar',
  68. data: {
  69. labels: <%~ JSON.stringify(time, null, 2) %>,
  70. datasets: [{
  71. label: `<%= it.property %>`,
  72. data: <%~ JSON.stringify(data, null, 2) %>,
  73. borderWidth: 1
  74. }]
  75. },
  76. options: {
  77. scales: {
  78. y: {
  79. beginAtZero: true
  80. }
  81. }
  82. }
  83. });
  84. </script>