Add daily filter to events count checker.
This commit is contained in:
parent
054a933def
commit
d4028d37ec
1 changed files with 9 additions and 4 deletions
13
main.go
13
main.go
|
@ -3,7 +3,7 @@
|
|||
// TODO: Record Inverter struct data only on-change.
|
||||
// Idea: Make a full admin / config GUI and only configure through this utility.
|
||||
// Idea: Gather settings only on start-up.
|
||||
// TODO: handleMessage: Support older data age than 0, due to new OpenDTU WebSocket implementation.
|
||||
// TODO: handleMessage: Support older data age than 0, due to new OpenDTU WebSocket implementation?
|
||||
// TODO: Only update meter readings such as yieldday, yieldtotal on-change.
|
||||
// TODO: DB migrations.
|
||||
package main
|
||||
|
@ -444,11 +444,16 @@ func queryEventsEndpoint(inverterSerial string) (*EventsResponse, error) {
|
|||
return &eventsResponse, nil
|
||||
}
|
||||
|
||||
// TODO: This function should probably be altered to only select from current day.
|
||||
// CHECK.
|
||||
// The events counter reported by OpenDTU resets every day.
|
||||
func getPreviousEventsCount(db *sql.DB, inverterSerial string) int {
|
||||
var count int
|
||||
err := db.QueryRow("SELECT COUNT(*) FROM opendtu_events WHERE inverter_serial = $1", inverterSerial).Scan(&count)
|
||||
err := db.QueryRow(`
|
||||
SELECT COUNT(*)
|
||||
FROM opendtu_events
|
||||
WHERE inverter_serial = $1
|
||||
AND timestamp >= CURRENT_DATE
|
||||
AND timestamp < CURRENT_DATE + INTERVAL '1 day'
|
||||
`, inverterSerial).Scan(&count)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
logger.Error("Error querying previous events count", "error", err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue