2019-05-06 14:12:53 +03:00
|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
|
|
|
const ndjson = require('ndjson')
|
|
|
|
const { mean, median, min, max } = require('simple-statistics')
|
|
|
|
|
|
|
|
const readFile = (...paths) => {
|
|
|
|
const a = []
|
|
|
|
const filename = path.join(...paths)
|
|
|
|
return new Promise(resolve => {
|
|
|
|
fs.createReadStream(filename)
|
|
|
|
.pipe(ndjson.parse())
|
|
|
|
.on('data', obj => a.push(obj))
|
|
|
|
.on('end', () => resolve(a))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function computeSignatureRequestStats(signatureRequests, senderHome) {
|
|
|
|
const processingLogs = signatureRequests.filter(x => x.eventTransactionHash)
|
2019-05-25 14:27:52 +03:00
|
|
|
const txSentMap = senderHome.filter(x => x.eventTransactionHash).reduce((acc, x) => {
|
|
|
|
acc[x.eventTransactionHash] = x
|
|
|
|
return acc
|
|
|
|
}, {})
|
2019-05-06 14:12:53 +03:00
|
|
|
|
|
|
|
const times = processingLogs.map(x => txSentMap[x.eventTransactionHash].time - x.time)
|
|
|
|
|
|
|
|
return {
|
|
|
|
count: times.length,
|
|
|
|
mean: mean(times),
|
|
|
|
median: median(times),
|
|
|
|
min: min(times),
|
|
|
|
max: max(times)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function computeCollectedSignaturesStats(collectedSignatures, senderForeign) {
|
|
|
|
const processingLogs = collectedSignatures.filter(x => x.eventTransactionHash)
|
2019-05-25 14:27:52 +03:00
|
|
|
const txSentMap = senderForeign.filter(x => x.eventTransactionHash).reduce((acc, x) => {
|
|
|
|
acc[x.eventTransactionHash] = x
|
|
|
|
return acc
|
|
|
|
}, {})
|
2019-05-06 14:12:53 +03:00
|
|
|
|
|
|
|
const times = processingLogs.map(x => txSentMap[x.eventTransactionHash].time - x.time)
|
|
|
|
|
|
|
|
return {
|
|
|
|
count: times.length,
|
|
|
|
mean: mean(times),
|
|
|
|
median: median(times),
|
|
|
|
min: min(times),
|
|
|
|
max: max(times)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const signatureRequests = await readFile(__dirname, '../logs/signature-request-watcher.txt')
|
|
|
|
const collectedSignatures = await readFile(__dirname, '../logs/collected-signatures-watcher.txt')
|
|
|
|
// const affirmationRequests = await readFile(__dirname, '../logs/affirmation-request-watcher.txt')
|
|
|
|
const senderHome = await readFile(__dirname, '../logs/home-sender.txt')
|
|
|
|
const senderForeign = await readFile(__dirname, '../logs/foreign-sender.txt')
|
|
|
|
|
|
|
|
const signatureRequestsStats = computeSignatureRequestStats(signatureRequests, senderHome)
|
|
|
|
console.log('Signature Requests')
|
|
|
|
console.log(signatureRequestsStats)
|
|
|
|
|
2019-08-01 16:10:22 +03:00
|
|
|
const collectedSignaturesStats = computeCollectedSignaturesStats(collectedSignatures, senderForeign)
|
2019-05-06 14:12:53 +03:00
|
|
|
console.log('Collected Signatures')
|
|
|
|
console.log(collectedSignaturesStats)
|
|
|
|
}
|
|
|
|
|
|
|
|
main().catch(console.error)
|