Lattice Grid Buy a licence

demo D236

Approximate figures, with the error bound shown

A constant-time estimate next to the figure it stands for, and the average over just the last few thousand readings

grid.statistics.maintenanceTier(fn) · windowed(col, fn, { kind, span })

Building…
Loading a live grid…

The configuration

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.28.0/lattice-grid.min.css">

<script type="module">
  import { defineLatticeGrid } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.28.0/modules/webcomponent.esm.js';
  defineLatticeGrid();
</script>

<lattice-grid row-key="id" style="display: block; height: 460px"></lattice-grid>
<pre id="out" style="margin-top: 12px"></pre>

<script type="module">
  const el = document.querySelector('lattice-grid');
  el.config = {
    toolPanel: { side: 'left', panels: ['filters', 'columns'] },
    columns: [
      { field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
      { field: 'desk', title: 'Desk', filter: { type: 'set' } },
      { field: 'price', title: 'Price', type: 'number' },
      { field: 'bid', title: 'Bid', type: 'number' },
      { field: 'volume', title: 'Volume', type: 'number' },
      { field: 'notional', title: 'Notional', type: 'number',
        format: { style: 'currency', currency: 'USD' }, total: 'sum' },
    ],
  };
  el.rows = rows;  // trading book records

  // el.grid is the live grid inside the element. The statistics API reads the
  // filtered rows, so every figure follows the filters. Recompute on change.
  const grid = el.grid;
  const out = document.getElementById('out');
  const report = () => {
    // maintenanceTier names how each reduction is computed, and the sketch and
    // stated error bound that would stand in for it on a very large stream.
    const tier = grid.statistics.maintenanceTier('distinct');
    // windowed reads a figure over just the most recent readings, and states
    // the window it covered: here the mean over the last 2,000, not all history.
    const recent = grid.statistics.windowed('price', 'avg', { kind: 'count', span: 2000 });
    out.textContent = JSON.stringify({ tier, recent }, null, 2);
  };
  grid.on('filter:changed', report);  // every figure follows the filters
  report();
</script>

Knowing what a figure actually costs, and what a shortcut would promise instead

A totals row over a large or fast-moving dataset can compute something like a distinct count or a p99 two ways: recompute it exactly on every read, or maintain an approximate version cheaply and say plainly what error bound it carries. Lattice Grid never swaps one in for the other silently; instead grid.statistics.maintenanceTier(fn) tells you, for any reduction, which of three honest positions it is actually in: exact, maintained (a running total that costs nothing extra per read, like a sum or an average), exact, rescan (correct, but a full pass over the data every time it is read, like a median or a percentile), or an approximate alternative with a named sketch and a stated bound, such as HyperLogLog for a distinct count or KLL for a quantile. grid.statistics.approximate is the same information as a lookup table, keyed by reduction name, each entry naming the sketch behind it and the bound it is verified to meet. The point of surfacing this rather than picking a tier for you is that “approximate” without a stated bound is just a wrong answer with better manners; a sketch that ships here is one this codebase runs against a real stream and asserts sits inside the bound it claims, so a figure with an error bound printed next to it is a claim you can check, not a disclaimer.

What is the difference between an exact and an approximate statistic in a data grid?

An exact reduction, whether maintained incrementally or recomputed on read, always matches a full pass over the data. An approximate one, backed by a sketch such as HyperLogLog or KLL, trades a small, stated error for constant memory and constant-time updates on a live or very large dataset. grid.statistics.maintenanceTier(fn) tells you which tier a given reduction is in and names the bound when an approximate form exists, so the choice is visible rather than buried in an implementation.

What is a stated error bound, and why does it matter?

A stated error bound is a specific, checkable claim: a HyperLogLog distinct count promises a standard error tied to its configured precision; a KLL quantile promises the true rank of the returned value is within a stated fraction of the requested rank. Reporting an approximate figure without that bound leaves a reader unable to tell a close estimate from a wrong one. Lattice Grid keeps the bound attached to the figure’s tier information specifically so an approximate result is never presented as an unqualified number.

Reading a figure over just the most recent readings, not the whole history

Over a long or fast-moving column, the figure over everything and the figure lately are different questions, and the average since the start hides a shift that only started an hour ago. grid.statistics.windowed(col, fn, { kind, span }) answers the second one: it reduces a column over a window of the recent readings rather than the whole set, and returns both the value and the window it covers so the answer states its own scope. A count window keeps the last N readings, a time window keeps the last so many minutes, and a session window covers the run so far, each stamping the result with the size of the window behind it. Like every statistic here it reads the filtered rows, so narrowing the grid narrows the window with it. The figure is exact over the readings in the window, so “the mean over the last few thousand” is a precise answer to a smaller question, not an estimate.

What is a windowed statistic in a data grid?

A windowed statistic reduces a column over a moving window of recent readings rather than the entire column. grid.statistics.windowed('price', 'avg', { kind: 'count', span: 2000 }) returns the mean over the last two thousand readings and states the window it covered, so a recent shift shows through instead of being averaged away across all of history. The window can be a count of readings, a span of time, or the whole session, and it follows the grid’s filters like any other figure.