-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
52 lines (42 loc) · 1.18 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package goco2
import (
"fmt"
"github.com/google/uuid"
"time"
)
// CO2Saving models the CO2 emissions saving per day, week, month, and year
type CO2Saving struct {
Day uint64 `json:"day"`
Week uint64 `json:"week"`
Month uint64 `json:"month"`
Year uint64 `json:"year"`
}
// Intervention models a house efficiency upgrade intervention
type Intervention struct {
ID uuid.UUID `json:"id"`
Date time.Time `json:"date"`
}
type Interventions map[string]Intervention
// Since returns the number of energy efficiency upgrade interventions since the specified time
func (i Interventions) Since(since time.Time) uint64 {
var intNumber uint64
for _, intervention := range i {
if intervention.Date.After(since) {
intNumber++
}
}
return intNumber
}
func (i Interventions) Today() uint64 {
return i.Since(time.Now().AddDate(0, 0, -1))
}
func (i Interventions) ThisWeek() uint64 {
return i.Since(time.Now().AddDate(0, 0, -7))
}
func (i Interventions) ThisMonth() uint64 {
return i.Since(time.Now().AddDate(0, -1, 0))
}
func (i Interventions) ThisYear() uint64 {
return i.Since(time.Now().AddDate(-1, 0, 0))
}
var ErrInterventionNotFound = fmt.Errorf("cannot find intervention information")