Skip to content

Commit a90066b

Browse files
authored
TimeCorrectionsDB (#23)
* TimeCorrectionsDB: * rename gnss_absolute_time_solver to database * rename TimeCorrections * add notion of validity period * Return an error when correction is not available in the database --------- Signed-off-by: Guillaume W. Bres <[email protected]>
1 parent a499faf commit a90066b

File tree

5 files changed

+222
-132
lines changed

5 files changed

+222
-132
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ mod processing;
1212
#[cfg(feature = "processing")]
1313
pub use processing::{
1414
Decimate, DecimationError, DecimationFilter, DecimationFilterType, Filter, FilterItem,
15-
GnssAbsoluteTime, MaskError, MaskFilter, MaskOperand, Masking, Preprocessing, Repair,
16-
RepairTrait, Split, TimePolynomial, Timeshift,
15+
MaskError, MaskFilter, MaskOperand, Masking, Preprocessing, Repair, RepairTrait, Split,
16+
TimeCorrection, TimeCorrectionsDB, Timeshift,
1717
};
1818

1919
#[cfg(feature = "html")]

src/processing/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod split;
1515
pub use split::Split;
1616

1717
mod time;
18-
pub use time::{GnssAbsoluteTime, TimePolynomial, Timeshift};
18+
pub use time::{TimeCorrection, TimeCorrectionsDB, Timeshift};
1919

2020
/// Preprocessing Trait is usually implemented by GNSS data
2121
/// to preprocess prior further analysis.
Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,68 @@
1-
use hifitime::{Epoch, Polynomial, TimeScale};
1+
use hifitime::{Duration, Epoch, Polynomial, TimeScale};
22

3-
/// [TimePolynomial] allows precise [Epoch] translation to another [TimeScale].
3+
/// [TimeCorrection] allows precise [Epoch] translation to another [TimeScale].
44
/// For example, |[TimeScale::GPST]-[TimeScale::UTC]| when referencing [TimeScale::GPST] to [TimeScale::UTC].
55
#[derive(Copy, Clone, PartialEq)]
6-
pub struct TimePolynomial {
6+
pub struct TimeCorrection {
77
/// LHS [TimeScale] to which [Polynomial] applies
88
pub lhs_timescale: TimeScale,
9+
910
/// RHS [TimeScale] to which [Polynomial] applies
1011
pub rhs_timescale: TimeScale,
12+
1113
/// Reference [Epoch] usually expressed in LHS [TimeScale], but we support any [TimeScale] here.
1214
pub ref_epoch: Epoch,
15+
16+
/// Validity period as [Duration]
17+
pub validity_period: Duration,
18+
1319
/// [Polynomial]
1420
pub polynomial: Polynomial,
1521
}
1622

17-
impl TimePolynomial {
18-
/// Define new [TimePolynomial] from Reference [Epoch] expressed as week counter
23+
impl TimeCorrection {
24+
/// Define new [TimeCorrection] from Reference [Epoch] expressed as week counter
1925
/// and elapsed seconds within week.
2026
pub fn from_reference_time_of_week_seconds(
2127
ref_week: u32,
2228
ref_tow: u64,
29+
validity_period: Duration,
2330
lhs_timescale: TimeScale,
2431
rhs_timescale: TimeScale,
2532
polynomial: Polynomial,
2633
) -> Self {
2734
Self::from_reference_time_of_week_nanos(
2835
ref_week,
2936
ref_tow * 1_000_000_000,
37+
validity_period,
3038
lhs_timescale,
3139
rhs_timescale,
3240
polynomial,
3341
)
3442
}
3543

36-
/// Define new [TimePolynomial] from reference [Epoch] that must be expressed in the correct [TimeScale]
44+
/// Define new [TimeCorrection] from reference [Epoch] that must be expressed in the correct [TimeScale]
3745
pub fn from_reference_epoch(
3846
ref_epoch: Epoch,
47+
validity_period: Duration,
3948
rhs_timescale: TimeScale,
4049
polynomial: Polynomial,
4150
) -> Self {
4251
Self {
4352
ref_epoch,
53+
validity_period,
4454
lhs_timescale: ref_epoch.time_scale,
4555
rhs_timescale,
4656
polynomial,
4757
}
4858
}
4959

50-
/// Define a new [TimePolynomials] from Reference [Epoch] expressed as week counter and
60+
/// Define a new [TimeCorrections] from Reference [Epoch] expressed as week counter and
5161
/// elapsed nanoseconds within week.
5262
pub fn from_reference_time_of_week_nanos(
5363
ref_week: u32,
5464
ref_tow_nanos: u64,
65+
validity_period: Duration,
5566
lhs_timescale: TimeScale,
5667
rhs_timescale: TimeScale,
5768
polynomial: Polynomial,
@@ -60,9 +71,27 @@ impl TimePolynomial {
6071

6172
Self {
6273
ref_epoch,
74+
validity_period,
6375
lhs_timescale,
6476
rhs_timescale,
6577
polynomial,
6678
}
6779
}
80+
81+
/// Returns true if this [TimeCorrection] should apply at ongoing [Epoch],
82+
/// acoording to publication validity period.
83+
pub fn applies(&self, now: Epoch) -> bool {
84+
let dt = (now - self.ref_epoch).abs();
85+
dt < self.validity_period
86+
}
87+
88+
/// Returns first [Epoch] for which this [TimeCorrection] should apply.
89+
pub fn validity_period_start(&self) -> Epoch {
90+
self.ref_epoch - self.validity_period
91+
}
92+
93+
/// Returns last [Epoch] for which this [TimeCorrection] should apply.
94+
pub fn validity_period_end(&self) -> Epoch {
95+
self.ref_epoch + self.validity_period
96+
}
6897
}

0 commit comments

Comments
 (0)