GithubHelp home page GithubHelp logo

datagen's Introduction

Avatar

Build Status Dependencies Status Coverage Status Published Version
npm Badge

DataGen

DataGen is a multi-process test data files generator.

This is handy when you want to generate large test data files (e.g. XMLs, JSONs, CSVs, etc), over multiple processes, utilising available CPU cores on your machine. It's also very easy to generate random numbers, dates, and strings as test data. You only need to create template files, no scripting involved.

Installation

npm install -g datagen 

Usage

Create example header, segment, and footer template files:

datagen init

Generate 8 data files containing 1 million segments in each file, written to data1 ... data8 output files, running over 8 processes, each process is used to generate 1 file:

datagen gen -s 1000000 -w 8 -o data

Limit the number of worker processes that can run concurrently to just 3:

datagen gen -s 1000000 -w 8 -m 3

Templates

DataGen uses three template files: header, segment, and footer. These templates are simple text files which are used to construct a data file in this format:

header
segment 1
segment 2
...
segment N (number of segments)
footer

Example header:

<?xml version="1.0" encoding="UTF-8"?>
<data>

Example segment:

<segment>
  <id>{gen_id}-{worker_id}-{segment_id}</id>
  <name>{first_name()} {last_name()}</name>
  <dob>{date('dd-mm-yyyy')}</dob>
</segment>

Example footer:

</data>

The above templates will generate an XML like this:

<?xml version="1.0" encoding="UTF-8"?>
<data>
<segment>
  <id>1-1-1</id>
  <name>Niels Bryant</name>
  <dob>12-08-1992</dob>
</segment>
<segment>
  <id>1-1-2</id>
  <name>John Bohr</name>
  <dob>01-11-1970</dob>
</segment>
...
</data>

Curly brackets in templates (e.g. JSON format) need to be escaped with double brackets:

{{ "id": "{gen_id}-{worker_id}-{segment_id}", "name": "{first_name()} {last_name()}", "dob": "{date('dd-mm-yyyy')}" }}

As for CSV, check out the example below.

Example header:

(Column1,Column2,Column3,Column4,Column5)
FirstName,LastName,Age,EmployeeNumber,DateJoint

Example segment:

john,Smith,{integer(18, 65)},{integer()},{date('yyyy-mm-dd', 2000, 2018)}

Footer is not required for CSV unless you ar using an ETL which my require a data record count.

Templates can contain the following parameters:

{gen_id}Unique to each datagen execution. Default value is master process PID, can be overridden via -i flag.
{worker_id}Unique to each worker. Value from 1 to number of workers.
{segment_id}Unique to each segment within the generated data file, repeated in each file. Value from 1 to number of segments. Not available in header and footer templates.
{integer()}Random integer.
{integer(100, 200)}Random integer between 100 and 200.
{float()}random float.
{float(1.23, 5.67)}Random float between 1.23 and 5.67 .
{date()}random date between 1970 and 2020 in ISO format.
{date('yyyy-mm-dd')}Random date between 1970 and 2020 in yyyy-mm-dd format.
Check out felixge/node-dateformat for more date formats.
{date(2000, 2010)}Random date between 2000 and 2010 in ISO format.
{date('yyyy-mm-dd', 2000, 2010)}Random date between 2000 and 2010 in yyyy-mm-dd format.
{select('apple', 'orange', ..., 'kiwi')}Select one item from the arguments. You can have as many arguments as you want.
{word()}Random word from Lorem Ipsum.
{word(3)}Random 3 words from Lorem Ipsum.
{first_name()}Random first name.
{last_name()}Random last name.
{email()}Random email address.
{phone()}Random phone number. Default format #### ####.
{phone('(###) ####-####')}Random phone number with a custom format. Each '#' will be replaced by a random number.

Screenshots

Command init Command gen with flags

Colophon

Developer's Guide

Build reports:

Articles:

datagen's People

Contributors

cliffano avatar rishidavda avatar

Stargazers

 avatar  avatar Andrew Ahearne avatar  avatar Ken Tanaka avatar  avatar Max avatar Tony Cesaro avatar  avatar Dan Reiland avatar Francois-Guillaume Ribreau avatar Desmond Morris avatar Jeff Webster avatar node-migrator-bot avatar Todd Bashor avatar Matthew Tole avatar Joël Galeran avatar Daniel Feies avatar James O'Reilly avatar Heinrich Goebl avatar  avatar  avatar James Jackson avatar  avatar Wojtek Gawroński avatar zach zhao avatar Erick Patrick avatar Erik avatar Crew Moss avatar Ilya Shaisultanov avatar Stepan Anchugov avatar Grant Lucas Muller avatar Don Park avatar Thomas Efer avatar  avatar Joohun, Maeng avatar Pierre Haufe avatar Chris Hamant avatar Michael Chen avatar Chee Aun avatar

Watchers

Takeshi Watanabe avatar tom zhou avatar  avatar James Cloos avatar Michaël Memeteau avatar Pakkun avatar  avatar

datagen's Issues

Flexible header/footer templates existence

Instead of forcing header and footer templates to always exist, it's better to allow some flexibility with the templates existence. Not everything needs header and footer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.