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

This commit is contained in:
Daniel Ledda
2020-11-07 00:50:36 +01:00
parent 69ee100edd
commit 40b23ebcde
3 changed files with 35 additions and 28 deletions

View File

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