Skip to content

Commit 01d3868

Browse files
committed
Add time based placeholders for scan/visit templates
{ts_hms} for HourMinuteSecond, eg 142117 {ts_ymd} for YearMonthDay, eg 20250221
1 parent a7a28cc commit 01d3868

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/graphql.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use axum::{Extension, Json, Router};
3737
use axum_extra::headers::authorization::Bearer;
3838
use axum_extra::headers::Authorization;
3939
use axum_extra::TypedHeader;
40-
use chrono::{Datelike, Local};
40+
use chrono::{DateTime, Datelike, Local};
4141
use tokio::net::TcpListener;
4242
use tracing::{info, instrument, trace, warn};
4343

@@ -147,6 +147,7 @@ struct VisitPath {
147147
struct ScanPaths {
148148
visit: VisitPath,
149149
subdirectory: Subdirectory,
150+
timestamp: DateTime<Local>,
150151
}
151152

152153
/// GraphQL type to provide current configuration for a beamline
@@ -301,6 +302,8 @@ impl FieldSource<ScanField> for ScanPaths {
301302
ScanField::Subdirectory => self.subdirectory.to_string().into(),
302303
ScanField::ScanNumber => self.visit.info.scan_number().to_string().into(),
303304
ScanField::Beamline(bl) => self.visit.resolve(bl),
305+
ScanField::YearMonthDay => self.timestamp.format("%Y%m%d").to_string().into(),
306+
ScanField::HourMinuteSecond => self.timestamp.format("%H%M%S").to_string().into(),
304307
}
305308
}
306309
}
@@ -427,6 +430,7 @@ impl Mutation {
427430
visit,
428431
info: next_scan,
429432
},
433+
timestamp: Local::now(),
430434
subdirectory: sub.unwrap_or_default(),
431435
})
432436
}

src/paths.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub enum BeamlineField {
3131
pub enum ScanField {
3232
Subdirectory,
3333
ScanNumber,
34+
YearMonthDay,
35+
HourMinuteSecond,
3436
Beamline(BeamlineField),
3537
}
3638

@@ -57,6 +59,8 @@ impl Display for ScanField {
5759
ScanField::Subdirectory => f.write_str("subdirectory"),
5860
ScanField::ScanNumber => f.write_str("scan_number"),
5961
ScanField::Beamline(bl) => write!(f, "{bl}"),
62+
ScanField::YearMonthDay => f.write_str("ts_ymd"),
63+
ScanField::HourMinuteSecond => f.write_str("ts_hms"),
6064
}
6165
}
6266
}
@@ -100,6 +104,8 @@ impl TryFrom<String> for ScanField {
100104
match value.as_str() {
101105
"scan_number" => Ok(ScanField::ScanNumber),
102106
"subdirectory" => Ok(ScanField::Subdirectory),
107+
"ts_hms" => Ok(ScanField::HourMinuteSecond),
108+
"ts_ymd" => Ok(ScanField::YearMonthDay),
103109
_ => Ok(ScanField::Beamline(BeamlineField::try_from(value)?)),
104110
}
105111
}

0 commit comments

Comments
 (0)