-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanalysis.js
64 lines (57 loc) · 1.29 KB
/
analysis.js
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
// @flow
import type { Metric } from './metrics';
export type AnalyzedResult = {
url: string,
level: number,
time: number,
message: string
};
export default class Analysis {
label: string;
date: Date;
metrics: Map<string, Metric>;
results: Array<AnalyzedResult>;
constructor(label: string, date: Date) {
this.label = label;
this.date = date;
this.metrics = new Map();
this.results = [];
}
/**
* Add a single metric to the analysis.
*
* @param key
* @param metric
*/
addMetric(key: string, metric: Metric) {
this.metrics.set(key, metric);
}
/**
* Add a single URL result to the analysis.
*
* @param url
* @param level
* @param time
* @param message
*/
addResult(url: string, level: number, time: number, message: string) {
this.results.push({
url,
level: level || 0,
time: time || 0,
message: message || 'Ok'
});
}
/**
* Check whether this analysis contains any failing results.
*
* @return {boolean}
*/
hasFailures(): boolean {
var failingResults = this.results.filter(r => r.level > 1);
var failingMetrics = Array.from(this.metrics).filter(
([name, metric]) => metric.level > 1
);
return failingResults.length > 0 || failingMetrics.length > 0;
}
}