-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatistics.ts
More file actions
61 lines (51 loc) · 1.43 KB
/
statistics.ts
File metadata and controls
61 lines (51 loc) · 1.43 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
import set from "set-value";
import { CategoryListType } from "./index";
type TypeMetrics = {
[key: string]: {
"#": number;
Name: string;
Id: string;
Status: string;
Total: number;
Page: number;
};
};
export class StatisticsManager {
private stats: {
errors: Array<any>;
metrics: TypeMetrics;
};
constructor() {
this.stats = { errors: [], metrics: {} };
}
public addStatusUpdate(label: string, newStatus: string) {
const path = `${label}.Status`;
this.stats.metrics = set(this.stats.metrics, path, newStatus);
// set(this.stats.metrics, `${label}.Page`, this.stats.metrics[label].Page + 1);
}
public incrementPage(label: string) {
this.stats.metrics = set(this.stats.metrics, `${label}.Page`, this.stats.metrics[label].Page + 1);
}
public incrementCount(label: string, by: number) {
this.stats.metrics = set(this.stats.metrics, `${label}.Total`, this.stats.metrics[label].Total + by);
}
public addError(error) {
this.stats.errors.push(error);
}
public addCategory(index: number, category: CategoryListType) {
this.stats.metrics = set(this.stats.metrics, category.label, {
"#": index + 1,
Name: category.label,
Id: category.tag,
Status: "🔵 - Pending",
Total: 0,
Page: 0
});
}
public print(): TypeMetrics {
return this.stats.metrics;
}
public printErrors(): Array<any> {
return this.stats.errors;
}
}