From f5997b61f8e4ee898c33877a56c2f987f5033bcd Mon Sep 17 00:00:00 2001 From: rmdocherty Date: Wed, 7 Aug 2024 11:30:47 +0100 Subject: [PATCH 01/21] changed 'success' to 'good news!' --- frontend/src/components/Popups.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/Popups.tsx b/frontend/src/components/Popups.tsx index ada3136..86b54e3 100644 --- a/frontend/src/components/Popups.tsx +++ b/frontend/src/components/Popups.tsx @@ -71,7 +71,7 @@ export const CLSModal = () => { } } - const txt = (showWarning == "over") ? 'Success!' : "Warning!" + const txt = (showWarning == "over") ? 'Good news!' : "Warning!" const bg = (showWarning == "over") ? '#6ac40a' : '#fcba03' return ( From 7c5cc78941144f57a09afc683fdd424096d5fcb1 Mon Sep 17 00:00:00 2001 From: rmdocherty Date: Wed, 7 Aug 2024 11:31:18 +0100 Subject: [PATCH 02/21] fixed race condition between server phase frac pings and repr results --- frontend/src/App.tsx | 14 ++++++++++---- frontend/src/components/Menu.tsx | 24 ++++++++++++++++++------ frontend/src/components/imageLogic.tsx | 2 +- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index ccc87d5..8a33e22 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -8,13 +8,13 @@ import NormalSlider from "./components/NormalSlider"; import { Menu } from "./components/Menu"; import { ErrorMessage, CLSModal, MoreInfo } from "./components/Popups" -import { loadFromTIFF, loadFromImage } from "./components/imageLogic"; +import { loadFromTIFF, loadFromImage, getPhaseFraction } from "./components/imageLogic"; import "./assets/scss/App.scss"; import 'bootstrap/dist/css/bootstrap.min.css'; -const PATH = "http://127.0.0.1:5000"; -//const PATH = "https://samba-segment.azurewebsites.net"; +//const PATH = "http://127.0.0.1:5000"; +const PATH = "https://samba-segment.azurewebsites.net"; //const PATH = "http://localhost:7071/api"; //const PATH = "https://representative.azurewebsites.net/api" const PF_ENDPOINT = PATH + "/phasefraction" @@ -147,7 +147,13 @@ const App = () => { }) const vals = imageInfo?.phaseVals! - const phaseFrac = accurateFractions![vals[selectedPhase - 1]] + const phaseFrac = (accurateFractions != null) ? + accurateFractions[vals[selectedPhase - 1]] + : getPhaseFraction( + imageInfo?.previewData.data!, + vals[selectedPhase - 1] + ); + setPfB([phaseFrac - absErr, phaseFrac + absErr]) if (obj["cls"] > IR_LIMIT_PX) { setShowWarning("cls") } diff --git a/frontend/src/components/Menu.tsx b/frontend/src/components/Menu.tsx index 4d9c64e..ecdc714 100644 --- a/frontend/src/components/Menu.tsx +++ b/frontend/src/components/Menu.tsx @@ -191,12 +191,24 @@ const Result = () => { const lResultRef = useRef(null); const vals = imageInfo?.phaseVals! - const phaseFrac = (accurateFractions != null) ? - accurateFractions[vals[selectedPhase - 1]] - : getPhaseFraction( - imageInfo?.previewData.data!, - vals[selectedPhase - 1] - ); + + const getPhaseFracs = () => { + const accurateAvailable = accurateFractions != null + const coarseAvailable = (imageInfo != null) && (imageInfo.previewData.data != null) + + if (accurateAvailable) { + return accurateFractions[vals[selectedPhase - 1]] + } else if (coarseAvailable) { + return getPhaseFraction( + imageInfo?.previewData.data!, + vals[selectedPhase - 1] + ); + } else { + return 0 + } + } + + const phaseFrac = getPhaseFracs(); const l = analysisInfo?.lForDefaultErr; diff --git a/frontend/src/components/imageLogic.tsx b/frontend/src/components/imageLogic.tsx index 1be6c62..15f4f57 100644 --- a/frontend/src/components/imageLogic.tsx +++ b/frontend/src/components/imageLogic.tsx @@ -38,7 +38,7 @@ export const getPhaseFraction = (arr: Uint8ClampedArray, val: number, nChannels: console.log('ahhhh') const uniqueVals = arr.filter((_, i, __) => { return i % nChannels == 0 }) const matching = uniqueVals.filter((v) => v == val); - return (100 * matching.length) / (arr.length / nChannels); + return (matching.length) / (arr.length / nChannels); } export const loadFromTIFF = (tiffBuffer: ArrayBuffer): ImageLoadInfo => { From ef16844925fc6ed8a1cf10d625426954fcd86550 Mon Sep 17 00:00:00 2001 From: rmdocherty Date: Wed, 7 Aug 2024 11:41:21 +0100 Subject: [PATCH 03/21] can view image info from topbar --- frontend/src/components/Menu.tsx | 4 +++- frontend/src/components/Popups.tsx | 6 ++++-- frontend/src/components/Topbar.tsx | 6 ++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/Menu.tsx b/frontend/src/components/Menu.tsx index ecdc714..e1a2979 100644 --- a/frontend/src/components/Menu.tsx +++ b/frontend/src/components/Menu.tsx @@ -269,6 +269,8 @@ const Result = () => { const vol = (ii?.nDims! == 3) ? (ii?.height! * ii?.width! * ii?.width!) : (ii?.height! * ii?.width!) const nMore = (Math.ceil(Math.pow(l!, imageInfo?.nDims!) / vol)) - 1 + const modalTitle = `Results for "${imageInfo?.file?.name}"` + const title = "Phase Fraction Estimation of the Material" const smallResults = ( @@ -325,7 +327,7 @@ const Result = () => { const largeResults = (<> - Results! + {modalTitle} diff --git a/frontend/src/components/Popups.tsx b/frontend/src/components/Popups.tsx index 86b54e3..43b8cd9 100644 --- a/frontend/src/components/Popups.tsx +++ b/frontend/src/components/Popups.tsx @@ -95,12 +95,14 @@ export const MoreInfo = () => { imageInfo: [imageInfo,], analysisInfo: [analysisInfo,], showInfo: [showInfo, setShowInfo], - menuState: [, setMenuState] + menuState: [menuState, setMenuState] } = useContext(AppContext)!; const handleClose = () => { setShowInfo(false); - setMenuState('conf_result'); + if (menuState == "conf_result_full") { + setMenuState('conf_result'); + } }; return ( diff --git a/frontend/src/components/Topbar.tsx b/frontend/src/components/Topbar.tsx index c527f38..fc61ba3 100644 --- a/frontend/src/components/Topbar.tsx +++ b/frontend/src/components/Topbar.tsx @@ -1,4 +1,5 @@ import React, { useContext, useEffect, useRef, useState } from "react"; +import AppContext from "./interfaces"; import Container from 'react-bootstrap/Container'; import Nav from 'react-bootstrap/Nav'; @@ -6,6 +7,10 @@ import Navbar from 'react-bootstrap/Navbar'; import { TopbarProps } from "./interfaces"; const Topbar = ({ loadFromFile, reset, changePhase }: TopbarProps) => { + + const { + showInfo: [showInfo, setShowInfo], + } = useContext(AppContext)!; const fileInputRef = useRef(null); const addData = () => { @@ -30,6 +35,7 @@ const Topbar = ({ loadFromFile, reset, changePhase }: TopbarProps) => { ImageRep