property.eta 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <% layout("/sk/panel/stations/history/layout", { title: it.meteostanica.name }) %>
  2. <%~ include("/sk/panel/partials/navbar") %>
  3. <% const backIcon = `
  4. <svg class="icon" 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. <%~ include("/sk/panel/stations/partials/details", { meteostanica: it.meteostanica }) %>
  9. <div class="container-row">
  10. <a role="button" href="/panel/stations/<%= it.meteostanica.id %>/history"><%~ backIcon %></a>
  11. <h2><%~ it?.lang?.stations?.history.properties?.[it?.property]() %></h2>
  12. </div>
  13. <div class="historyLinks">
  14. <a role="button" href="/panel/stations/<%= it.meteostanica.id %>/history/<%= it.property %>/daily">deň</a>
  15. <a role="button" href="/panel/stations/<%= it.meteostanica.id %>/history/<%= it.property %>/monthly">mesiac</a>
  16. <a role="button" href="/panel/stations/<%= it.meteostanica.id %>/history/<%= it.property %>/yearly">rok</a>
  17. <a role="button" href="/panel/stations/<%= it.meteostanica.id %>/history/<%= it.property %>/allTime">celý čas</a>
  18. </div>
  19. <% if (it?.dateMap?.years) { %>
  20. <form id="historyForm">
  21. <% if (it?.dateMap?.days) { %>
  22. <div>
  23. <label for="day">deň</label>
  24. <select id="day" name="day">
  25. <% for (const item of it?.dateMap?.days) { %>
  26. <option value="<%= item %>" <%= item === it?.dateMap?.days[it?.dateMap?.days.length - 1] ? `selected` : `` %> ><%= item %></option>
  27. <% } %>
  28. </select>
  29. </div>
  30. <% } %>
  31. <% if (it?.dateMap?.months) { %>
  32. <div>
  33. <label for="month">mesiac</label>
  34. <select id="month" name="month">
  35. <% for (const item of it?.dateMap?.months) { %>
  36. <option value="<%= item %>" <%= item === it?.dateMap?.months[it?.dateMap?.months.length - 1] ? `selected` : `` %> > <%= it?.lang?.general.dateFormats.months?.[item]() %></option>
  37. <% } %>
  38. </select>
  39. </div>
  40. <% } %>
  41. <div>
  42. <label for="year">rok</label>
  43. <select id="year" name="year">
  44. <% for (const item of it?.dateMap?.years) { %>
  45. <option value="<%= item %>" <%= item === it?.dateMap?.years[it?.dateMap?.years.length - 1] ? `selected` : `` %> > <%= item %></option>
  46. <% } %>
  47. </select>
  48. </div>
  49. <button type="submit">načítať</button>
  50. </form>
  51. <% } %>
  52. <% const time = [] %>
  53. <% const data = [] %>
  54. <% for (const item of it.data) { %>
  55. <% time.push(item.timeMark) %>
  56. <% if (it.property === "outdoorConnected") {%>
  57. <% data.push(item.value) %>
  58. <% continue %>
  59. <% } %>
  60. <% data.push(item.value / 100) %>
  61. <% } %>
  62. <div>
  63. <canvas id="historyChart"></canvas>
  64. </div>
  65. <script>
  66. const ctx = document.getElementById('historyChart');
  67. new Chart(ctx, {
  68. type: 'bar',
  69. data: {
  70. labels: <%~ JSON.stringify(time, null, 2) %>,
  71. datasets: [{
  72. label: `<%= it.property %>`,
  73. data: <%~ JSON.stringify(data, null, 2) %>,
  74. borderWidth: 1
  75. }]
  76. },
  77. options: {
  78. scales: {
  79. y: {
  80. beginAtZero: true
  81. }
  82. }
  83. }
  84. });
  85. </script>