-
Notifications
You must be signed in to change notification settings - Fork 472
Expand file tree
/
Copy pathComponentStatistics.vue
More file actions
240 lines (198 loc) · 6.56 KB
/
Copy pathComponentStatistics.vue
File metadata and controls
240 lines (198 loc) · 6.56 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<template>
<v-container fluid>
<v-col>
<v-row class="ma-0 mb-4">
<h3 class="title text-primary">
<v-btn
color="primary"
variant="outlined"
@click="downloadCSV"
>
Export CSV
</v-btn>
<v-btn
icon="mdi-refresh"
title="Reload statistics"
color="primary"
variant="text"
@click="fetchStatistics"
/>
</h3>
</v-row>
<v-row class="ma-0 mb-6">
<v-col
cols="12"
class="pa-0"
>
<component-statistics-table
:items="statistics"
:loading="loading"
:filters="statisticsFilters"
/>
</v-col>
<unique-stat-warning v-if="baseStats.reportFilter.value.isUnique" />
</v-row>
</v-col>
</v-container>
</template>
<script setup>
import { ref } from "vue";
import { useBaseStatistics } from "@/composables/useBaseStatistics";
import { useToCSV } from "@/composables/useToCSV";
import {
CompareData,
DiffType,
ReportFilter
} from "@cc/report-server-types";
import {
UniqueStatWarning,
getComponents,
initDiffField
} from "@/components/Statistics";
import {
getComponentStatistics
} from "@/components/Statistics/StatisticsHelper";
import ComponentStatisticsTable from "./ComponentStatisticsTable";
const props = defineProps({
bus: { type: Object, required: true },
namespace: { type: String, required: true }
});
const csv = useToCSV();
const baseStats = useBaseStatistics(props, null);
const loading = ref(false);
const statistics = ref([]);
const components = ref([]);
const statisticsFilters = ref({});
const fieldsToUpdate = [ "reports", "unreviewed", "confirmed",
"falsePositive", "intentional" ];
baseStats.setupRefreshListener(fetchStatistics);
function downloadCSV() {
const _data = [
[
"Component", "Unreviewed", "Confirmed bug",
"Outstanding reports (Unreviewed + Confirmed)", "False positive",
"Intentional", "Suppressed reports (False positive + Intentional)",
"All reports"
],
...statistics.value.map(_stat => {
return [
_stat.component, _stat.unreviewed.count, _stat.confirmed.count,
_stat.outstanding.count, _stat.falsePositive.count,
_stat.intentional.count, _stat.suppressed.count, _stat.reports.count
];
})
];
csv.toCSV(_data, "codechecker_component_statistics.csv");
}
function updateCalculatedFields(oldValues, newValues, type) {
if (oldValues["outstanding"] !== undefined) {
oldValues["outstanding"][type] =
newValues["unreviewed"].count + newValues["confirmed"].count;
}
if (oldValues["suppressed"] !== undefined) {
oldValues["suppressed"][type] =
newValues["falsePositive"].count + newValues["intentional"].count;
}
}
async function fetchDifference() {
if (!baseStats.cmpData.value) return;
return Promise.all(components.value.map(_component => {
const _q1 = getNewReports(_component).then(_newReports => {
const _row = statistics.value.find(_s =>
_s.component === _component.name);
if (_row) {
fieldsToUpdate.forEach(_f => _row[_f].new = _newReports[_f].count);
updateCalculatedFields(_row, _newReports, "new");
}
});
const _q2 = getResolvedReports(_component).then(_resolvedReports => {
const _row = statistics.value.find(_s =>
_s.component === _component.name);
if (_row) {
fieldsToUpdate.forEach(_f =>
_row[_f].resolved = _resolvedReports[_f].count);
updateCalculatedFields(_row, _resolvedReports, "resolved");
}
});
return Promise.all([ _q1, _q2 ]);
}));
}
function getNewReports(component) {
const _runIds = baseStats.runIds.value;
const _reportFilter = new ReportFilter(baseStats.reportFilter.value);
_reportFilter["componentNames"] = [ component.name ];
const _cmpData = new CompareData(baseStats.cmpData.value);
_cmpData.diffType = DiffType.NEW;
return getStatistics(component, _runIds, _reportFilter, _cmpData);
}
function getResolvedReports(component) {
const _runIds = baseStats.runIds.value;
const _reportFilter = new ReportFilter(baseStats.reportFilter.value);
_reportFilter["componentNames"] = [ component.name ];
const _cmpData = new CompareData(baseStats.cmpData.value);
_cmpData.diffType = DiffType.RESOLVED;
return getStatistics(component, _runIds, _reportFilter, _cmpData);
}
function initStatistics(components) {
statistics.value = components.map(_component => ({
component : _component.name,
value : _component.value || _component.description,
reports : initDiffField(undefined),
unreviewed : initDiffField(undefined),
confirmed : initDiffField(undefined),
outstanding : initDiffField(undefined),
falsePositive : initDiffField(undefined),
intentional : initDiffField(undefined),
suppressed : initDiffField(undefined)
}));
}
async function getStatistics(component, runIds, reportFilter, cmpData) {
const _res = await getComponentStatistics(component, runIds, reportFilter,
cmpData);
return {
component : component.name,
value : component.value || component.description,
reports : initDiffField(_res.reports),
unreviewed : initDiffField(_res.unreviewed),
confirmed : initDiffField(_res.confirmed),
outstanding : initDiffField(_res.outstanding),
falsePositive : initDiffField(_res.falsePositive),
intentional : initDiffField(_res.intentional),
suppressed : initDiffField(_res.suppressed)
};
}
async function fetchStatistics() {
loading.value = true;
statistics.value = [];
components.value = await getComponents();
initStatistics(components.value);
statisticsFilters.value = baseStats.getStatisticsFilters();
const {
runIds: _runIds,
reportFilter: _reportFilter,
cmpData: _cmpData
} = statisticsFilters.value;
const _queries = components.value.map(async _component => {
const _res = await getStatistics(_component, _runIds, _reportFilter,
_cmpData);
const _idx = statistics.value.findIndex(_s =>
_s.component === _component.name);
statistics.value[_idx] = {
..._res,
loading: false,
checkerStatistics: null
};
statistics.value = [ ...statistics.value ];
return statistics.value[_idx];
});
await Promise.all(_queries).then(_statistics =>
statistics.value = _statistics);
await fetchDifference();
loading.value = false;
}
</script>
<style lang="scss">
:deep(.v-data-table__expanded__content .v-card) {
padding: 10px;
}
</style>