@signalk/tracks-plugin 3.0.2 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as TimeWindowError, a as createDistanceTo, b as thin, c as gpxFilename, d as rfc8187, g as validateParameters, h as unwrapString, i as contextName, l as historyRowPosition, m as trackLabel, n as SelfPositionUnavailableError, p as toIsoTimes, r as asciiFilename, s as createMatcher, t as QueryParameterError, u as resolveContext, v as parseTrackQuery, x as thinToBudget, y as segment } from "./utils-OGjP1B0D.js";
1
+ import { S as uncoveredBetween, _ as TimeWindowError, a as createDistanceTo, b as thin, c as gpxFilename, d as rfc8187, g as validateParameters, h as unwrapString, i as contextName, l as historyRowPosition, m as trackLabel, n as SelfPositionUnavailableError, p as toIsoTimes, r as asciiFilename, s as createMatcher, t as QueryParameterError, u as resolveContext, v as parseTrackQuery, x as thinToBudget, y as segment } from "./utils-DOEyuPRy.js";
2
2
  import { Temporal } from "@js-temporal/polyfill";
3
3
  import { join } from "node:path";
4
4
  import { Worker } from "node:worker_threads";
@@ -792,12 +792,29 @@ function reconcile(history, stored, resolution) {
792
792
  for (const point of stored) if (!covered.has(bucketOf(point.timestamp, resolution))) positions.push(point);
793
793
  positions.sort((a, b) => a.timestamp - b.timestamp);
794
794
  return {
795
- positions,
795
+ positions: measuredFromHistory(positions, history),
796
796
  fromHistory,
797
797
  fromStore: positions.length - fromHistory
798
798
  };
799
799
  }
800
800
  /**
801
+ * A stored point's `pauseBefore` was measured over the stored points thinning
802
+ * dropped before it. Where a history point now comes right before it, history
803
+ * covered part of that time, so the pause is at most the time since that
804
+ * bucket, and at most the longest step the store recorded, whichever is less.
805
+ */
806
+ function measuredFromHistory(positions, history) {
807
+ const fromHistory = new Set(history);
808
+ return positions.map((point, i) => {
809
+ const before = positions[i - 1];
810
+ if (point.pauseBefore === void 0 || before === void 0 || !fromHistory.has(before)) return point;
811
+ return {
812
+ ...point,
813
+ pauseBefore: Math.min(point.pauseBefore, uncoveredBetween(before, point))
814
+ };
815
+ });
816
+ }
817
+ /**
801
818
  * Fallback when no bucket width is known: history covers its own time span,
802
819
  * and the store supplies whatever falls outside it.
803
820
  *
@@ -818,7 +835,7 @@ function reconcileByExtent(history, stored) {
818
835
  }
819
836
  const outside = stored.filter((p) => p.timestamp < first || p.timestamp > last);
820
837
  return {
821
- positions: [...history, ...outside].sort((a, b) => a.timestamp - b.timestamp),
838
+ positions: measuredFromHistory([...history, ...outside].sort((a, b) => a.timestamp - b.timestamp), history),
822
839
  fromHistory: history.length,
823
840
  fromStore: outside.length
824
841
  };
@@ -1716,7 +1733,8 @@ async function historyPositions(app, context, window, resolutionMs, debug) {
1716
1733
  const withinEnd = window.inclusiveEnd ? timestamp <= window.to : timestamp < window.to;
1717
1734
  if (timestamp >= window.from && withinEnd) points.push({
1718
1735
  position,
1719
- timestamp
1736
+ timestamp,
1737
+ span: applied
1720
1738
  });
1721
1739
  }
1722
1740
  }