forked from ipfs/public-gateway-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStats.ts
42 lines (37 loc) · 1.17 KB
/
Stats.ts
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
import type { Checker } from './Checker'
import { Tag } from './Tag'
import { UiComponent } from './UiComponent'
class Stats extends UiComponent {
gateways: HTMLDivElement
totals: HTMLDivElement
constructor (readonly parent: Checker) {
super(parent)
const statsElement = document.getElementById('checker.stats')
if (statsElement == null) {
throw new Error('Could not find element with Id "checker.stats"')
}
this.tag = Tag.fromElement(statsElement)
this.gateways = document.createElement('div')
this.gateways.textContent = '0/0 tested'
this.gateways.className = 'Gateways'
this.tag.append(this.gateways)
this.totals = document.createElement('div')
this.totals.textContent = '0 online'
this.totals.className = 'Totals'
this.tag.append(this.totals)
}
public update (): void {
let up = 0
let down = 0
for (const savedNode of this.parent.nodes) {
if (savedNode.status.up) {
up += 1
} else if (savedNode.status.down) {
down += 1
}
}
this.gateways.textContent = `${up + down}/${this.parent.nodes.length} tested`
this.totals.textContent = `${up} online`
}
}
export { Stats }