Skip to content

Commit

Permalink
Merge branch 'dev' into feat/support-solver-v87
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Feb 27, 2024
2 parents 0b39393 + 8d95e70 commit 87c6114
Show file tree
Hide file tree
Showing 23 changed files with 93 additions and 26 deletions.
4 changes: 2 additions & 2 deletions antarest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

# Standard project metadata

__version__ = "2.16.4"
__version__ = "2.16.5"
__author__ = "RTE, Antares Web Team"
__date__ = "2024-02-14"
__date__ = "2024-02-29"
# noinspection SpellCheckingInspection
__credits__ = "(c) Réseau de Transport de l’Électricité (RTE)"

Expand Down
3 changes: 2 additions & 1 deletion antarest/study/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ class Study(Base): # type: ignore
__mapper_args__ = {"polymorphic_identity": "study", "polymorphic_on": type}

def __str__(self) -> str:
cls = self.__class__.__name__
return (
f"[Study]"
f"[{cls}]"
f" id={self.id},"
f" type={self.type},"
f" name={self.name},"
Expand Down
2 changes: 1 addition & 1 deletion antarest/study/storage/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def update_antares_info(metadata: Study, study_tree: FileStudyTree, *, update_au
study_data_info["antares"]["created"] = metadata.created_at.timestamp()
study_data_info["antares"]["lastsave"] = metadata.updated_at.timestamp()
study_data_info["antares"]["version"] = metadata.version
if update_author:
if update_author and metadata.additional_data:
study_data_info["antares"]["author"] = metadata.additional_data.author
study_tree.save(study_data_info, ["study"])

Expand Down
4 changes: 4 additions & 0 deletions antarest/study/storage/variantstudy/model/dbmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@ def is_snapshot_up_to_date(self) -> bool:
and (self.snapshot.created_at >= self.updated_at)
and (self.snapshot_dir / "study.antares").is_file()
)

def has_snapshot(self) -> bool:
"""Check if the snapshot exists."""
return (self.snapshot is not None) and (self.snapshot_dir / "study.antares").is_file()
2 changes: 1 addition & 1 deletion antarest/study/storage/variantstudy/snapshot_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def search_ref_study(
# To reuse the snapshot of the current variant, the last executed command
# must be one of the commands of the current variant.
curr_variant = descendants[-1]
if curr_variant.snapshot:
if curr_variant.has_snapshot():
last_exec_cmd = curr_variant.snapshot.last_executed_command
command_ids = [c.id for c in curr_variant.commands]
# If the variant has no command, we can reuse the snapshot if it is recent
Expand Down
19 changes: 19 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
Antares Web Changelog
=====================

v2.16.5 (2024-02-29)
--------------------

### Features

* **ui-results:** add results matrix timestamps [`#1945`](https://github.com/AntaresSimulatorTeam/AntaREST/pull/1945)


### Bug Fixes

* **ui-hydro:** disable stretch to fix display issue on some matrices [`#1945`](https://github.com/AntaresSimulatorTeam/AntaREST/pull/1945)
* **ui-hydro:** add missing matrix path encoding [`#1940`](https://github.com/AntaresSimulatorTeam/AntaREST/pull/1940)
* **ui-results:** disable stretch to fix display issue [`#1945`](https://github.com/AntaresSimulatorTeam/AntaREST/pull/1945)
* **ui-results:** prevent duplicate updates on same toggle button click [`#1945`](https://github.com/AntaresSimulatorTeam/AntaREST/pull/1945)
* **ui-thermal:** update cluster group options to handle `Other 1` [`#1945`](https://github.com/AntaresSimulatorTeam/AntaREST/pull/1945)
* **variants:** correct the generation of variant when a snapshot is removed [`#1947`](https://github.com/AntaresSimulatorTeam/AntaREST/pull/1947)
* **study:** correct access to study `additional_data` [`#1949`](https://github.com/AntaresSimulatorTeam/AntaREST/pull/1949)


v2.16.4 (2024-02-14)
--------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="AntaREST",
version="2.16.4",
version="2.16.5",
description="Antares Server",
long_description=Path("README.md").read_text(encoding="utf-8"),
long_description_content_type="text/markdown",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ sonar.exclusions=antarest/gui.py,antarest/main.py
sonar.python.coverage.reportPaths=coverage.xml
sonar.python.version=3.8
sonar.javascript.lcov.reportPaths=webapp/coverage/lcov.info
sonar.projectVersion=2.16.4
sonar.projectVersion=2.16.5
sonar.coverage.exclusions=antarest/gui.py,antarest/main.py,antarest/singleton_services.py,antarest/worker/archive_worker_service.py,webapp/**/*
2 changes: 1 addition & 1 deletion tests/study/storage/variantstudy/model/test_dbmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def test_init__without_snapshot(self, db_session: Session, raw_study_id: str, us
obj: VariantStudy = db_session.query(VariantStudy).filter(VariantStudy.id == variant_study_id).one()

# check Study representation
assert str(obj).startswith(f"[Study] id={variant_study_id}")
assert str(obj).startswith(f"[VariantStudy] id={variant_study_id}")

# check Study fields
assert obj.id == variant_study_id
Expand Down
4 changes: 2 additions & 2 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "antares-web",
"version": "2.16.4",
"version": "2.16.5",
"private": true,
"type": "module",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ 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 @@ -37,6 +37,7 @@ 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 @@ -125,6 +126,7 @@ export const MATRICES: Matrices = {
"Pumping Max Energy (Hours at Pmax)",
],
stats: MatrixStats.NOCOL,
stretch: false,
},
[HydroMatrixType.ReservoirLevels]: {
title: "Reservoir Levels",
Expand Down Expand Up @@ -185,6 +187,7 @@ 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 @@ -16,7 +16,7 @@ export const THERMAL_GROUPS = [
"Mixed fuel",
"Nuclear",
"Oil",
"Other",
"Other 1",
"Other 2",
"Other 3",
"Other 4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import ButtonBack from "../../../../../common/ButtonBack";
import BooleanFE from "../../../../../common/fieldEditors/BooleanFE";
import SelectFE from "../../../../../common/fieldEditors/SelectFE";
import NumberFE from "../../../../../common/fieldEditors/NumberFE";
import moment from "moment";

function ResultDetails() {
const { study } = useOutletContext<{ study: StudyMetadata }>();
Expand Down Expand Up @@ -148,15 +149,27 @@ function ResultDetails() {
},
);

// !NOTE: Workaround to display the date in the correct format, to be replaced by a proper solution.
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]);

////////////////////////////////////////////////////////////////
// Event Handlers
////////////////////////////////////////////////////////////////

const handleItemTypeChange: ToggleButtonGroupProps["onChange"] = (
_,
value: OutputItemType,
newValue: OutputItemType,
) => {
setItemType(value);
if (newValue && newValue !== itemType) {
setItemType(newValue);
}
};

const handleDownload = (matrixData: MatrixType, fileName: string): void => {
Expand Down Expand Up @@ -366,6 +379,8 @@ function ResultDetails() {
<EditableMatrix
matrix={matrix}
matrixTime={false}
rowNames={dateTimeFromIndex}
stretch={false}
readOnly
/>
)
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/components/common/EditableMatrix/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface PropTypes {
rowNames?: string[];
computStats?: MatrixStats;
isPercentDisplayEnabled?: boolean;
stretch?: boolean;
}

type CellType = Array<number | string | boolean>;
Expand Down Expand Up @@ -55,6 +56,7 @@ 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 @@ -176,7 +178,7 @@ function EditableMatrix(props: PropTypes) {
data={grid}
width="100%"
height="100%"
stretchH="all"
stretchH={stretch ? "all" : "none"}
className="editableMatrix"
colHeaders
rowHeaderWidth={matrixRowNames ? 150 : undefined}
Expand All @@ -186,7 +188,6 @@ function EditableMatrix(props: PropTypes) {
beforeKeyDown={(e) => handleKeyDown(e)}
columns={formattedColumns}
rowHeaders={matrixRowNames || true}
manualColumnResize
/>
</Root>
);
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/common/EditableMatrix/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const Root = styled(Box)(({ theme }) => ({
display: "flex",
flexDirection: "column",
alignItems: "center",
overflow: "auto",
overflow: "hidden",
}));

export const StyledButton = styled(Button)(({ theme }) => ({
Expand Down
3 changes: 3 additions & 0 deletions webapp/src/components/common/MatrixInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface Props {
fetchFn?: fetchMatrixFn;
disableEdit?: boolean;
enablePercentDisplay?: boolean;
stretch?: boolean;
}

function MatrixInput({
Expand All @@ -50,6 +51,7 @@ function MatrixInput({
fetchFn,
disableEdit,
enablePercentDisplay,
stretch,
}: Props) {
const { enqueueSnackbar } = useSnackbar();
const enqueueErrorSnackbar = useEnqueueErrorSnackbar();
Expand Down Expand Up @@ -211,6 +213,7 @@ function MatrixInput({
onUpdate={handleUpdate}
computStats={computStats}
isPercentDisplayEnabled={enablePercentDisplay}
stretch={stretch}
/>
) : (
!isLoading && (
Expand Down
9 changes: 5 additions & 4 deletions webapp/src/components/common/fieldEditors/ListFE/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ import reactHookFormSupport, {
import {
createFakeBlurEventHandler,
createFakeChangeEventHandler,
createFakeInputElement,
FakeBlurEventHandler,
FakeChangeEventHandler,
FakeHTMLInputElement,
InputObject,
} from "../../../../utils/feUtils";
import { makeLabel, makeListItems } from "./utils";

Expand Down Expand Up @@ -97,7 +98,7 @@ function ListFE<TItem, TOption>(props: ListFEProps<TItem, TOption>) {
// Trigger event handlers
useUpdateEffect(() => {
if (onChange || onBlur) {
const fakeInputElement: FakeHTMLInputElement = {
const fakeInputElement: InputObject = {
value: listItems.map((item) => item.value),
name,
};
Expand All @@ -108,10 +109,10 @@ function ListFE<TItem, TOption>(props: ListFEProps<TItem, TOption>) {

// Set ref
useEffect(() => {
const fakeInputElement: FakeHTMLInputElement = {
const fakeInputElement = createFakeInputElement({
value: listItems.map((item) => item.value),
name,
};
});
setRef(inputRef, fakeInputElement);
}, [inputRef, listItems, name]);

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/services/api/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const editMatrix = async (
matrixEdit: MatrixEditDTO[],
): Promise<void> => {
const res = await client.put(
`/v1/studies/${sid}/matrix?path=${path}`,
`/v1/studies/${sid}/matrix?path=${encodeURIComponent(path)}`,
matrixEdit,
);
return res.data;
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/services/api/studies/tableMode/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { snakeCase } from "lodash";
import { DeepPartial } from "react-hook-form";
import { StudyMetadata } from "../../../../common/types";
import client from "../../client";
import { format } from "../../../../utils/stringUtils";
import { TABLE_MODE_API_URL } from "../../constants";
import type { TableData, TableModeColumnsForType, TableModeType } from "./type";
import { toColumnApiName } from "./utils";

export async function getTableMode<T extends TableModeType>(
studyId: StudyMetadata["id"],
Expand All @@ -15,7 +15,7 @@ export async function getTableMode<T extends TableModeType>(
const res = await client.get(url, {
params: {
table_type: type,
columns: columns.map(snakeCase).join(","),
columns: columns.map(toColumnApiName).join(","),
},
});
return res.data;
Expand Down
11 changes: 11 additions & 0 deletions webapp/src/services/api/studies/tableMode/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { snakeCase } from "lodash";
import { TableModeColumnsForType, TableModeType } from "./type";

export function toColumnApiName(
column: TableModeColumnsForType<TableModeType>[number],
) {
if (column === "co2") {
return "co2";
}
return snakeCase(column);
}
12 changes: 10 additions & 2 deletions webapp/src/utils/feUtils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { HTMLInputTypeAttribute } from "react";

export interface FakeHTMLInputElement {
export interface InputObject {
value: unknown;
checked?: boolean;
type?: HTMLInputTypeAttribute;
name?: string;
}

type Target = HTMLInputElement | FakeHTMLInputElement;
type Target = HTMLInputElement | InputObject;

export interface FakeChangeEventHandler {
target: Target;
Expand Down Expand Up @@ -36,3 +36,11 @@ export function createFakeBlurEventHandler(
type: "blur",
};
}

export function createFakeInputElement(obj: InputObject): HTMLInputElement {
const inputElement = document.createElement("input");
inputElement.name = obj.name || "";
inputElement.value = obj.value as string;

return inputElement;
}

0 comments on commit 87c6114

Please sign in to comment.