marek 1 mês atrás
pai
commit
c1839a2919

+ 7 - 0
assets/css/style.css

@@ -67,6 +67,13 @@ body {
     width: 10em;
     flex: 1;
     font-size: 1.2em;
+    display: flex;
+    flex-direction: column;
+    justify-content: flex-end;
+}
+
+#mainStats .stats .values p {
+    margin: 0.5em 0;
 }
 
 p {

Diferenças do arquivo suprimidas por serem muito extensas
+ 6 - 0
assets/js/chart.umd.js


+ 45 - 1
routes/include/history.js

@@ -10,7 +10,7 @@ export default (langName, lang) => new Elysia({ prefix: `/history` })
     return eta.render(`${langName}/history/index`, {  })
   })
   .get(`/:property`, ({ params: { property }, set }) => {
-    const data = Meteostanica.getDataProperty(property)
+    const data = Meteostanica.getDataPropertyMonthly(property, `2026-03`)
 
     if (!data) {
         set.headers['content-type'] = 'text/html; charset=utf8'
@@ -19,4 +19,48 @@ export default (langName, lang) => new Elysia({ prefix: `/history` })
 
     set.headers['content-type'] = 'text/html; charset=utf8'
     return eta.render(`${langName}/history/property`, { lang, property, data })
+  })
+  .get(`/:property/daily`, ({ params: { property }, set }) => {
+    const data = Meteostanica.getDataPropertyDaily(property, `2026-03-01`)
+
+    if (!data) {
+        set.headers['content-type'] = 'text/html; charset=utf8'
+        return eta.render(`${langName}/history/notFound`, { property })
+    }
+
+    set.headers['content-type'] = 'text/html; charset=utf8'
+    return eta.render(`${langName}/history/property`, { lang, type: `daily`, property, data })
+  })
+  .get(`/:property/monthly`, ({ params: { property }, set }) => {
+    const data = Meteostanica.getDataPropertyMonthly(property, `2026-03`)
+
+    if (!data) {
+        set.headers['content-type'] = 'text/html; charset=utf8'
+        return eta.render(`${langName}/history/notFound`, { property })
+    }
+
+    set.headers['content-type'] = 'text/html; charset=utf8'
+    return eta.render(`${langName}/history/property`, { lang, type: `monthly`, property, data })
+  })
+  .get(`/:property/yearly`, ({ params: { property }, set }) => {
+    const data = Meteostanica.getDataPropertyYearly(property, `2026`)
+
+    if (!data) {
+        set.headers['content-type'] = 'text/html; charset=utf8'
+        return eta.render(`${langName}/history/notFound`, { property })
+    }
+
+    set.headers['content-type'] = 'text/html; charset=utf8'
+    return eta.render(`${langName}/history/property`, { lang, type: `yearly`, property, data })
+  })
+  .get(`/:property/allTime`, ({ params: { property }, set }) => {
+    const data = Meteostanica.getDataPropertyAllTime(property)
+
+    if (!data) {
+        set.headers['content-type'] = 'text/html; charset=utf8'
+        return eta.render(`${langName}/history/notFound`, { property })
+    }
+
+    set.headers['content-type'] = 'text/html; charset=utf8'
+    return eta.render(`${langName}/history/property`, { lang, type: `allTime`, property, data })
   })

+ 2 - 1
templates/sk/history/layout.eta

@@ -4,10 +4,11 @@
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title><%= it.title ? `${it.title} — meteostanica` : "meteostanica" %></title>
-    <link rel="stylesheet" href="/assets/css/charts.css">
     <link rel="stylesheet" href="/assets/css/style.css">
 </head>
 <body>
+    <script src="/assets/js/chart.umd.js"></script>
+    
     <%~ it.body %>
 </body>
 </html>

+ 38 - 22
templates/sk/history/property.eta

@@ -4,29 +4,45 @@
 
 <h2>história <%= it?.property %></h2>
 
-<% if (it?.data?.length) { %>
-
 <%= JSON.stringify(it.data[0]) %>
 
-<table class="charts-css column show-primary-axis show-data-axes">
-    <% for (let i = 0; i < it.data.length; i++) { %>
-        <% const item = it.data?.[i] %>
-        
-        <% if (it.property === "outdoorConnected") { %>
-            <% item.value = item?.[it.property] %>
-            <% item.size = item.value %>
-        <% } else { %>
-            <% item.value = item?.[it.property] / 100 %>
-            <% item.size = item.value / 100 %>
-        <% } %>
-
-        <tr>
-            <td style="--size: <%= item.size %>;">
-                <span class="tooltip"> <%= item.value %> </span>
-            </td>
-            <% /* <td style="--size: <%= item.size %>;"> </td> */ %>
-        </tr>
+<% const time = [] %>
+<% const data = [] %>
+
+<% for (const item of it.data) { %>
+    <% time.push(item.timeMark) %>
+    
+    <% if (it.property === "outdoorConnected") {%>
+        <% data.push(item.value) %>
+        <% continue %>
     <% } %>
-</table>
 
-<% } %>
+    <% data.push(item.value / 100) %>
+<% } %>
+
+<div>
+    <canvas id="historyChart"></canvas>
+</div>
+
+<script>
+  const ctx = document.getElementById('historyChart');
+
+  new Chart(ctx, {
+    type: 'bar',
+    data: {
+      labels: <%~ JSON.stringify(time) %>,
+      datasets: [{
+        label: `<%= it.property %>`,
+        data: <%~ JSON.stringify(data) %>,
+        borderWidth: 1
+      }]
+    },
+    options: {
+      scales: {
+        y: {
+          beginAtZero: true
+        }
+      }
+    }
+  });
+</script>

+ 71 - 1
utils/meteostanica.js

@@ -32,7 +32,6 @@ export default class Meteostanica {
 
     static getDataProperty(property) {
         const tableNames = meteostanicaDB.prepare(`PRAGMA table_info('data');`).all()
-
         if (!tableNames.find(i => i.name === property)) return null
 
         const statement = meteostanicaDB.prepare(`
@@ -46,4 +45,75 @@ export default class Meteostanica {
 
         return result
     }
+
+    static getDataPropertyDaily(property, date) {
+        const tableNames = meteostanicaDB.prepare(`PRAGMA table_info('data');`).all()
+        if (!tableNames.find(i => i.name === property)) return null
+
+        const statement = meteostanicaDB.prepare(`
+            SELECT strftime('%Y-%m-%d %H:00:00', timestamp) AS timeMark, 
+                AVG(${property}) AS value
+            FROM data
+            WHERE date(timestamp) = ?  -- Pass 'YYYY-MM-DD' here
+            GROUP BY timeMark
+            ORDER BY timeMark;
+        `)
+        
+        const result = statement.all(date);
+
+        return result
+    }
+
+    static getDataPropertyMonthly(property, yearMonth) {
+        const tableNames = meteostanicaDB.prepare(`PRAGMA table_info('data');`).all()
+        if (!tableNames.find(i => i.name === property)) return null
+
+        const statement = meteostanicaDB.prepare(`
+            SELECT date(timestamp) AS timeMark, 
+                AVG(${property}) AS value
+            FROM data
+            WHERE strftime('%Y-%m', timestamp) = ? -- Pass 'YYYY-MM' here
+            GROUP BY timeMark
+            ORDER BY timeMark;
+        `)
+        
+        const result = statement.all(yearMonth);
+
+        return result
+    }
+
+    static getDataPropertyYearly(property, year) {
+        const tableNames = meteostanicaDB.prepare(`PRAGMA table_info('data');`).all()
+        if (!tableNames.find(i => i.name === property)) return null
+
+        const statement = meteostanicaDB.prepare(`
+            SELECT strftime('%Y-%m', timestamp) AS timeMark, 
+                AVG(${property}) AS value
+            FROM data
+            WHERE strftime('%Y', ts) = ? -- Pass 'YYYY' here
+            GROUP BY timeMark
+            ORDER BY timeMark;
+        `)
+        
+        const result = statement.all(year);
+
+        return result
+    }
+
+    static getDataPropertyAllTime(property) {
+        const tableNames = meteostanicaDB.prepare(`PRAGMA table_info('data');`).all()
+        if (!tableNames.find(i => i.name === property)) return null
+
+        const statement = meteostanicaDB.prepare(`
+            SELECT strftime('%Y', timestamp) AS timeMark, 
+                AVG(${property}) AS value
+            FROM data
+            GROUP BY timeMark
+            ORDER BY timeMark;
+        `)
+        
+        const result = statement.all();
+
+        return result
+    }
 }

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff