More robust CSV parsing

Permit lowercases, alternative column names
This commit is contained in:
Emilia Allison 2024-02-10 18:00:47 -05:00
parent 8a3bbc8b92
commit 0625854895
Signed by: emilia
GPG Key ID: 05D5D1107E5100A1
2 changed files with 11 additions and 7 deletions

View File

@ -1,4 +1,5 @@
use std::collections::HashSet;
use std::str::FromStr;
use js_sys::Array;
use lazy_static::lazy_static;
@ -107,6 +108,9 @@ pub fn import_transfer_csv_onload_callback(
) -> Closure<dyn FnMut(Event)> {
Closure::<dyn FnMut(_)>::new(move |_: Event| {
if let Some(value) = &file_reader.result().ok().and_then(|v| v.as_string()) {
let (header, data) = value.split_at(value.find("\n").unwrap());
let modified: String = header.to_lowercase() + data;
log::info!("{}", modified);
let mut rdr = csv::Reader::from_reader(value.as_bytes());
let mut records = Vec::new();
for record in rdr.deserialize::<crate::data::csv::TransferRecord>() {
@ -245,7 +249,7 @@ pub fn import_transfer_csv_submit_callback(
let to_dest = to_dest.value();
lazy_static! {
static ref REGEX: Regex = Regex::new(r"([A-Z]+)(\d+)").unwrap();
static ref REGEX: Regex = Regex::new(r"([A-Z,a-z]+)(\d+)").unwrap();
}
let records: Vec<((u8, u8), (u8, u8))> = records
.iter()

View File

@ -7,17 +7,17 @@ use std::error::Error;
#[derive(Serialize, Deserialize, Debug)]
pub struct TransferRecord {
#[serde(rename = "Source Plate")]
#[serde(rename = "Source Plate", alias = "source plate", alias = "src plate")]
pub source_plate: String,
#[serde(rename = "Source Well")]
#[serde(rename = "Source Well", alias = "source well", alias = "src well")]
pub source_well: String,
#[serde(rename = "Dest Plate")]
#[serde(rename = "Dest Plate", alias = "dest plate", alias = "destination plate")]
pub destination_plate: String,
#[serde(rename = "Destination Well")]
#[serde(rename = "Destination Well", alias = "destination well", alias = "dest well")]
pub destination_well: String,
#[serde(rename = "Transfer Volume")]
#[serde(rename = "Transfer Volume", alias = "transfer volume")]
pub volume: f32,
#[serde(rename = "Concentration")]
#[serde(rename = "Concentration", alias = "concentration")]
pub concentration: Option<f32>,
}