-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathvotingStatistics.js
More file actions
78 lines (68 loc) · 2.9 KB
/
Copy pathvotingStatistics.js
File metadata and controls
78 lines (68 loc) · 2.9 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
class VotingStatistics {
constructor() {
this.startedCreationTimestamp = new Date();
this.votes = [];
}
blockCreationLocalFinished() {
const timestamp = new Date();
this.localBlockCreationFinishedTimestamp = timestamp;
this.blockCreationLocalTime = timestamp - this.startedCreationTimestamp;
this.startedConsensusTimestamp = timestamp;
}
blockCreationResultsReceived() {
const timestamp = new Date();
this.resultsReceivedTimestamp = timestamp;
this.blockCreationTotalTime = timestamp - this.startedCreationTimestamp;
}
validationStarted() {
this.validationStartedTimestamp = new Date();
}
localValidationFinished() {
const timestamp = new Date();
this.localValidationFinishedTimestamp = timestamp;
this.validationLocalTime = timestamp - this.validationStartedTimestamp;
}
validationResultsReceived() {
const timestamp = new Date();
this.validationFinishedTimestamp = timestamp;
this.validationTotalTime = timestamp - this.validationStartedTimestamp;
}
consensusFinished() {
const timestamp = new Date();
this.consensusFinishTimestamp = timestamp;
this.consensusTotalTime = timestamp - this.startedConsensusTimestamp;
}
voteReceived(vote, node) {
this.votes.push({
'timestamp': new Date(),
node,
vote
});
}
getResults(numOfNodes) {
return {
'blockCreationLocalTime': this.blockCreationLocalTime,
'validationLocalTime': this.validationLocalTime,
'validationTotalTime': this.validationTotalTime,
'consensusTotalTime': this.consensusTotalTime,
'blockCreationTotalTime': this.blockCreationTotalTime,
'timeScale': 'ms',
'numberOfNodesInNetwork': numOfNodes,
'detailedTimestamps': {
'startedCreationTimestamp': prettyTimestamp(this.startedCreationTimestamp),
'localBlockCreationFinishedTimestamp': prettyTimestamp(this.localBlockCreationFinishedTimestamp),
'startedConsensusTimestamp': prettyTimestamp(this.startedConsensusTimestamp),
'validationStartedTimestamp': prettyTimestamp(this.validationStartedTimestamp),
'localValidationFinishedTimestamp': prettyTimestamp(this.localValidationFinishedTimestamp),
'consensusFinishTimestamp': prettyTimestamp(this.consensusFinishTimestamp),
'validationFinishedTimestamp': prettyTimestamp(this.validationFinishedTimestamp),
'resultsReceivedTimestamp': prettyTimestamp(this.resultsReceivedTimestamp),
'receivedVotesTimestamps': this.votes
}
}
}
}
function prettyTimestamp(ts) {
return ts.toISOString().replace('T', ' ').replace('Z', '');
}
module.exports = VotingStatistics