Changed endpoints and db queries, chart now shows suggested mins and maxes
This commit is contained in:
21
Database.go
21
Database.go
@@ -39,6 +39,27 @@ func writeSnapshotToDb(snapshotSub *SnapshotSubmission) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getLastSnapshotRecordFromDb() (*SnapshotRecord, error) {
|
||||
var snapshotRecord SnapshotRecord
|
||||
query := "SELECT `%s`, `%s`, `%s`, `%s`, `%s` FROM `snapshots` ORDER BY `id` DESC LIMIT 1;"
|
||||
rows, err := ClimateDb.Query(fmt.Sprintf(query, "id", "temp", "humidity", "co2", "time"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rows.Next()
|
||||
err = rows.Scan(
|
||||
&snapshotRecord.Id,
|
||||
&snapshotRecord.Temp,
|
||||
&snapshotRecord.Humidity,
|
||||
&snapshotRecord.Co2,
|
||||
&snapshotRecord.Timestamp,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &snapshotRecord, nil
|
||||
}
|
||||
|
||||
func getSnapshotRecordsFromDb(minuteAgo int) ([]*SnapshotRecord, error) {
|
||||
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;"
|
||||
|
||||
Reference in New Issue
Block a user