Documentation
¶
Overview ¶
Package speedstat computes speed distribution statistics (histogram and weighted percentiles) over a GPX track.
Raw point-to-point speed is noisy at poor GPS signal: short time/distance deltas between jittery fixes produce implausible spikes. Samples merges consecutive points until both a minimum duration and a minimum distance are reached before trusting their speed, optionally skipping points with a bad HDOP fix. This keeps every meter and every second accounted for (merged, never dropped), so distance/time totals stay exact and percentages computed from the histogram remain meaningful.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByDistance ¶
ByDistance weighs a sample by the distance it covers.
func ByDuration ¶
ByDuration weighs a sample by the time it covers.
Types ¶
type Bucket ¶
type Bucket struct {
FromKmh float64
ToKmh float64
Count int
Distance float64 // meters
Duration float64 // seconds
}
Bucket is one histogram bin, covering speeds in [FromKmh, ToKmh).
type Histogram ¶
type Histogram struct {
BinWidth float64
Buckets []Bucket
// Samples are the non-excluded samples, kept for percentile queries.
Samples []Sample
TotalDistance float64 // meters
TotalDuration float64 // seconds
// Excluded aggregates samples dropped for exceeding Options.MaxSpeedKmh.
Excluded Bucket
}
Histogram holds bucketed samples plus totals needed to turn buckets and percentiles into shares of the overall distance/time.
func NewHistogram ¶
NewHistogram buckets samples by speed, weighting each bucket by both the distance and time it covers.
func (Histogram) SpeedAbove ¶
func (h Histogram) SpeedAbove(coveragePct float64, weightFn WeightFunc) float64
SpeedAbove returns the speed threshold X such that coveragePct percent of the total weight (distance or time, per weightFn) was covered at speed at or above X. For example SpeedAbove(99, ByDistance) answers "99% of distance was covered at speed above X km/h".
type Options ¶
type Options struct {
// MinInterval is the minimum duration a sample must span before its speed
// is trusted. Shorter spans are merged into the following sample.
MinInterval time.Duration
// MinDistance is the minimum distance (in meters) a sample must span
// before its speed is trusted. Shorter spans are merged into the
// following sample.
MinDistance float64
// MaxHDOP discards points whose horizontal dilution of precision exceeds
// this value, bridging the gap between the surrounding good fixes. Zero
// disables HDOP filtering.
MaxHDOP float64
// MaxSpeedKmh excludes samples faster than this from the histogram and
// percentiles, reporting them separately as GPS noise. Zero disables
// this clamp.
MaxSpeedKmh float64
// BinWidth is the histogram bucket width, km/h. Defaults to 5 if zero.
BinWidth float64
}
Options configures how raw points are turned into speed Samples and how Samples are bucketed into a Histogram.
type WeightFunc ¶
WeightFunc selects which sample weight to use for a coverage/percentile query: distance-weighted or time-weighted.