-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstats.go
68 lines (57 loc) · 1.57 KB
/
stats.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"sync"
)
// Notifications struct
type StatsDB struct {
db *DBHandler
querylocker sync.RWMutex
}
type StatRecord struct {
Date string `json:"date" storm:"id"`
TotalUsers int `json:"totalusers"`
OnlineUsers int `json:"onlineusers"`
IdleUsers int `json:"idleusers"`
DNDUsers int `json:"dndusers"`
InvisibleUsers int `json:"invisibleusers"`
GamingUsers int `json:"gamingusers"`
VoiceUsers int `json:"voiceusers"`
MessageCount int `json:"messagecount"`
Engagement int `json:"engagement"`
EngagementDaily int `json:"engagementdaily"`
ActiveUserCount int `json:"activeusercount"`
}
// AddStatToDB function
func (h *StatsDB) AddStatToDB(stat StatRecord) (err error) {
h.querylocker.Lock()
defer h.querylocker.Unlock()
db := h.db.rawdb.From("Statistics")
err = db.Save(&stat)
return err
}
// UpdateStatInDB function
func (h *StatsDB) UpdateStatInDB(stat StatRecord) (err error) {
h.querylocker.Lock()
defer h.querylocker.Unlock()
db := h.db.rawdb.From("Statistics")
err = db.Update(&stat)
return err
}
// RemoveStatFromDB function
func (h *StatsDB) RemoveStatFromDB(stat StatRecord) (err error) {
h.querylocker.Lock()
defer h.querylocker.Unlock()
db := h.db.rawdb.From("Statistics")
err = db.DeleteStruct(&stat)
return err
}
func (h *StatsDB) GetFullDB() (stats []StatRecord, err error) {
h.querylocker.Lock()
defer h.querylocker.Unlock()
db := h.db.rawdb.From("Statistics")
err = db.All(&stats)
if err != nil {
return stats, err
}
return stats, nil
}