Skip to content
Snippets Groups Projects
Commit b25bc9a7 authored by Mike Lynch's avatar Mike Lynch
Browse files

Improved random names

parent 9dd8fc27
Branches
Tags
No related merge requests found
......@@ -40,6 +40,8 @@ const path = require('path');
const uuidv4 = require('uuid/v4');
const ArgumentParser = require('argparse').ArgumentParser;
const VOCABULARIES = './vocabularies';
function randrange(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
......@@ -48,14 +50,24 @@ function randoms(n, fn) {
return Array(n).fill(0).map(fn);
}
function randname() {
return _.upperFirst(randdict());
async function loadsource(file) {
const text = await fs.readFile(file);
return text.toString().split("\n");
}
async function loadsourcedata(dir) {
const sourcedata = {};
sourcedata['surnames'] = await loadsource(path.join(dir, 'surname.txt'));
sourcedata['givennames'] = await loadsource(path.join(dir, 'givenname.txt'));
return sourcedata;
}
function randperson() {
function randperson(sourcedata) {
const honorific = _.sample(HONORIFICS);
const surname = randname();
const givenname = randname();
const surname = _.sample(sourcedata['surnames']);
const givenname = _.sample(sourcedata['givennames']);
const name = givenname + ' ' + surname;
const email = givenname + '.' + surname + '@' + EMAIL_DOMAIN;
const id = uuidv4();
......@@ -101,9 +113,9 @@ function randdatapub(keywords, people) {
}
function randdatapubs(n) {
function randdatapubs(n, sourcedata) {
const keywords = randoms(Math.floor(n / 2), randkeyword);
const people = randoms(n * 2, randperson);
const people = randoms(n * 2, () => { return randperson(sourcedata) });
return randoms(n, () => randdatapub(keywords, people))
}
......@@ -123,7 +135,8 @@ async function makedatacrate(dest, datapub) {
async function randomdatacrates(dest, n) {
const datapubs = randdatapubs(n);
const sourcedata = await loadsourcedata(VOCABULARIES);
const datapubs = randdatapubs(n, sourcedata);
Promise.all(
datapubs.map(async p => {
await makedatacrate(dest, p);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment