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 🙏

© 2026 – Pkg Stats / Ryan Hefner

hyperdb-downsampling

v1.0.5

Published

Time series downsampling with d3. Multi-resolution tiered aggregation for displaying recent data in full detail and older data progressively compressed.

Downloads

463

Readme

hyperdb-downsampling

Tiered time series downsampling for HyperDB using d3. Show recent data in full detail, older data progressively aggregated.

Install

npm install hyperdb-downsampling

Usage

import { downsample } from 'hyperdb-downsampling'

Simple downsampling

Aggregate all data into hourly averages:

const result = downsample(data, {
  field: 'value',
  tiers: [
    { label: 'hourly', to: Infinity, interval: 'hour' }
  ]
})

Tiered downsampling

Show raw data for the last 10 seconds, 10-second averages up to 1 minute, and minute averages up to 5 minutes:

const result = downsample(data, {
  field: 'value',
  tiers: [
    { label: 'raw', to: 10_000 },
    { label: '10s_avg', from: 10_000, to: 60_000, interval: '10s' },
    { label: '1min_avg', from: 60_000, to: 300_000, interval: 'minute' },
  ]
})

Custom aggregation

Each tier defaults to mean, but you can choose min, max, median, or sum:

const result = downsample(data, {
  field: 'value',
  tiers: [
    { label: 'raw', to: 10_000 },
    { label: '10s_max', from: 10_000, to: 60_000, interval: '10s', aggregate: 'max' },
    { label: '1min_min', from: 60_000, to: 300_000, interval: 'minute', aggregate: 'min' },
  ]
})

API

downsample(data, options)

data — Array of objects with a timestamp field and one or more numeric fields.

options:

| Option | Type | Default | Description | |--------|------|---------|-------------| | field | string | — | The numeric field to aggregate | | tiers | Tier[] | — | Array of tier configurations | | timestampField | string | 'timestamp' | Name of the timestamp field |

Tier configuration:

| Option | Type | Default | Description | |--------|------|---------|-------------| | label | string | — | Name for this tier (included in output) | | from | number | 0 | Min age in ms (inclusive) | | to | number | — | Max age in ms (exclusive) | | interval | string | — | Aggregation interval. Omit for raw data | | aggregate | string | 'mean' | One of mean, min, max, median, sum |

Available intervals: 5s, 10s, 30s, second, minute, hour, day, week, month

Output

Returns a sorted array of objects:

[
  { date: Date, value: 14.2, tier: 'raw' },
  { date: Date, value: 15.1, tier: '10s_avg' },
  { date: Date, value: 14.8, tier: '1min_avg' },
]

Example with HyperDB

import { downsample } from 'hyperdb-downsample'

const all = await db.find('@collection/readings').toArray()

const result = downsample(all, {
  field: 'value',
  tiers: [
    { label: 'raw', to: 10_000 },
    { label: '10s_avg', from: 10_000, to: 60_000, interval: '10s' },
    { label: '1min_avg', from: 60_000, to: 300_000, interval: 'minute' },
  ]
})

License

ISC