Created
November 27, 2019 05:11
-
-
Save awave1/2b013a6c6a6b005b5ed9e4e6939a76b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const fs = require('fs'); | |
/** | |
* Simple script to generate random data for our mongodb | |
* example: | |
* node generate.js <topic_name> <min> <max> <numEntries> | |
* | |
* # or | |
* | |
* node generate.js <topic_name> <min> <max> <numEntries> true # this will round up the data results | |
* | |
* result of the script is written to a file: <topic>.sample.json | |
*/ | |
// takes in min, max and a bool to round the data | |
// returns a rand int in the specified range | |
const rand = (min, max, round = false) => | |
round | |
? Math.floor(Math.random() * (max - min) + min) | |
: Math.random() * (max - min) + min; | |
const data = []; | |
const topic = process.argv[2]; | |
const min = process.argv[3]; | |
const max = process.argv[4]; | |
const numEntries = process.argv[5]; | |
const round = process.argv[6] && process.argv[5] === 'true'; | |
for (let i = 0; i < numEntries; i++) { | |
data.push({ | |
topic, | |
data: [rand(min, max)], | |
}); | |
} | |
fs.writeFileSync(`${topic}.sample.json`, JSON.stringify(data)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment