Almost there
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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
2
webapp/dist/main.js
vendored
File diff suppressed because one or more lines are too long
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user