Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui-common): fix matrices display issues #1960

Merged
merged 5 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion webapp/public/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@
"study.postProcessing": "Post processing",
"study.timeLimit": "Time limit (h)",
"study.nbCpu": "Number of cores",
"study.clusterLoad": "Cluster load",
"study.allocatedCpuRate": "CPU usage",
"study.clusterLoadRate": "Cluster load",
"study.nbQueuedJobs": "Pending jobs",
"study.synthesis": "Synthesis",
"study.level": "Level",
"study.years": "Years",
Expand Down
4 changes: 3 additions & 1 deletion webapp/public/locales/fr/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@
"study.postProcessing": "Post-traitement",
"study.timeLimit": "Limite de temps (h)",
"study.nbCpu": "Nombre de coeurs",
"study.clusterLoad": "Charge du cluster",
"study.allocatedCpuRate": "Utilisation CPU",
skamril marked this conversation as resolved.
Show resolved Hide resolved
"study.clusterLoadRate": "Charge cluster",
"study.nbQueuedJobs": "Tâches en attente",
"study.synthesis": "Synthèse",
"study.level": "Niveau",
"study.years": "Années",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function HydroMatrix({ type }: Props) {
fetchFn={hydroMatrix.fetchFn}
disableEdit={hydroMatrix.disableEdit}
enablePercentDisplay={hydroMatrix.enablePercentDisplay}
stretch={hydroMatrix.stretch}
/>
</Root>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export interface HydroMatrixProps {
fetchFn?: fetchMatrixFn;
disableEdit?: boolean;
enablePercentDisplay?: boolean;
stretch?: boolean; // TODO: Remove this once the `EditableMatrix` component is refactored
}

type Matrices = Record<HydroMatrixType, HydroMatrixProps>;
Expand Down Expand Up @@ -121,7 +120,6 @@ export const MATRICES: Matrices = {
"Pumping Max Energy (Hours at Pmax)",
],
stats: MatrixStats.NOCOL,
stretch: false,
},
[HydroMatrixType.ReservoirLevels]: {
title: "Reservoir Levels",
Expand Down Expand Up @@ -177,7 +175,6 @@ export const MATRICES: Matrices = {
"December",
],
stats: MatrixStats.NOCOL,
stretch: false,
},
[HydroMatrixType.Allocation]: {
title: "Allocation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,36 @@ function ResultDetails() {
const dateTimeFromIndex = useMemo(() => {
if (!matrixRes.data) return [];

return matrixRes.data.index.map((dateTime) => {
const parsedDate = moment(dateTime, "MM/DD HH:mm");
return parsedDate.format("ddd D MMM HH:mm");
});
}, [matrixRes.data]);
// Annual format has a static string
if (timestep === Timestep.Annual) {
return ["Annual"];
}

// Original date/time format mapping for moment parsing
const parseFormat = {
[Timestep.Hourly]: "MM/DD HH:mm",
[Timestep.Daily]: "MM/DD",
[Timestep.Weekly]: "WW",
[Timestep.Monthly]: "MM",
}[timestep];

// Output formats for each timestep to match legacy UI requirements
const outputFormat = {
[Timestep.Hourly]: "DD MMM HH:mm I",
[Timestep.Daily]: "DD MMM I",
[Timestep.Weekly]: "WW",
[Timestep.Monthly]: "MMM",
}[timestep];

const needsIndex =
timestep === Timestep.Hourly || timestep === Timestep.Daily;

return matrixRes.data.index.map((dateTime, i) =>
moment(dateTime, parseFormat).format(
outputFormat.replace("I", needsIndex ? ` - ${i + 1}` : ""),
),
);
}, [matrixRes.data, timestep]);

////////////////////////////////////////////////////////////////
// Event Handlers
Expand Down Expand Up @@ -380,7 +405,6 @@ function ResultDetails() {
matrix={matrix}
matrixTime={false}
rowNames={dateTimeFromIndex}
stretch={false}
readOnly
/>
)
Expand Down
55 changes: 38 additions & 17 deletions webapp/src/components/App/Tasks/JobTableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
Checkbox,
FormControlLabel,
Typography,
Skeleton,
} from "@mui/material";
import { useTranslation } from "react-i18next";
import RefreshIcon from "@mui/icons-material/Refresh";
Expand All @@ -27,8 +28,9 @@ import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown";
import { grey } from "@mui/material/colors";
import { TaskView, TaskType } from "../../../common/types";
import usePromiseWithSnackbarError from "../../../hooks/usePromiseWithSnackbarError";
import { getLauncherLoad } from "../../../services/api/study";
import { getLauncherMetrics } from "../../../services/api/study";
import LinearProgressWithLabel from "../../common/LinearProgressWithLabel";
import UsePromiseCond from "../../common/utils/UsePromiseCond";

interface PropType {
content: TaskView[];
Expand All @@ -44,11 +46,13 @@ function JobTableView(props: PropType) {
useState<boolean>(false);
const [currentContent, setCurrentContent] = useState<TaskView[]>(content);

const { data: load, reload: reloadLauncherLoad } =
usePromiseWithSnackbarError(() => getLauncherLoad(), {
const laucherMetrics = usePromiseWithSnackbarError(
() => getLauncherMetrics(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip: use point-free

{
errorMessage: t("study.error.launchLoad"),
deps: [],
});
},
);

const applyFilter = useCallback(
(taskList: TaskView[]) => {
Expand Down Expand Up @@ -109,29 +113,46 @@ function JobTableView(props: PropType) {
>
<Box
sx={{
width: "30%",
width: "60%",
display: "flex",
justifyContent: "flex-start",
alignItems: "flex-end",
alignContent: "center",
alignSelf: "center",
gap: 1,
}}
>
<Typography sx={{ mr: 2 }}>{t("study.clusterLoad")}</Typography>
{load && (
<LinearProgressWithLabel
indicator={load.slurm * 100}
size="60%"
tooltip={t("study.clusterLoad")}
gradiant
/>
)}
<UsePromiseCond
response={laucherMetrics}
ifResolved={(data) => (
<>
<Typography>{t("study.allocatedCpuRate")}</Typography>
<LinearProgressWithLabel
indicator={Math.floor(data.allocatedCpuRate)}
size="20%"
tooltip={t("study.allocatedCpuRate")}
gradiant
/>
<Typography>{t("study.clusterLoadRate")}</Typography>
<LinearProgressWithLabel
indicator={Math.floor(data.clusterLoadRate)}
size="20%"
tooltip={t("study.clusterLoadRate")}
gradiant
/>
<Typography>
{t("study.nbQueuedJobs")}: {data.nbQueuedJobs}
</Typography>
</>
)}
ifPending={() => <Skeleton width={300} />}
/>
</Box>
<Box display="flex" alignItems="center">
<Tooltip title={t("tasks.refresh") as string} sx={{ mr: 4 }}>
<Button
color="primary"
onClick={() => {
refresh();
reloadLauncherLoad();
laucherMetrics.reload();
}}
variant="outlined"
>
Expand Down
5 changes: 1 addition & 4 deletions webapp/src/components/common/EditableMatrix/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ interface PropTypes {
rowNames?: string[];
computStats?: MatrixStats;
isPercentDisplayEnabled?: boolean;
stretch?: boolean;
}

type CellType = Array<number | string | boolean>;
Expand Down Expand Up @@ -56,7 +55,6 @@ function EditableMatrix(props: PropTypes) {
rowNames,
computStats,
isPercentDisplayEnabled = false,
stretch = true,
} = props;
const { data = [], columns = [], index = [] } = matrix;
const prependIndex = index.length > 0 && matrixTime;
Expand Down Expand Up @@ -178,10 +176,9 @@ function EditableMatrix(props: PropTypes) {
data={grid}
width="100%"
height="100%"
stretchH={stretch ? "all" : "none"}
className="editableMatrix"
colHeaders
rowHeaderWidth={matrixRowNames ? 150 : undefined}
rowHeaderWidth={rowNames ? 150 : 50}
afterChange={(change, source) =>
onUpdate && handleSlice(change || [], source)
}
Expand Down
3 changes: 0 additions & 3 deletions webapp/src/components/common/MatrixInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ interface Props {
fetchFn?: fetchMatrixFn;
disableEdit?: boolean;
enablePercentDisplay?: boolean;
stretch?: boolean;
}

function MatrixInput({
Expand All @@ -51,7 +50,6 @@ function MatrixInput({
fetchFn,
disableEdit,
enablePercentDisplay,
stretch,
}: Props) {
const { enqueueSnackbar } = useSnackbar();
const enqueueErrorSnackbar = useEnqueueErrorSnackbar();
Expand Down Expand Up @@ -213,7 +211,6 @@ function MatrixInput({
onUpdate={handleUpdate}
computStats={computStats}
isPercentDisplayEnabled={enablePercentDisplay}
stretch={stretch}
/>
) : (
!isLoading && (
Expand Down
10 changes: 6 additions & 4 deletions webapp/src/services/api/study.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,11 @@ export const launchStudy = async (
return res.data;
};

interface LauncherLoadDTO {
slurm: number;
local: number;
interface LauncherMetrics {
allocatedCpuRate: number;
clusterLoadRate: number;
nbQueuedJobs: number;
status: string;
}

export const getLauncherVersions = async (): Promise<string[]> => {
Expand All @@ -302,7 +304,7 @@ export const getLauncherCores = async (): Promise<Record<string, number>> => {
return res.data;
};

export const getLauncherLoad = async (): Promise<LauncherLoadDTO> => {
export const getLauncherMetrics = async (): Promise<LauncherMetrics> => {
const res = await client.get("/v1/launcher/load");
return res.data;
};
Expand Down
Loading