Changed endpoints and db queries, chart now shows suggested mins and maxes
This commit is contained in:
15
Database.go
15
Database.go
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user