Almost there

This commit is contained in:
Daniel Ledda
2020-11-14 15:26:45 +01:00
parent 99b7c21c76
commit d2955e53b4
4 changed files with 5 additions and 6 deletions

View File

@@ -2,9 +2,8 @@ package main
import (
"database/sql"
_ "github.com/Freeaqingme/golang-sql-driver-mysql"
"fmt"
"time"
_ "github.com/Freeaqingme/golang-sql-driver-mysql"
)
var ClimateDb *sql.DB
@@ -67,7 +66,7 @@ func getLastSnapshotRecordFromDb() (*SnapshotRecord, error) {
return &snapshotRecord, nil
}
func getSnapshotRecordsFromDb(dateSince time.Time) ([]*SnapshotRecord, error) {
func getSnapshotRecordsFromDb(dateSince string) ([]*SnapshotRecord, error) {
snapshots := make([]*SnapshotRecord, 0)
query := "SELECT `%s`, `%s`, `%s`, `%s`, `%s` FROM `snapshots` WHERE `%s` > %s ORDER BY `id` DESC;"
rows, err := ClimateDb.Query(fmt.Sprintf(query, "id", "temp", "humidity", "co2", "time", "time", dateSince))

View File

@@ -52,7 +52,7 @@ func sendData(w http.ResponseWriter, r *http.Request) {
}
dateSince = newDateSince
}
records, err := getSnapshotRecordsFromDb(dateSince)
records, err := getSnapshotRecordsFromDb(dateSince.String())
if internalErrorOnErr(fmt.Errorf("couldn't get snapshots from db: %w", err), w, r) { return }
json, err := createJsonFromSnapshotRecords(records)
if internalErrorOnErr(fmt.Errorf("couldn't create json from snapshots: %w", err), w, r) { return }

2
webapp/dist/main.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -46,7 +46,7 @@ class ClimateChart {
private async getInitialDataBlob(): Promise<SnapshotRecords> {
try {
const data = await fetch(this.rootUrl + "/data?since=" + (new Date().getTime() - this.minutesDisplayed * 60 * 1000));
const data = await fetch(this.rootUrl + "/data?since=" + new Date((new Date().getTime() - this.minutesDisplayed * 60 * 1000)).toISOString());
return await data.json();
}
catch (e) {