Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time based placeholders for scan/visit templates #100

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use axum::{Extension, Json, Router};
use axum_extra::headers::authorization::Bearer;
use axum_extra::headers::Authorization;
use axum_extra::TypedHeader;
use chrono::{Datelike, Local};
use chrono::{DateTime, Datelike, Local};
use tokio::net::TcpListener;
use tracing::{info, instrument, trace, warn};

Expand Down Expand Up @@ -147,6 +147,7 @@ struct VisitPath {
struct ScanPaths {
visit: VisitPath,
subdirectory: Subdirectory,
timestamp: DateTime<Local>,
}

/// GraphQL type to provide current configuration for a beamline
Expand Down Expand Up @@ -301,6 +302,8 @@ impl FieldSource<ScanField> for ScanPaths {
ScanField::Subdirectory => self.subdirectory.to_string().into(),
ScanField::ScanNumber => self.visit.info.scan_number().to_string().into(),
ScanField::Beamline(bl) => self.visit.resolve(bl),
ScanField::YearMonthDay => self.timestamp.format("%Y%m%d").to_string().into(),
ScanField::HourMinuteSecond => self.timestamp.format("%H%M%S").to_string().into(),
}
}
}
Expand Down Expand Up @@ -427,6 +430,7 @@ impl Mutation {
visit,
info: next_scan,
},
timestamp: Local::now(),
subdirectory: sub.unwrap_or_default(),
})
}
Expand Down
6 changes: 6 additions & 0 deletions src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub enum BeamlineField {
pub enum ScanField {
Subdirectory,
ScanNumber,
YearMonthDay,
HourMinuteSecond,
Beamline(BeamlineField),
}

Expand All @@ -57,6 +59,8 @@ impl Display for ScanField {
ScanField::Subdirectory => f.write_str("subdirectory"),
ScanField::ScanNumber => f.write_str("scan_number"),
ScanField::Beamline(bl) => write!(f, "{bl}"),
ScanField::YearMonthDay => f.write_str("ts_ymd"),
ScanField::HourMinuteSecond => f.write_str("ts_hms"),
}
}
}
Expand Down Expand Up @@ -100,6 +104,8 @@ impl TryFrom<String> for ScanField {
match value.as_str() {
"scan_number" => Ok(ScanField::ScanNumber),
"subdirectory" => Ok(ScanField::Subdirectory),
"ts_hms" => Ok(ScanField::HourMinuteSecond),
"ts_ymd" => Ok(ScanField::YearMonthDay),
_ => Ok(ScanField::Beamline(BeamlineField::try_from(value)?)),
}
}
Expand Down
Loading