OLD | NEW |
---|---|
(Empty) | |
1 package model | |
2 | |
3 import ( | |
4 "errors" | |
5 "strings" | |
6 ) | |
7 | |
8 const ( | |
9 // ResultsSize is the size that "results.json" should be trimmed to. | |
10 ResultsSize = 500 | |
11 | |
12 // ResultsSmallSize is the size that "results_small.json" should | |
13 // be trimmed to. | |
14 ResultsSmallSize = 100 | |
15 | |
16 runtimeThresholdNormal float64 = 3 | |
17 runtimeThresholdDebug float64 = 9 | |
18 ) | |
19 | |
20 func isDebugBuilder(builder string) bool { | |
21 for _, s := range []string{"debug", "dbg"} { | |
22 if strings.Contains(strings.ToLower(builder), s) { | |
23 return true | |
24 } | |
25 } | |
26 return false | |
27 } | |
28 | |
29 // Trim trims the leaves of Tests in ar to the specified size. | |
30 func (ar *AggregateResult) Trim(size int) error { | |
31 t := runtimeThresholdNormal | |
32 | |
33 if isDebugBuilder(ar.Builder) { | |
34 t = runtimeThresholdDebug | |
35 } | |
36 | |
37 return ar.Tests.trim(size, t) | |
38 } | |
39 | |
40 func (at AggregateTest) trim(size int, threshold float64) error { | |
41 for k, v := range at { | |
42 if leaf, ok := v.(*AggregateTestLeaf); ok { | |
43 leaf.trim(size) | |
44 if leaf.shouldDelete(threshold) { | |
45 delete(at, k) | |
46 } | |
47 continue | |
48 } | |
49 | |
50 child, ok := v.(AggregateTest) | |
51 if !ok { | |
52 return errors.New("model: trim: expected AggregateTest") | |
53 } | |
54 if err := child.trim(size, threshold); err != nil { | |
55 return err | |
56 } | |
57 if len(child) == 0 { | |
58 delete(at, k) | |
59 } | |
60 } | |
61 return nil | |
62 } | |
63 | |
64 func (leaf *AggregateTestLeaf) trim(size int) { | |
martiniss
2016/08/12 00:14:24
why is size an int here, but threshold is declared
nishanths
2016/08/12 02:37:40
threshold is a float because it is used to compare
| |
65 n := 0 | |
66 | |
67 for i, r := range leaf.Results { | |
68 leaf.Results[i].Count = min(r.Count, size) | |
69 n += r.Count | |
70 if n >= size { | |
71 leaf.Results = leaf.Results[:i+1] | |
72 break | |
73 } | |
74 } | |
75 | |
76 n = 0 | |
77 | |
78 for i, r := range leaf.Runtimes { | |
79 leaf.Runtimes[i].Count = min(r.Count, size) | |
80 n += r.Count | |
81 if n >= size { | |
82 leaf.Runtimes = leaf.Runtimes[:i+1] | |
83 break | |
84 } | |
85 } | |
86 } | |
87 | |
88 func min(a, b int) int { | |
89 if a < b { | |
90 return a | |
91 } | |
92 return b | |
93 } | |
94 | |
95 var deletableTypes = map[string]bool{"P": true, "N": true, "Y": true} | |
96 | |
97 func (leaf *AggregateTestLeaf) shouldDelete(threshold float64) bool { | |
98 if len(leaf.Expected) == 1 && leaf.Expected[0] != "PASS" { | |
99 return false | |
100 } | |
101 if leaf.Bugs != nil { | |
102 return false | |
103 } | |
104 | |
105 for _, r := range leaf.Results { | |
106 if !deletableTypes[r.Type] { | |
107 return false | |
108 } | |
109 } | |
110 for _, r := range leaf.Runtimes { | |
111 if r.Runtime >= threshold { | |
112 return false | |
113 } | |
114 } | |
115 | |
116 return true | |
117 } | |
OLD | NEW |