plate-tool/plate-tool-web/src/lib.rs

100 lines
3.0 KiB
Rust
Raw Normal View History

2023-05-11 21:49:03 +00:00
#![allow(non_snake_case)]
mod components;
2024-02-12 00:46:43 +00:00
use std::error::Error;
2023-05-11 21:49:03 +00:00
2023-05-21 16:45:12 +00:00
use components::main_window::MainWindow;
2024-02-12 00:46:43 +00:00
use components::states::MainState;
use plate_tool_lib::csv::*;
2023-06-01 17:04:03 +00:00
use yew::prelude::*;
2023-05-11 21:49:03 +00:00
2023-05-12 20:38:14 +00:00
#[cfg(debug_assertions)]
2024-02-12 00:46:43 +00:00
use plate_tool_lib::*;
2023-05-12 20:38:14 +00:00
#[function_component]
pub fn App() -> Html {
html! {
<MainWindow />
}
2023-05-11 21:49:03 +00:00
}
2023-05-12 20:38:14 +00:00
#[cfg(debug_assertions)]
2023-05-12 20:38:14 +00:00
pub fn plate_test() {
let source = plate::Plate::new(plate::PlateType::Source, plate::PlateFormat::W96);
2023-05-13 23:13:03 +00:00
let destination = plate::Plate::new(plate::PlateType::Destination, plate::PlateFormat::W384);
2023-05-12 20:38:14 +00:00
let transfer = transfer_region::TransferRegion {
source_plate: source,
source_region: transfer_region::Region::Rect((1, 1), (2, 2)),
dest_plate: destination,
dest_region: transfer_region::Region::Rect((2, 2), (11, 11)),
2023-06-01 17:04:03 +00:00
interleave_source: (1, 1),
interleave_dest: (3, 3),
2023-05-12 20:38:14 +00:00
};
2023-05-13 00:25:21 +00:00
println!("{}", transfer);
2023-05-21 01:29:21 +00:00
let sws = transfer.get_source_wells();
let m = transfer.calculate_map();
for w in sws {
2023-06-01 17:04:03 +00:00
println!("{:?} -> {:?}", w, m(w));
2023-05-21 01:29:21 +00:00
}
2023-05-12 20:38:14 +00:00
}
2024-02-12 00:46:43 +00:00
pub fn state_to_csv(state: &MainState) -> Result<String, Box<dyn Error>> {
match state.preferences.csv_export_type {
components::states::CsvExportType::Normal => state_to_csv_regular(state),
components::states::CsvExportType::EchoClient => state_to_csv_echo_client(state)
}
}
fn state_to_csv_regular(state: &MainState) -> Result<String, Box<dyn Error>> {
2024-02-12 00:46:43 +00:00
let mut records: Vec<TransferRecord> = Vec::new();
for transfer in &state.transfers {
let src_barcode = state
.source_plates
.iter()
.find(|spi| spi.get_uuid() == transfer.source_id)
.ok_or("Found unpurged transfer")?;
let dest_barcode = state
.destination_plates
.iter()
.find(|dpi| dpi.get_uuid() == transfer.dest_id)
.ok_or("Found unpurged transfer")?;
records.append(&mut transfer_to_records(
transfer,
&src_barcode.name,
&dest_barcode.name,
))
}
records_to_csv(records)
}
fn state_to_csv_echo_client(state: &MainState) -> Result<String, Box<dyn Error>> {
let current_src = state.selected_source_plate;
let current_dst = state.selected_dest_plate;
let mut records: Vec<TransferRecord> = Vec::new();
for transfer in &state.transfers {
let src_barcode = state
.source_plates
.iter()
.find(|spi| spi.get_uuid() == transfer.source_id)
.ok_or("Found unpurged transfer")?;
let dest_barcode = state
.destination_plates
.iter()
.find(|dpi| dpi.get_uuid() == transfer.dest_id)
.ok_or("Found unpurged transfer")?;
if src_barcode.get_uuid() == current_src && dest_barcode.get_uuid() == current_dst {
records.append(&mut transfer_to_records(
transfer,
&src_barcode.name,
&dest_barcode.name,
))
}
}
records_to_echo_client_csv(records)
}