Skip to content

Commit

Permalink
# changes to get results from single/list of pages for estimator (#1884)
Browse files Browse the repository at this point in the history
* # changes to get results from single/list of pages for estimator

* missed one file

* Add description of filed

* missed changes during mergeing confilcts

* small bugfix

* fix request's url

* delete console log
  • Loading branch information
matuszsmig authored Dec 12, 2024
1 parent 6f48b3c commit 33333d8
Show file tree
Hide file tree
Showing 5 changed files with 240 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -1,48 +1,86 @@
import { Card, CardContent, Tab, Tabs } from '@mui/material';
import { SyntheticEvent, useCallback, useEffect, useState } from 'react';

import { FullSimulationData, useShSimulation } from '../../../../services/ShSimulatorService';
import {
FullSimulationData,
SpecificEstimator,
useShSimulation
} from '../../../../services/ShSimulatorService';
import { EstimatorPagesByDimensions } from '../../../../types/ResponseTypes';

interface EstimatorsTabProps {
tabsValue: number;
setTabsValue: (value: number) => void;
simulation: FullSimulationData;
setResultsSimulationData: React.Dispatch<React.SetStateAction<FullSimulationData | undefined>>;
estimatorsTabData: string[];
estimatorsPagesData: EstimatorPagesByDimensions[] | undefined;
}

const EstimatorsSelect = ({
tabsValue,
setTabsValue,
simulation,
setResultsSimulationData,
estimatorsTabData
estimatorsTabData,
estimatorsPagesData
}: EstimatorsTabProps) => {
const [controller] = useState(new AbortController());

const { getJobResult } = useShSimulation();
const { getEstimatorsPages } = useShSimulation();

const handleEstimatorTabChange = useCallback(
async (id: number) => {
const currentEstimatorData = simulation.estimators;
const estimatorExists =
currentEstimatorData[id] && currentEstimatorData[id].name !== '';

if (!estimatorExists) {
const simulationJobId = simulation.jobId;
if (estimatorsPagesData) {
const estimatorsPagesByDimensions = estimatorsPagesData[id].pagesByDimensions;

if (!estimatorExists) {
const simulationJobId = simulation.jobId;
const allResults: SpecificEstimator[] = [];

for (const [dimension, pageDimension] of Object.entries(
estimatorsPagesByDimensions
)) {
const estimatorData = await getEstimatorsPages(
{
jobId: simulationJobId,
estimatorName: estimatorsTabData[id],
pageNumbers: pageDimension.pageNums
},
controller.signal,
true
);

if (estimatorData) {
allResults.push(estimatorData);
}
}

const estimatorData = await getJobResult(
{
jobId: simulationJobId,
estimatorName: estimatorsTabData[id]
},
controller.signal,
true
);
if (allResults.length === 0) return;

const newEstimatorData = estimatorData?.estimators;
const aggregationResults = allResults.reduce(
(acc, result) => {
result.estimators.forEach(estimator => {
const existingEstimator = acc.estimators.find(
e => e.name === estimator.name
);

if (existingEstimator) {
existingEstimator.pages.push(...estimator.pages);
} else {
acc.estimators.push(estimator);
}
});

return acc;
},
{ jobId: simulationJobId, estimators: [], message: '' } as SpecificEstimator
);

if (newEstimatorData) {
const newEstimators = [...currentEstimatorData];

while (newEstimators.length <= id) {
Expand All @@ -52,7 +90,7 @@ const EstimatorsSelect = ({
});
}

newEstimators[id] = newEstimatorData[0];
newEstimators[id] = aggregationResults.estimators[0];

const newSimulation = {
...simulation,
Expand All @@ -62,7 +100,14 @@ const EstimatorsSelect = ({
}
}
},
[controller.signal, estimatorsTabData, getJobResult, setResultsSimulationData, simulation]
[
controller.signal,
estimatorsPagesData,
estimatorsTabData,
getEstimatorsPages,
setResultsSimulationData,
simulation
]
);

useEffect(() => {
Expand Down
10 changes: 8 additions & 2 deletions src/WrapperApp/components/Results/ResultsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,22 @@ function ResultsPanel() {
const [estimatorsResults, setEstimatorsResults] = useState<EstimatorResults[]>([]);
const [groupQuantities, setGroupQuantities] = useState(false);

const userTabInputFilesEstimatorNames = simulation?.input.userInputFilesEstimatorNames;
const userTabInputFilesEstimatorNames = simulation?.input.estimatorsItems?.map(
estimator => estimator.name
);
const uploadedInputFilesEstimatorNames = estimatorsResults?.map(estimator => estimator.name);

const editorEstimatorNames = simulation?.input.inputJson?.scoringManager.outputs
.filter(output => output.name)
.map(output => output.name);

const estimatorsTabData: string[] | undefined = simulation?.input.userInputFilesEstimatorNames
const estimatorsTabData: string[] | undefined = simulation?.input.estimatorsItems
? userTabInputFilesEstimatorNames
: editorEstimatorNames;

// In estimatorsItems we store information about estimators and estimator's pages by dimensions, names, and number of pages
const estimatorsPagesData = simulation?.input.estimatorsItems;

useEffect(() => {
setEstimatorsResults(parseEstimators(simulation?.estimators ?? []));

Expand Down Expand Up @@ -168,6 +173,7 @@ function ResultsPanel() {
? estimatorsTabData
: uploadedInputFilesEstimatorNames
}
estimatorsPagesData={estimatorsPagesData}
/>
<EstimatorTab
estimator={chosenEstimator}
Expand Down
Loading

0 comments on commit 33333d8

Please sign in to comment.