@naturalcycles/nodejs-lib
Version:
Standard library for Node.js
50 lines • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const time_lib_1 = require("@naturalcycles/time-lib");
const __1 = require("../..");
const __2 = require("../..");
class NDJsonStats {
constructor() {
this.tookMillis = 0;
this.rows = 0;
this.sizeBytes = 0;
}
static create(o = {}) {
return Object.assign(new NDJsonStats(), o);
}
static empty() {
return new NDJsonStats();
}
static createCombined(stats) {
return stats.reduce((statsTotal, stats) => statsTotal.add(stats), new NDJsonStats());
}
get rpsTotal() {
return Math.round(this.rows / ((this.tookMillis || 1) / 1000));
}
get bpsTotal() {
return this.sizeBytes === 0 ? 0 : Math.round(this.sizeBytes / ((this.tookMillis || 1) / 1000));
}
get avgBytesPerRow() {
return Math.round(this.sizeBytes / this.rows);
}
/**
* Non-mutating addition, returns new object
*/
add(s) {
return NDJsonStats.create({
tookMillis: this.tookMillis + s.tookMillis,
rows: this.rows + s.rows,
sizeBytes: this.sizeBytes + s.sizeBytes,
});
}
toPretty(name) {
return [
`Processed ${name ? __2.boldWhite(name) + ': ' : ''}${__1.dimWhite(this.rows)} rows, ${__1.dimWhite(__1.hb(this.sizeBytes))} in ${__1.dimWhite(time_lib_1.ms(this.tookMillis))}`,
`${__1.dimWhite(this.rpsTotal + ' rows/sec')}`,
`${__1.dimWhite(__1.hb(this.avgBytesPerRow) + '/row')}`,
`${__1.dimWhite(__1.hb(this.bpsTotal) + '/sec')}`,
].join(', ');
}
}
exports.NDJsonStats = NDJsonStats;
//# sourceMappingURL=ndjson.model.js.map