Skip to main content
Version: Next

Querying History

From a screen

ComponentUse
HmiTrendChartLive trend of one or more tags, with a rolling window
HistorianHistorical chart with time-range controls and statistics
Sparkline / HmiSparklineA value's recent shape, inline

Bind the tag list and the chart does the rest — window selection, downsampling and aggregation are handled server-side.

From a script

Python
data = system.hist.getTrends(
["Line1/Filler/Motor1/Speed", "Line1/Filler/Motor1/Current"],
"2026-08-01T00:00:00Z",
"2026-08-02T00:00:00Z",
maxPoints=500,
agg="avg",
)
JavaScript
const data = await system.hist.getTrends(
["Line1/Filler/Motor1/Speed"],
start, end, 500, "minmax",
);
ParameterMeaning
pathsTag paths
start, endISO-8601 timestamps
maxPointsDownsample target — the server aggregates to about this many points
aggavg or minmax

Aggregation

ModeKeepsUse for
avgThe mean per bucketSmooth analogue trends — temperature, pressure, level
minmaxThe extremes per bucketAnything where spikes matter — current, vibration, pressure transients

avg hides spikes. A 200 ms current spike averaged into a one-minute bucket disappears completely. If the excursion is the reason you are looking, use minmax.

Always set maxPoints

A day of one-second data is 86,400 points per tag. A chart 1,200 pixels wide can draw about 1,200. Transferring the rest costs bandwidth, browser memory and render time, and shows nothing.

WindowA sensible maxPoints
Last hour300–600
Last day500–1,000
Last week1,000–2,000
Last month1,000–2,000

The server aggregates down to your target using the rollup where appropriate, so a long window does not mean a slow query.

Statistics

Range-mode statistics give the per-tag summary shown beside a chart when a date range is selected:

StatisticNotes
min / maxExtremal
first / lastFrom the outermost part of the window that has data
count / sumAdditive
avgReconstructed exactly, not averaged
variance, standard deviationReconstructed exactly from (Σx², Σx, n)

That last point matters across epochs. An average of averages is wrong whenever the parts hold different sample counts, and a mean of variances is meaningless — so QUBIQ recombines from the underlying sums instead. The same decomposition is what the rollup materialises.

Live versus range mode

ModeBehaviour
LiveA rolling window that follows now; new samples push in. Shows the instantaneous current value.
RangeA fixed window. Shows aggregate statistics for the window.

In live mode, the live tail buffer merges the most recent in-memory samples into the result, so the chart's leading edge is genuinely live despite QuestDB's batched flush.

Performance

SymptomCauseFix
Slow long-range queryReading the base table instead of the rollupRebuild the rollup if stale
Slow query on any rangeToo many tags at onceSplit across charts, or reduce the series
Browser sluggish after loading a chartmaxPoints too highLower it
Trend has gapsDeadband too large, or the source was downCompare against connection health for the period
Trend flat-lines then jumpsStore interval absent on a slow-moving tagSet a store interval
Trend stops at a date in the pastAn epoch boundary with a retired storeCheck the historian's epochs

Interpreting a trend honestly

  • A deadband means the stored trend is not the raw signal. That is intended, but know the deadband before drawing conclusions about noise.
  • avg aggregation smooths. Switch to minmax before concluding an excursion did not happen.
  • A gap can be missing data or a genuinely static value. A store interval removes the ambiguity.
  • Bad-quality periods are not the same as zero. Check quality alongside value when a trend drops to nothing.

Exporting history

For reports and analysis outside QUBIQ:

  • A Gateway script that queries system.hist.getTrends, formats the result and writes it with system.files.save — then hands the URL to a screen or a notification.
  • A pipeline on a schedule doing the same and pushing to an external system.
  • Direct SQL against QuestDB via a named query, for tools that speak Postgres wire.

Gateway scripts

Next

Security