Changed endpoints and db queries, chart now shows suggested mins and maxes

This commit is contained in:
Daniel Ledda
2020-11-07 01:01:30 +01:00
parent 80cedfcff8
commit 5a522245c1

View File

@@ -40,7 +40,7 @@ func writeSnapshotToDb(snapshotSub *SnapshotSubmission) error {
}
func getSnapshotRecordsFromDb(minuteAgo int) ([]*SnapshotRecord, error) {
snapshots := make([]*SnapshotRecord)
snapshots := make([]*SnapshotRecord, 0)
query := "SELECT `%s`, `%s`, `%s`, `%s`, `%s` FROM `snapshots` WHERE `%s` > date_sub(now(), interval %v minute) ORDER BY `id` DESC;"
rows, err := ClimateDb.Query(fmt.Sprintf(query, "id", "temp", "humidity", "co2", "time", "time", minuteAgo))
if err != nil {
@@ -58,7 +58,7 @@ func getSnapshotRecordsFromDb(minuteAgo int) ([]*SnapshotRecord, error) {
if err != nil {
return nil, err
}
snapshots[i] = &snapshotRecord
snapshots = append(snapshots, &snapshotRecord)
}
return snapshots, nil
}