├── .gitignore ├── cli.js ├── package.json ├── readme.md └── test.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | var streamStatistics = require('stream-statistics') 3 | var ndjson = require('ndjson') 4 | 5 | process.stdin 6 | .pipe(ndjson.parse()) 7 | .pipe(streamStatistics()) 8 | .pipe(ndjson.serialize()) 9 | .pipe(process.stdout) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jsonstats", 3 | "version": "1.0.0", 4 | "description": "cli for ndjson based streaming summary statistics on numbers", 5 | "main": "index.js", 6 | "bin": { 7 | "jsonstats": "cli.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/maxogden/jsonstats.git" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "BSD-2-Clause", 16 | "bugs": { 17 | "url": "https://github.com/maxogden/jsonstats/issues" 18 | }, 19 | "homepage": "https://github.com/maxogden/jsonstats#readme", 20 | "dependencies": { 21 | "ndjson": "^1.5.0", 22 | "stream-statistics": "^0.4.0" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # jsonstats 2 | 3 | install with `npm i jsonstats -g` 4 | 5 | pipe [ndjson](https://npmjs.org/ndjson) numbers into `jsonstats` and you'll get summary statistics on `stdout` when the stream is done 6 | 7 | ## example 8 | 9 | ``` 10 | ~/src/js/jsonstats 🐈 cat test.json | jsonfilter num | jsonstats 11 | {"max":4,"min":1,"n":4,"_geometric_mean":24,"_reciprocal_sum":2.083333333333333,"mean":2.5,"ss":5,"sum":10,"_seen_this":1,"_mode":1,"_mode_valid":true,"variance":1.25,"standard_deviation":1.118033988749895,"geometric_mean":2.2133638394006434,"harmonic_mean":1.9200000000000004,"mode":1,"_max_seen":1,"_last":4} 12 | ``` -------------------------------------------------------------------------------- /test.json: -------------------------------------------------------------------------------- 1 | {"num": 1} 2 | {"num": 2} 3 | {"num": 3} 4 | {"num": 4} --------------------------------------------------------------------------------