-
Notifications
You must be signed in to change notification settings - Fork 21
/
workunitsSortby.go
51 lines (46 loc) · 1.42 KB
/
workunitsSortby.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
package core
// create workunit slice type to use for sorting
type WorkunitsSortby struct {
Order string
Direction string
Workunits []*Workunit
}
func (w WorkunitsSortby) Len() int {
return len(w.Workunits)
}
func (w WorkunitsSortby) Swap(i, j int) {
w.Workunits[i], w.Workunits[j] = w.Workunits[j], w.Workunits[i]
}
func (w WorkunitsSortby) Less(i, j int) bool {
// default is ascending
if w.Direction == "desc" {
i, j = j, i
}
switch w.Order {
// default is info.submittime
default:
return w.Workunits[i].Info.SubmitTime.Before(w.Workunits[j].Info.SubmitTime)
case "wuid":
return w.Workunits[i].Id < w.Workunits[j].Id
case "client":
return w.Workunits[i].Client < w.Workunits[j].Client
case "info.submittime":
return w.Workunits[i].Info.SubmitTime.Before(w.Workunits[j].Info.SubmitTime)
case "checkout_time":
return w.Workunits[i].CheckoutTime.Before(w.Workunits[j].CheckoutTime)
case "info.name":
return w.Workunits[i].Info.Name < w.Workunits[j].Info.Name
case "cmd.name":
return w.Workunits[i].Cmd.Name < w.Workunits[j].Cmd.Name
case "rank":
return w.Workunits[i].Rank < w.Workunits[j].Rank
case "totalwork":
return w.Workunits[i].TotalWork < w.Workunits[j].TotalWork
case "state":
return w.Workunits[i].State < w.Workunits[j].State
case "failed":
return w.Workunits[i].Failed < w.Workunits[j].Failed
case "info.priority":
return w.Workunits[i].Info.Priority < w.Workunits[j].Info.Priority
}
}