The Difficulties of Generating Fake Data

Background

The majority of the applications I work on focus on distilling the complexities of data into simple interfaces. This was the crux of my work with LRE Water and is even more so with my new company Stae. Many different types and structures of data are needed to adequetly test dashboards and data visualizations. For ease of development, I often generate fake datasets.

In the past, I have relied on Google Sheets and a combination of array formulas, vlookups, random value generators to create fake datasets. This approach worked for small, one off datasets. Any time I needed to generate more than 1000 records or needed to update a dataset, this approach proved to be tedious. I also explored Faker and Casual (both of which are fantastic tools) but found that the data they generate was too abstract and that the implementation wasn't ideal for large datasets. I wanted a tool that:

  • makes it easy to generate realistic fake datasets of any size,
  • is highly configurable,
  • makes updating a dataset trivial,
  • outputs the data in a format that is easy to work with.

To solve this issue, I started developing Data Spring and the associated CLI.

Case Study

Let's say we are developing a dashboard for visualizing a state government's daily spending by department over the past 5 years. The dataset has the following requirements:

  1. Multiple spending values are needed for each day for each department over the last 5 years
  2. We need to be able specifiy a realistic list of departments that data will be generated for.
  3. The spending values need to be within a realistic range
  4. Needs to be output in JSON format.

The data structure should be as follows:

1
[
2
{
3
"date": "2020-01-01T08:00:00.007Z",
4
"department": "Transportation",
5
"spending": 10000
6
},
7
...many more records
8
]
9

The Google Sheet Approach

The dataset is relatively simple but still tedious to generate. Using Google Sheets, we would need to implement some sort of date step interval logic for the date field, randomly select a department using a combination of a random number and vlookup, and then generate a random number between our thresholds. Then we would need to copy our formulas down thousands of rows or use an array formula and deal with the incredibly slow resulting spreadsheet. Lastly, we would need to download the spreadsheet as a CSV and then convert it to JSON.

The same scenario with Data Spring

Data Spring is a config based data generator, meaning you define the desired shape of your data using an object or a JSON config file. To create the dataset in the case study you would do the following.

1
import { DataSpring } from "data-spring"
2
3
const config = [
4
{ id: "record_id", type: "id" },
5
{
6
id: "date",
7
type: "date",
8
interval: "hour",
9
min: "2015-01-01 00:00:00",
10
max: "2020-12-31 00:00:00",
11
},
12
{
13
id: "department",
14
type: "string",
15
values: ["Transportation", "Environment", "Public Health", "Parks and Rec"],
16
},
17
{
18
id: "spending",
19
type: "number",
20
min: 5000,
21
max: 100000,
22
},
23
]
24
25
const dataset = DataSpring(Config)
26

Pretty simple huh? If you realized you forgot to add a department or that the spending range was wrong, it is as easy as updating the config variable.

Wrapping up

This was a pretty contrived example but hopefully it demonstrated how Data Spring can be used to easily generate fake datasets. If you have feedback or comments, please reach out below.

Useful Links

Interested in working together?

Drop me a line
© 2020 Lost Creek Designs