@naturalcycles/nodejs-lib
Version:
Standard library for Node.js
49 lines • 1.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const js_lib_1 = require("@naturalcycles/js-lib");
const colors_1 = require("../../colors");
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 ? colors_1.boldWhite(name) + ': ' : ''}${colors_1.dimWhite(this.rows)} rows, ${colors_1.dimWhite(js_lib_1._hb(this.sizeBytes))} in ${colors_1.dimWhite(js_lib_1._ms(this.tookMillis))}`,
`${colors_1.dimWhite(this.rpsTotal + ' rows/sec')}`,
`${colors_1.dimWhite(js_lib_1._hb(this.avgBytesPerRow) + '/row')}`,
`${colors_1.dimWhite(js_lib_1._hb(this.bpsTotal) + '/sec')}`,
].join(', ');
}
}
exports.NDJsonStats = NDJsonStats;
//# sourceMappingURL=ndjson.model.js.map