Programming · free software · the open webSubscribe via RSS

How Can a Sensor Reading Be Aggregated by Hour?

From the earlier reference collection. Read the current software blog.

An hourly summary depends on a stated time zone, interval boundary, and policy for uneven or missing samples.

Define the hour first

“By hour” can refer to clock hours in a local time zone or fixed one-hour spans on a timeline. State which convention is used before grouping observations. A local hour can be affected by daylight-saving transitions, when a clock hour may be skipped or repeated; a fixed-time-zone grouping avoids that ambiguity but may not match a reader’s local clock.

Also specify whether an interval is labeled by its start or end. A clear convention might define the interval from 10:00 inclusive to 11:00 exclusive and label it “10:00.” The boundary rule ensures that a reading exactly at 11:00 belongs to only one group.

Choose an aggregation method

The arithmetic mean is easy to calculate, but it gives every included sample equal weight. That is appropriate when samples are regularly spaced and the goal is to summarize those observations. If readings arrive irregularly, a cluster of samples in one short part of the hour can dominate the mean even though it represents little elapsed time.

Suppose a sensor records at 10:05, 10:10, and 10:55. An ordinary mean treats all three measurements equally, while a time-weighted method gives more influence to conditions that persisted across longer intervals. Neither is universally right. Pick the method that matches the measurement process and explain it alongside the result.

Handle coverage explicitly

An hourly value should not conceal how many observations support it. Include a sample count or coverage indicator, and define what happens when the hour contains no records. Returning a missing value is often clearer than carrying the prior hour forward without an explicit estimate label.

If the expected cadence is regular, you can define a minimum coverage rule—for example, require a stated number of valid samples before publishing a mean. Set that rule from the data’s collection design rather than choosing a threshold after seeing which answer looks best.

Preserve enough detail to reproduce it

Keep raw timestamps and values available, and record the time zone, interval convention, aggregation method, quality filtering, and coverage rule. A reader should be able to understand why a dashboard’s 10:00 summary differs from a summary calculated with different boundaries or weights.

Hourly aggregation is a transformation, not a property of the original sensor reading. Make its assumptions visible so that the summary remains useful and reproducible.

Suggest a correction · All posts