-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.go
77 lines (67 loc) · 2.55 KB
/
report.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
69
70
71
72
73
74
75
76
77
package main
import (
"fmt"
"strings"
)
// Gives a summary for the week of current state and things that will need to be done.
func report() {
// Note: this produces YAML, but, really *dumb* YAML that looks like normal text
// Otherwise we could just use yaml.Marshal
reportData := gatherReportData()
rs := "Report:\n" // Report string
for catName, longCatName := range map[string]string{
"decision waiting": "Waiting for Decision",
"implementation waiting": "Waiting for Implementation",
"removal waiting": "Waiting for Removal",
"expires within five days": "Will Expire Within Five Days",
"expires within two weeks": "Will Expire Within Two Weeks",
} {
ids := reportData[catName]
c := len(ids)
if c != 0 {
rs = rs + fmt.Sprintf(" %s:\n Count: %d\n IDs:\n%s", longCatName, c, yamlListOfIDs(ids, 5))
}
}
fmt.Print(rs)
}
func yamlListOfIDs(list []uint, indent int) string {
var s string
sIndent := strings.Repeat(" ", indent)
for _, v := range list {
s = s + fmt.Sprintf("%s- %d\n", sIndent, v)
}
return s
}
func gatherReportData() map[string][]uint {
timeNow := getDBTimeNow()
time5daysFromNow := getDBFutureTimes("5 day")
timeTwoWeeksFromNow := getDBFutureTimes("14 day")
rd := make(map[string][]uint)
// We want the count of and IDs of:
// - things that are currently waiting for a decision
rd["decision waiting"] = getExceptionIDsWhere("status = 'undecided'")
// - things that are currently waiting for implementation
rd["implementation waiting"] = getExceptionIDsWhere("status = 'approved' AND start_date > " + timeNow)
// - things that are waiting to be removed
rd["removal waiting"] = getExceptionIDsWhere("status = 'implemented' AND end_date < " + timeNow)
// - things that will expire within the next 5 days (ie. working week)
rd["expires within five days"] = getExceptionIDsWhere("status = 'implemented' AND end_date >= " + timeNow + " AND end_date < " + time5daysFromNow)
// - things that will expire in the next 5-14 days (ie. their owner should be notified)
rd["expires within two weeks"] = getExceptionIDsWhere("status = 'implemented' AND end_date >= " + time5daysFromNow + " AND end_date < " + timeTwoWeeksFromNow)
return rd
}
func getExceptionIDsWhere(whereClause string) []uint {
exs := getExceptionsWhere(whereClause)
exIDs := make([]uint, 0)
for _, v := range exs {
exIDs = append(exIDs, v.ID)
}
return exIDs
}
func getExceptionsWhere(whereClause string) []Exception {
var listSet []Exception
db := getDB()
defer db.Close()
db.Where(whereClause).Find(&listSet)
return listSet
}