mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-06 08:18:51 -06:00
web: use defaults; calculate table height
This commit is contained in:
@@ -152,6 +152,12 @@ interface BusesTableProps {
|
|||||||
onBusRenamed: (oldName: string, newName: string) => ValidationError | null;
|
onBusRenamed: (oldName: string, newName: string) => ValidationError | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function computeBusesTableHeight(scenario: UnitCommitmentScenario): string {
|
||||||
|
const numBuses = Object.keys(scenario.Buses).length;
|
||||||
|
const height = 65 + Math.min(numBuses, 15) * 28;
|
||||||
|
return `${height}px`;
|
||||||
|
}
|
||||||
|
|
||||||
function BusesTable(props: BusesTableProps) {
|
function BusesTable(props: BusesTableProps) {
|
||||||
const tableContainerRef = useRef<HTMLDivElement | null>(null);
|
const tableContainerRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
@@ -188,7 +194,7 @@ function BusesTable(props: BusesTableProps) {
|
|||||||
layout: "fitColumns",
|
layout: "fitColumns",
|
||||||
data: generateBusesTableData(scenario),
|
data: generateBusesTableData(scenario),
|
||||||
columns: generateBusesTableColumns(scenario),
|
columns: generateBusesTableColumns(scenario),
|
||||||
maxHeight: "500px",
|
height: computeBusesTableHeight(scenario),
|
||||||
});
|
});
|
||||||
table.on("cellEdited", (cell) => {
|
table.on("cellEdited", (cell) => {
|
||||||
onCellEdited(cell);
|
onCellEdited(cell);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import {
|
|||||||
changeTimeHorizon,
|
changeTimeHorizon,
|
||||||
changeTimeStep,
|
changeTimeStep,
|
||||||
} from "../../core/Operations/parameterOperations";
|
} from "../../core/Operations/parameterOperations";
|
||||||
|
import { preprocess } from "../../core/Operations/preprocessing";
|
||||||
|
|
||||||
const CaseBuilder = () => {
|
const CaseBuilder = () => {
|
||||||
const [scenario, setScenario] = useState(TEST_SCENARIO);
|
const [scenario, setScenario] = useState(TEST_SCENARIO);
|
||||||
@@ -87,11 +88,16 @@ const CaseBuilder = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onLoad = (scenario: UnitCommitmentScenario) => {
|
const onLoad = (scenario: UnitCommitmentScenario) => {
|
||||||
if (!validate(scenario)) {
|
const preprocessed = preprocess(
|
||||||
|
scenario,
|
||||||
|
) as unknown as UnitCommitmentScenario;
|
||||||
|
|
||||||
|
// Validate and assign default values
|
||||||
|
if (!validate(preprocessed)) {
|
||||||
console.error(validate.errors);
|
console.error(validate.errors);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setScenario(scenario);
|
setScenario(preprocessed);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onParameterChanged = (key: string, value: string) => {
|
const onParameterChanged = (key: string, value: string) => {
|
||||||
|
|||||||
39
web/src/core/Operations/preprocessing.test.ts
Normal file
39
web/src/core/Operations/preprocessing.test.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||||
|
* Copyright (C) 2020-2025, UChicago Argonne, LLC. All rights reserved.
|
||||||
|
* Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import assert from "node:assert";
|
||||||
|
import { preprocess } from "./preprocessing";
|
||||||
|
|
||||||
|
export const PREPROCESSING_TEST_DATA_1: any = {
|
||||||
|
Parameters: {
|
||||||
|
Version: "0.4",
|
||||||
|
"Time horizon (h)": 5,
|
||||||
|
},
|
||||||
|
Buses: {
|
||||||
|
b1: { "Load (MW)": [35.79534, 34.38835, 33.45083, 32.89729, 33.25044] },
|
||||||
|
b2: { "Load (MW)": 10 },
|
||||||
|
b3: { "Load (MW)": [27.3729, 26.29698, 25.58005, 25.15675, 25.4268] },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
test("preprocess", () => {
|
||||||
|
const newScenario = preprocess(PREPROCESSING_TEST_DATA_1);
|
||||||
|
assert.deepEqual(newScenario, {
|
||||||
|
Parameters: {
|
||||||
|
Version: "0.4",
|
||||||
|
"Time horizon (h)": 5,
|
||||||
|
"Power balance penalty ($/MW)": 1000,
|
||||||
|
"Scenario name": "s1",
|
||||||
|
"Scenario weight": 1,
|
||||||
|
"Time step (min)": 60,
|
||||||
|
},
|
||||||
|
Buses: {
|
||||||
|
b1: { "Load (MW)": [35.79534, 34.38835, 33.45083, 32.89729, 33.25044] },
|
||||||
|
b2: { "Load (MW)": [10, 10, 10, 10, 10] },
|
||||||
|
b3: { "Load (MW)": [27.3729, 26.29698, 25.58005, 25.15675, 25.4268] },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
34
web/src/core/Operations/preprocessing.ts
Normal file
34
web/src/core/Operations/preprocessing.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// @ts-nocheck
|
||||||
|
|
||||||
|
/*
|
||||||
|
* UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||||
|
* Copyright (C) 2020-2025, UChicago Argonne, LLC. All rights reserved.
|
||||||
|
* Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { validate } from "../Validation/validate";
|
||||||
|
|
||||||
|
export const preprocess = (data) => {
|
||||||
|
// Make a copy of the original data
|
||||||
|
let result = JSON.parse(JSON.stringify(data));
|
||||||
|
|
||||||
|
// Run JSON validation and assign default values
|
||||||
|
if (!validate(result)) {
|
||||||
|
console.error(validate.errors);
|
||||||
|
throw Error("Invalid JSON");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expand scalars into arrays
|
||||||
|
const timeHorizon = result["Parameters"]["Time horizon (h)"];
|
||||||
|
const timeStep = result["Parameters"]["Time step (min)"];
|
||||||
|
const T = (timeHorizon * 60) / timeStep;
|
||||||
|
for (const busName in result["Buses"]) {
|
||||||
|
// @ts-ignore
|
||||||
|
const busData = result["Buses"][busName];
|
||||||
|
const busLoad = busData["Load (MW)"];
|
||||||
|
if (typeof busLoad === "number") {
|
||||||
|
busData["Load (MW)"] = Array(T).fill(busLoad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
@@ -9,6 +9,7 @@ import Ajv from "ajv";
|
|||||||
|
|
||||||
// Create Ajv instance with detailed debug options
|
// Create Ajv instance with detailed debug options
|
||||||
const ajv = new Ajv({
|
const ajv = new Ajv({
|
||||||
|
useDefaults: true,
|
||||||
verbose: true,
|
verbose: true,
|
||||||
allErrors: true,
|
allErrors: true,
|
||||||
$data: true,
|
$data: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user