From 51093f5efd2a242d1839d76e211d32888846b0b4 Mon Sep 17 00:00:00 2001 From: Emilia Date: Sat, 10 Aug 2024 04:49:10 -0400 Subject: [PATCH] fix: Consider well re-usage when calculating volume --- README.md | 8 ++++---- plate-tool-web/src/components/plates/plate.rs | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 618ea57..c88b303 100644 --- a/README.md +++ b/README.md @@ -157,13 +157,13 @@ To turn them back on, do the exact same thing. This can be used to verify that all of the wells in a plate will have the same volume transferred at a glance. Wells will be colored based on the sum of all transfers using that plate. -In version `0.5.0`, this is best suited for use with CSV imports. To toggle this feature, mouse over "Options", then "Styles", then click "Toggle volume heatmap". -_NOTE:_ In version `<=0.5.0`, if a source well is used multiple times it's volume will -be representative of the total usage. - +_NOTE_: The scale for the colors is spaced linearly; if you have a well that is being used +significantly more than some others, it may be difficult to see the difference between other wells +with more similar volumes. +If you have a use case that would benefit from a logarithmic scale here, please let me know. ## Installation diff --git a/plate-tool-web/src/components/plates/plate.rs b/plate-tool-web/src/components/plates/plate.rs index ba1769f..c19ed36 100644 --- a/plate-tool-web/src/components/plates/plate.rs +++ b/plate-tool-web/src/components/plates/plate.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::ops::Deref; +use plate_tool_lib::transfer_region::TransferRegion; use plate_tool_lib::transfer_volume::TransferVolume; use yew::prelude::*; use yewdux::prelude::*; @@ -75,11 +76,15 @@ pub fn Plate(props: &PlateProps) -> Html { }, _ => unreachable!(), }; + // Usage to be used as a volume multiplier; should be in [1, U32_MAX] + // First convert to f64 (u32 can not fit in f32 directly) and then cast + // to round into the closest f32. + let usage: f32 = Into::::into(count_plate_usage(transfer, &well).unwrap_or(1u32).max(1u32)) as f32; if let Some(val) = volume_map_temp.get_mut(&well) { - *val += temp_volume + *val += temp_volume * usage; } else { - volume_map_temp.insert(well, temp_volume); + volume_map_temp.insert(well, temp_volume * usage); } volume_max_temp = f32::max(volume_max_temp, *volume_map_temp.get(&well).expect("Just added")); } @@ -270,6 +275,15 @@ pub fn in_rect(corner1: Option<(u8, u8)>, corner2: Option<(u8, u8)>, pt: (u8, u8 } } +fn count_plate_usage(transfer: &Transfer, well: &Well) -> Option { + if let Region::Custom(_) = transfer.transfer_region.source_region { + return None; + } + + let map = transfer.transfer_region.calculate_map(); + map(*well).and_then(|list| Some(list.len() as u32)) +} + #[cfg(test)] mod tests { use wasm_bindgen_test::*;