| OLD | NEW |
| 1 package analysis | 1 package analysis |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "fmt" | 4 "fmt" |
| 5 | 5 |
| 6 "github.com/rcrowley/go-metrics" | 6 "github.com/rcrowley/go-metrics" |
| 7 "skia.googlesource.com/buildbot.git/golden/go/types" | 7 "skia.googlesource.com/buildbot.git/golden/go/types" |
| 8 ) | 8 ) |
| 9 | 9 |
| 10 const ( | 10 const ( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 // Number of untriaged digests in HEAD. | 46 // Number of untriaged digests in HEAD. |
| 47 UntriagedCount int `json:"untriagedCount"` | 47 UntriagedCount int `json:"untriagedCount"` |
| 48 | 48 |
| 49 // Number of negative digests in HEAD. | 49 // Number of negative digests in HEAD. |
| 50 NegativeCount int `json:"negativeCount"` | 50 NegativeCount int `json:"negativeCount"` |
| 51 } | 51 } |
| 52 | 52 |
| 53 // calcStatus determines the status based on the current tile. It breaks | 53 // calcStatus determines the status based on the current tile. It breaks |
| 54 // down the status by individual corpora. | 54 // down the status by individual corpora. |
| 55 func (a *Analyzer) calcStatus(labeledTile *LabeledTile) *GUIStatus { | 55 func calcStatus(state *AnalyzeState) *GUIStatus { |
| 56 » corpStatus := make(map[string]*GUICorpusStatus, len(a.currentIndex.corpo
ra)) | 56 » corpStatus := make(map[string]*GUICorpusStatus, len(state.Index.corpora)
) |
| 57 minCommitId := map[string]int{} | 57 minCommitId := map[string]int{} |
| 58 okByCorpus := map[string]bool{} | 58 okByCorpus := map[string]bool{} |
| 59 | 59 |
| 60 // Gathers unique labels by corpus and label. | 60 // Gathers unique labels by corpus and label. |
| 61 byCorpus := map[string]map[types.Label]map[string]bool{} | 61 byCorpus := map[string]map[types.Label]map[string]bool{} |
| 62 | 62 |
| 63 » for _, corpus := range a.currentIndex.corpora { | 63 » for _, corpus := range state.Index.corpora { |
| 64 » » minCommitId[corpus] = len(labeledTile.Commits) | 64 » » minCommitId[corpus] = len(state.Tile.Commits) |
| 65 okByCorpus[corpus] = true | 65 okByCorpus[corpus] = true |
| 66 byCorpus[corpus] = map[types.Label]map[string]bool{ | 66 byCorpus[corpus] = map[types.Label]map[string]bool{ |
| 67 types.POSITIVE: map[string]bool{}, | 67 types.POSITIVE: map[string]bool{}, |
| 68 types.NEGATIVE: map[string]bool{}, | 68 types.NEGATIVE: map[string]bool{}, |
| 69 types.UNTRIAGED: map[string]bool{}, | 69 types.UNTRIAGED: map[string]bool{}, |
| 70 } | 70 } |
| 71 if _, ok := corpusGauges[corpus]; !ok { | 71 if _, ok := corpusGauges[corpus]; !ok { |
| 72 corpusGauges[corpus] = map[types.Label]metrics.Gauge{ | 72 corpusGauges[corpus] = map[types.Label]metrics.Gauge{ |
| 73 types.UNTRIAGED: metrics.NewRegisteredGauge(fmt.
Sprintf(METRIC_CORPUS_TMPL, types.UNTRIAGED, corpus), nil), | 73 types.UNTRIAGED: metrics.NewRegisteredGauge(fmt.
Sprintf(METRIC_CORPUS_TMPL, types.UNTRIAGED, corpus), nil), |
| 74 types.POSITIVE: metrics.NewRegisteredGauge(fmt.
Sprintf(METRIC_CORPUS_TMPL, types.POSITIVE, corpus), nil), | 74 types.POSITIVE: metrics.NewRegisteredGauge(fmt.
Sprintf(METRIC_CORPUS_TMPL, types.POSITIVE, corpus), nil), |
| 75 types.NEGATIVE: metrics.NewRegisteredGauge(fmt.
Sprintf(METRIC_CORPUS_TMPL, types.NEGATIVE, corpus), nil), | 75 types.NEGATIVE: metrics.NewRegisteredGauge(fmt.
Sprintf(METRIC_CORPUS_TMPL, types.NEGATIVE, corpus), nil), |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Iterate over the current traces | 80 // Iterate over the current traces |
| 81 var idx int | 81 var idx int |
| 82 var corpus string | 82 var corpus string |
| 83 » for _, testTraces := range labeledTile.Traces { | 83 » for _, testTraces := range state.Tile.Traces { |
| 84 for _, trace := range testTraces { | 84 for _, trace := range testTraces { |
| 85 corpus = trace.Params[types.CORPUS_FIELD] | 85 corpus = trace.Params[types.CORPUS_FIELD] |
| 86 idx = len(trace.Labels) - 1 | 86 idx = len(trace.Labels) - 1 |
| 87 | 87 |
| 88 okByCorpus[corpus] = okByCorpus[corpus] && (trace.Labels
[idx] == types.POSITIVE) | 88 okByCorpus[corpus] = okByCorpus[corpus] && (trace.Labels
[idx] == types.POSITIVE) |
| 89 if trace.CommitIds[idx] < minCommitId[corpus] { | 89 if trace.CommitIds[idx] < minCommitId[corpus] { |
| 90 minCommitId[corpus] = trace.CommitIds[idx] | 90 minCommitId[corpus] = trace.CommitIds[idx] |
| 91 } | 91 } |
| 92 byCorpus[corpus][trace.Labels[idx]][trace.Digests[idx]]
= true | 92 byCorpus[corpus][trace.Labels[idx]][trace.Digests[idx]]
= true |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 overallOk := true | 96 overallOk := true |
| 97 allUntriagedCount := 0 | 97 allUntriagedCount := 0 |
| 98 allPositiveCount := 0 | 98 allPositiveCount := 0 |
| 99 allNegativeCount := 0 | 99 allNegativeCount := 0 |
| 100 » for _, corpus := range a.currentIndex.corpora { | 100 » for _, corpus := range state.Index.corpora { |
| 101 overallOk = overallOk && okByCorpus[corpus] | 101 overallOk = overallOk && okByCorpus[corpus] |
| 102 untriagedCount := len(byCorpus[corpus][types.UNTRIAGED]) | 102 untriagedCount := len(byCorpus[corpus][types.UNTRIAGED]) |
| 103 positiveCount := len(byCorpus[corpus][types.POSITIVE]) | 103 positiveCount := len(byCorpus[corpus][types.POSITIVE]) |
| 104 negativeCount := len(byCorpus[corpus][types.NEGATIVE]) | 104 negativeCount := len(byCorpus[corpus][types.NEGATIVE]) |
| 105 corpStatus[corpus] = &GUICorpusStatus{ | 105 corpStatus[corpus] = &GUICorpusStatus{ |
| 106 OK: okByCorpus[corpus], | 106 OK: okByCorpus[corpus], |
| 107 » » » MinCommitHash: labeledTile.Commits[minCommitId[corpus]]
.Hash, | 107 » » » MinCommitHash: state.Tile.Commits[minCommitId[corpus]].
Hash, |
| 108 UntriagedCount: untriagedCount, | 108 UntriagedCount: untriagedCount, |
| 109 NegativeCount: negativeCount, | 109 NegativeCount: negativeCount, |
| 110 } | 110 } |
| 111 allUntriagedCount += untriagedCount | 111 allUntriagedCount += untriagedCount |
| 112 allNegativeCount += negativeCount | 112 allNegativeCount += negativeCount |
| 113 allPositiveCount += positiveCount | 113 allPositiveCount += positiveCount |
| 114 | 114 |
| 115 corpusGauges[corpus][types.POSITIVE].Update(int64(positiveCount)
) | 115 corpusGauges[corpus][types.POSITIVE].Update(int64(positiveCount)
) |
| 116 corpusGauges[corpus][types.NEGATIVE].Update(int64(negativeCount)
) | 116 corpusGauges[corpus][types.NEGATIVE].Update(int64(negativeCount)
) |
| 117 corpusGauges[corpus][types.UNTRIAGED].Update(int64(untriagedCoun
t)) | 117 corpusGauges[corpus][types.UNTRIAGED].Update(int64(untriagedCoun
t)) |
| 118 } | 118 } |
| 119 allUntriagedGauge.Update(int64(allUntriagedCount)) | 119 allUntriagedGauge.Update(int64(allUntriagedCount)) |
| 120 allPositiveGauge.Update(int64(allPositiveCount)) | 120 allPositiveGauge.Update(int64(allPositiveCount)) |
| 121 allNegativeGauge.Update(int64(allNegativeCount)) | 121 allNegativeGauge.Update(int64(allNegativeCount)) |
| 122 totalGauge.Update(int64(allUntriagedCount + allPositiveCount + allNegati
veCount)) | 122 totalGauge.Update(int64(allUntriagedCount + allPositiveCount + allNegati
veCount)) |
| 123 | 123 |
| 124 return &GUIStatus{ | 124 return &GUIStatus{ |
| 125 OK: overallOk, | 125 OK: overallOk, |
| 126 CorpStatus: corpStatus, | 126 CorpStatus: corpStatus, |
| 127 } | 127 } |
| 128 } | 128 } |
| OLD | NEW |