npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fake-time-series

v1.1.0

Published

A flexible CLI tool and library for generating fake time series data. Perfect for testing, development, and demonstration purposes.

Downloads

199

Readme

⏲️ fake-time-series

A flexible CLI tool and library for generating fake time series data. Perfect for testing, development, and demonstration purposes.

  • ✅ Generate realistic time series data with customizable data shapes.
  • ✅ Support for human-readable time ranges like "3 days ago" or "1 year ago" or "2024-6-30"
  • ✅ Send data to HTTP endpoints.
  • ✅ Fine-grained control over data generation with batch size and interval settings
  • ✅ Built-in randomization features for more realistic data patterns.
  • ✅ Simple configuration via JavaScript/ESM config files.

📡 Installation

npm install fake-time-series

yarn add fake-time-series

pnpm add fake-time-series

👋 Hello there! Follow me @linesofcode or visit linesofcode.dev for more cool projects like this one.

🚀 Getting Started

fake-time-series generate --startTime "1 week ago" --endTime "1 day ago"

Send generated data to an endpoint:

fake-time-series send --sink-url "http://localhost:3000/api/ingest" --startTime "3 months ago" --endTime "1 month ago"

🛠️ Configuration

Config File

The tool supports configuration through a JavaScript/ESM config file. By default, it looks for fake-time-series.config.mjs in the current directory.

A sample config file:

// fake-time-series.config.mjs
export const options = {
  startTime: "3 weeks ago",
  minInterval: "5s",
  maxInterval: "30s",
  maxBatchSize: 20,
  sinkUrl: "http://localhost:3000/api/ingest",
  headers: {
    "Authorization": "Bearer your-token",
    "Content-Type": "application/json"
  },
  shapes: {
		temperature: () => ({
			sensorId: Math.random().toString(36).substring(2, 15),
			value: Math.random() * 100,
		}),
	},
};

Shapes

Shapes are functions that return a data point. They can be used to generate realistic data for your specific use case.

Each shape function is identified by a key in the shapes object in the config file. Each shape function accepts the current timestamp and returns a data point, this can be a single value or a more complex object.

For example, the following shape function generates a random temperature value between 0 and 100 for a given timestamp:

// fake-time-series.config.mjs
export const config = {
	shapes: {
		temperature: (timestamp) => ({
			sensorId: Math.random().toString(36).substring(2, 15),
			value: Math.random() * 100,
		}),
	},
};

Specify a custom config path:

fake-time-series generate --config ./custom-config.mjs

Time Formats

The tool supports various time formats for startTime and endTime:

Relative Times

  • Simple offsets: -1 day, -30 minutes, -12 hours, -1 week, 1 day ago, 30 minutes ago
  • Multiple units: -1 day 6 hours, -2 weeks 3 days, 1 week 2 days ago
  • Special keywords: now, today, yesterday

Absolute Times

  • ISO 8601: 2024-01-15T10:30:00Z
  • Date strings: 2024-01-15, 15-01-2024
  • Time with timezone: 2024-01-15T10:30:00-05:00

Interval Formats

For minInterval and maxInterval:

  • Seconds: 5s, 30s
  • Minutes: 1m, 5m
  • Hours: 1h, 12h
  • Days: 1d
  • Milliseconds: 1234567890

🔧 Options

| Option | Description | Default | |--------|-------------|---------| | startTime | Start time of the series | -1 day | | endTime | End time of the series | now | | minInterval | Minimum interval between points | 1s | | maxInterval | Maximum interval between points | 10s | | maxBatchSize | Maximum points per batch | 10 | | batchSizeRandomization | Enable random batch sizes | true | | intervalRandomization | Enable random intervals | true | | batchReverseProbability | Chance to reverse batch order | 0.5 | | batchShuffleProbability | Chance to shuffle batch | 0.4 | | intervalSkewProbability | Chance of interval skewing | 0.8 | | concurrency | Max concurrent requests (send only) | 10 | | sinkUrl | Endpoint URL (send only) | required | | headers | Request headers (send only) | {"Content-Type": "application/json"} |

Examples

Generate data for the last 3 days:

fake-time-series generate --startTime "-3 days"

Generate data with specific intervals:

fake-time-series generate --minInterval "30s" --maxInterval "5m"

Send data with custom headers:

fake-time-series send \
  --sink-url "http://localhost:3000/api/ingest" \
  --headers '{"Authorization": "Bearer token123"}'