Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/daq_log_parse/correlate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ pub struct CorrelationFunction {
}

impl CorrelationFunction {
pub fn correlate(&self, log_ts: u32) -> Option<chrono::DateTime<chrono::Local>> {
pub fn correlate(&self, log_ts: u32) -> Option<chrono::DateTime<chrono::Utc>> {
let unix_ms = self.slope * log_ts as f64 + self.intercept_ms;

match chrono::DateTime::from_timestamp_millis(unix_ms.round() as i64) {
Some(dt) => Some(dt.with_timezone(&chrono::Local)),
Some(dt) => Some(dt),
None => {
log::error!(
"Correlated time {} ms for log time {} ms is out of range for chrono::DateTime",
Expand Down Expand Up @@ -122,19 +121,18 @@ pub fn time_correlate_chunk(chunk: Vec<ParsedMessage>) -> CorrelationChunkResult
})
{
let dt_utc = chrono::Utc.from_utc_datetime(&dt);
let dt_local = chrono::DateTime::<chrono::Local>::from(dt_utc);

let current_year = chrono::Local::now().year();
if dt_local.year() < current_year - 2 || dt_local.year() > current_year + 2 {
let current_year = chrono::Utc::now().year();
if dt_utc.year() < current_year - 2 || dt_utc.year() > current_year + 2 {
log::warn!(
"GPS message at {} ms has suspicious year value {}, skipping",
msg.timestamp,
dt_local.year()
dt_utc.year()
);
continue;
}

gps_points.push((msg.timestamp, dt_local));
gps_points.push((msg.timestamp, dt_utc));
} else {
log::error!(
"GPS message at {} ms has invalid date/time values, skipping",
Expand Down
8 changes: 5 additions & 3 deletions src/daq_log_parse/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ impl TableBuilder {

let first_correlated_time: Option<String> =
chunk.correlation_fn.as_ref().and_then(|cf| {
cf.correlate(first_time)
.map(|dt| dt.format("%Y_%m_%d__%H_%M_%S").to_string())
cf.correlate(first_time).map(|dt| {
dt.to_rfc3339_opts(chrono::SecondsFormat::Millis, true)
.replace(':', "-")
})
Comment thread
LelsersLasers marked this conversation as resolved.
});

let out_file = match first_correlated_time {
Expand All @@ -181,7 +183,7 @@ impl TableBuilder {
.as_ref()
.and_then(|cf| cf.correlate(row_time))
{
row[0] = ct.format("%H:%M:%S.%3f").to_string();
row[0] = ct.to_rfc3339_opts(chrono::SecondsFormat::Millis, true);
}
row[1] = format!("{:.3}", row_time as f32 / 1000.0);

Expand Down
Loading