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
|
|
|
|
2023-05-22 15:26:08 +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
|
|
|
|
2023-05-22 01:47:29 +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 {
|
2023-05-22 22:11:49 +00:00
|
|
|
source_plate: source,
|
2024-08-10 04:58:55 +00:00
|
|
|
source_region: transfer_region::Region::Rect((1, 1).into(), (2, 2).into()),
|
2023-05-22 22:11:49 +00:00
|
|
|
dest_plate: destination,
|
2024-08-10 04:58:55 +00:00
|
|
|
dest_region: transfer_region::Region::Rect((2, 2).into(), (11, 11).into()),
|
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>> {
|
2024-08-03 22:42:31 +00:00
|
|
|
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)
|
|
|
|
}
|
2024-08-03 22:42:31 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|