-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.go
More file actions
96 lines (81 loc) · 1.74 KB
/
Copy pathmodel.go
File metadata and controls
96 lines (81 loc) · 1.74 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"sort"
"github.com/prairiegroupinc/linearsummarybot/yearmonth"
)
// Report represents a complete summary of all issues organized by month
type Report struct {
Months []*MonthData
}
type IssueData struct {
Identifier string
Title string
Points int
Schedule Schedule
MonthName string
YearMonth yearmonth.YM
InitName string // empty if orphaned
URL string
Bucket string
Labels []string
Clients []string
}
type MonthData struct {
Name string
Key yearmonth.YM
Initiatives map[string]*InitiativeData
Config *MonthConfig
IsPast bool
Capacity int
// Cached calculations
Fixed int
Planned int
Flex int
Used int
Total int
// Cached sorting
SortedInitiatives []*InitiativeData
}
func (md *MonthData) RemainingBudget() int {
return md.Capacity - md.Total
}
func (md *MonthData) IsOverCapacity() bool {
return md.RemainingBudget() < 0
}
func (md *MonthData) LookupInitiative(name string) *InitiativeData {
idata, ok := md.Initiatives[name]
if !ok {
idata = &InitiativeData{
Name: name,
Issues: make([]*IssueData, 0),
}
md.Initiatives[name] = idata
}
return idata
}
type InitiativeData struct {
Name string
Fixed int
Planned int
Flex int
Total int
Used int
Budget int
Issues []*IssueData
}
// sortIssues sorts Issues by points (descending) and identifier (ascending)
func (i *InitiativeData) sortIssues() {
sort.Slice(i.Issues, func(a, b int) bool {
if i.Issues[a].Points != i.Issues[b].Points {
return i.Issues[a].Points > i.Issues[b].Points // descending
}
return i.Issues[a].Identifier < i.Issues[b].Identifier // ascending
})
}
type Schedule int
const (
Unscheduled Schedule = iota
Fixed
Planned
Flex
)