Add Echo Client format support in lib

This commit is contained in:
Emilia Allison 2024-08-03 17:55:13 -04:00
parent 3fcd526010
commit 194b78430c
Signed by: emilia
GPG Key ID: 7A3F8997BFE894E0
3 changed files with 37 additions and 2 deletions

View File

@ -0,0 +1,26 @@
use serde::Serialize;
use super::TransferRecord;
// Format preferred by the Echo Client when using the Pick-List function.
// Note that this does not export plate info!
// Exports of this type should combine all transfers between the two actively selected plates.
#[derive(Serialize, Debug)]
pub struct EchoClientTransferRecord {
#[serde(rename = "SrcWell")]
pub source_well: String,
#[serde(rename = "DestWell")]
pub destination_well: String,
#[serde(rename = "XferVol")]
pub volume: f32,
}
impl From<TransferRecord> for EchoClientTransferRecord {
fn from(value: TransferRecord) -> Self {
EchoClientTransferRecord {
source_well: value.source_well,
destination_well: value.destination_well,
volume: value.volume,
}
}
}

View File

@ -1,10 +1,9 @@
use crate::transfer::Transfer; use crate::transfer::Transfer;
use crate::util::*; use crate::util::*;
use super::{TransferRecord, transfer_record::TransferRecordDeserializeIntermediate, mangle_headers::mangle_headers}; use super::{alternative_formats::EchoClientTransferRecord, mangle_headers::mangle_headers, transfer_record::TransferRecordDeserializeIntermediate, TransferRecord};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use serde::{Deserialize, Serialize};
use std::error::Error; use std::error::Error;
pub fn transfer_to_records( pub fn transfer_to_records(
@ -44,6 +43,15 @@ pub fn records_to_csv(trs: Vec<TransferRecord>) -> Result<String, Box<dyn Error>
Ok(data) Ok(data)
} }
pub fn records_to_echo_client_csv(trs: Vec<TransferRecord>) -> Result<String, Box<dyn Error>> {
let mut wtr = csv::WriterBuilder::new().from_writer(vec![]);
for record in trs {
wtr.serialize(Into::<EchoClientTransferRecord>::into(record))?
}
let data = String::from_utf8(wtr.into_inner()?)?;
Ok(data)
}
pub fn string_well_to_pt(input: &str) -> Option<(u8, u8)> { pub fn string_well_to_pt(input: &str) -> Option<(u8, u8)> {
lazy_static! { lazy_static! {
static ref REGEX: Regex = Regex::new(r"([A-Z,a-z]+)(\d+)").unwrap(); static ref REGEX: Regex = Regex::new(r"([A-Z,a-z]+)(\d+)").unwrap();

View File

@ -2,6 +2,7 @@ mod transfer_record;
mod conversion; mod conversion;
mod auto; mod auto;
mod mangle_headers; mod mangle_headers;
mod alternative_formats;
pub use transfer_record::volume_default; pub use transfer_record::volume_default;
pub use transfer_record::TransferRecord; pub use transfer_record::TransferRecord;