Validation; reformat source code

web
Alinson S. Xavier 4 months ago
parent 062b38514b
commit 6469840f0a

11
.gitignore vendored

@ -1,3 +1,4 @@
*-off.md
*.bak *.bak
*.gz *.gz
*.ipynb *.ipynb
@ -19,6 +20,7 @@
.apdisk .apdisk
.com.apple.timemachine.donotpresent .com.apple.timemachine.donotpresent
.fseventsd .fseventsd
.idea
.ipy* .ipy*
.vscode .vscode
Icon Icon
@ -32,12 +34,11 @@ benchmark/tables
benchmark/tmp.json benchmark/tmp.json
build build
docs/_build docs/_build
docs/src/tutorials/customizing.md
docs/src/tutorials/lmp.md
docs/src/tutorials/market.md
docs/src/tutorials/usage.md
instances/**/*.json instances/**/*.json
instances/_source instances/_source
local local
notebooks notebooks
docs/src/tutorials/usage.md
docs/src/tutorials/customizing.md
docs/src/tutorials/market.md
docs/src/tutorials/lmp.md
*-off.md

5479
web/package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -16,8 +16,8 @@
"@types/papaparse": "^5.3.16", "@types/papaparse": "^5.3.16",
"@types/react": "^19.1.3", "@types/react": "^19.1.3",
"@types/react-dom": "^19.1.3", "@types/react-dom": "^19.1.3",
"@typescript-eslint/utils": "^8.32.1",
"ajv": "^8.17.1", "ajv": "^8.17.1",
"eslint": "^8.57.1",
"papaparse": "^5.5.2", "papaparse": "^5.5.2",
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0", "react-dom": "^19.1.0",
@ -58,6 +58,6 @@
}, },
"devDependencies": { "devDependencies": {
"@types/tabulator-tables": "^6.2.6", "@types/tabulator-tables": "^6.2.6",
"eslint": "^8.57.1" "prettier": "3.5.3"
} }
} }

@ -1,14 +1,11 @@
<!DOCTYPE html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" /> <meta name="theme-color" content="#000000" />
<meta <meta name="description" content="UnitCommitment.jl Case Builder" />
name="description"
content="UnitCommitment.jl Case Builder"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>Case Builder - UnitCommitment.jl</title> <title>Case Builder - UnitCommitment.jl</title>

@ -4,22 +4,27 @@
* Released under the modified BSD license. See COPYING.md for more details. * Released under the modified BSD license. See COPYING.md for more details.
*/ */
import {UnitCommitmentScenario} from "../../../core/data"; import { UnitCommitmentScenario } from "../../../core/data";
import {changeBusData, createBus, deleteBus, renameBus} from "./BusOperations"; import {
changeBusData,
createBus,
deleteBus,
renameBus,
} from "./BusOperations";
import assert from "node:assert"; import assert from "node:assert";
export const BUS_TEST_DATA_1: UnitCommitmentScenario = { export const BUS_TEST_DATA_1: UnitCommitmentScenario = {
"Parameters": { Parameters: {
"Version": "0.4", Version: "0.4",
"Power balance penalty ($/MW)": 1000.0, "Power balance penalty ($/MW)": 1000.0,
"Time horizon (h)": 5, "Time horizon (h)": 5,
"Time step (min)": 60, "Time step (min)": 60,
}, },
"Buses": { Buses: {
"b1": {"Load (MW)": [35.79534, 34.38835, 33.45083, 32.89729, 33.25044]}, b1: { "Load (MW)": [35.79534, 34.38835, 33.45083, 32.89729, 33.25044] },
"b2": {"Load (MW)": [14.03739, 13.48563, 13.11797, 12.9009, 13.03939]}, b2: { "Load (MW)": [14.03739, 13.48563, 13.11797, 12.9009, 13.03939] },
"b3": {"Load (MW)": [27.3729, 26.29698, 25.58005, 25.15675, 25.4268]}, b3: { "Load (MW)": [27.3729, 26.29698, 25.58005, 25.15675, 25.4268] },
} },
}; };
test("createBus", () => { test("createBus", () => {
@ -29,56 +34,75 @@ test("createBus", () => {
test("changeBusData", () => { test("changeBusData", () => {
let scenario = BUS_TEST_DATA_1; let scenario = BUS_TEST_DATA_1;
scenario = changeBusData("b1", "Load 0", "99", scenario); let err = null;
scenario = changeBusData("b1", "Load 3", "99", scenario);
scenario = changeBusData("b3", "Load 4", "99", scenario); [scenario, err] = changeBusData("b1", "Load 0", "99", scenario);
assert.equal(err, null);
[scenario, err] = changeBusData("b1", "Load 3", "99", scenario);
assert.equal(err, null);
[scenario, err] = changeBusData("b3", "Load 4", "99", scenario);
assert.equal(err, null);
assert.deepEqual(scenario, { assert.deepEqual(scenario, {
"Parameters": { Parameters: {
"Version": "0.4", Version: "0.4",
"Power balance penalty ($/MW)": 1000.0, "Power balance penalty ($/MW)": 1000.0,
"Time horizon (h)": 5, "Time horizon (h)": 5,
"Time step (min)": 60, "Time step (min)": 60,
}, },
"Buses": { Buses: {
"b1": {"Load (MW)": [99, 34.38835, 33.45083, 99, 33.25044]}, b1: { "Load (MW)": [99, 34.38835, 33.45083, 99, 33.25044] },
"b2": {"Load (MW)": [14.03739, 13.48563, 13.11797, 12.9009, 13.03939]}, b2: { "Load (MW)": [14.03739, 13.48563, 13.11797, 12.9009, 13.03939] },
"b3": {"Load (MW)": [27.3729, 26.29698, 25.58005, 25.15675, 99]}, b3: { "Load (MW)": [27.3729, 26.29698, 25.58005, 25.15675, 99] },
} },
}); });
}); });
test("changeBusData with invalid numbers", () => {
let [, err] = changeBusData("b1", "Load 0", "xx", BUS_TEST_DATA_1);
assert(err !== null);
assert.equal(err.message, "Invalid value: xx");
});
test("deleteBus", () => { test("deleteBus", () => {
let scenario = BUS_TEST_DATA_1; let scenario = BUS_TEST_DATA_1;
scenario = deleteBus("b2", scenario); scenario = deleteBus("b2", scenario);
assert.deepEqual(scenario, { assert.deepEqual(scenario, {
"Parameters": { Parameters: {
"Version": "0.4", Version: "0.4",
"Power balance penalty ($/MW)": 1000.0, "Power balance penalty ($/MW)": 1000.0,
"Time horizon (h)": 5, "Time horizon (h)": 5,
"Time step (min)": 60, "Time step (min)": 60,
}, },
"Buses": { Buses: {
"b1": {"Load (MW)": [35.79534, 34.38835, 33.45083, 32.89729, 33.25044]}, b1: { "Load (MW)": [35.79534, 34.38835, 33.45083, 32.89729, 33.25044] },
"b3": {"Load (MW)": [27.3729, 26.29698, 25.58005, 25.15675, 25.4268]}, b3: { "Load (MW)": [27.3729, 26.29698, 25.58005, 25.15675, 25.4268] },
} },
}); });
}); });
test("renameBus", () => { test("renameBus", () => {
let scenario = BUS_TEST_DATA_1; let [scenario, err] = renameBus("b2", "b99", BUS_TEST_DATA_1);
scenario = renameBus("b2", "b99", scenario); assert(err === null);
assert.deepEqual(scenario, { assert.deepEqual(scenario, {
"Parameters": { Parameters: {
"Version": "0.4", Version: "0.4",
"Power balance penalty ($/MW)": 1000.0, "Power balance penalty ($/MW)": 1000.0,
"Time horizon (h)": 5, "Time horizon (h)": 5,
"Time step (min)": 60, "Time step (min)": 60,
}, },
"Buses": { Buses: {
"b1": {"Load (MW)": [35.79534, 34.38835, 33.45083, 32.89729, 33.25044]}, b1: { "Load (MW)": [35.79534, 34.38835, 33.45083, 32.89729, 33.25044] },
"b99": {"Load (MW)": [14.03739, 13.48563, 13.11797, 12.9009, 13.03939]}, b99: { "Load (MW)": [14.03739, 13.48563, 13.11797, 12.9009, 13.03939] },
"b3": {"Load (MW)": [27.3729, 26.29698, 25.58005, 25.15675, 25.4268]}, b3: { "Load (MW)": [27.3729, 26.29698, 25.58005, 25.15675, 25.4268] },
} },
}); });
}); });
test("renameBus with duplicated name", () => {
let [, err] = renameBus("b3", "b1", BUS_TEST_DATA_1);
assert(err != null);
assert.equal(err.message, `Bus b1 already exists`);
});

@ -4,9 +4,10 @@
* Released under the modified BSD license. See COPYING.md for more details. * Released under the modified BSD license. See COPYING.md for more details.
*/ */
import {Buses, UnitCommitmentScenario} from "../../../core/data"; import { Buses, UnitCommitmentScenario } from "../../../core/data";
import { ValidationError } from "../../../core/Validation/validate";
function generateUniqueBusName(scenario: UnitCommitmentScenario) { const generateUniqueBusName = (scenario: UnitCommitmentScenario) => {
let newBusName = "b"; let newBusName = "b";
let counter = 1; let counter = 1;
let name = `${newBusName}${counter}`; let name = `${newBusName}${counter}`;
@ -15,67 +16,91 @@ function generateUniqueBusName(scenario: UnitCommitmentScenario) {
name = `${newBusName}${counter}`; name = `${newBusName}${counter}`;
} }
return name; return name;
} };
function generateDefaultBusLoad(scenario: UnitCommitmentScenario) { const generateDefaultBusLoad = (scenario: UnitCommitmentScenario) => {
const T = scenario.Parameters["Time horizon (h)"] * (60 / scenario.Parameters["Time step (min)"]); const T =
scenario.Parameters["Time horizon (h)"] *
(60 / scenario.Parameters["Time step (min)"]);
return new Array(T).fill(0); return new Array(T).fill(0);
} };
export function createBus(scenario: UnitCommitmentScenario) { export const createBus = (scenario: UnitCommitmentScenario) => {
const load = generateDefaultBusLoad(scenario); const load = generateDefaultBusLoad(scenario);
let name = generateUniqueBusName(scenario); let name = generateUniqueBusName(scenario);
return { return {
...scenario, ...scenario,
"Buses": { Buses: {
...scenario.Buses, ...scenario.Buses,
[name]: { [name]: {
"Load (MW)": load "Load (MW)": load,
} },
} },
}; };
} };
export function changeBusData(bus: string, field: string, newValue: string, scenario: UnitCommitmentScenario) { export const changeBusData = (
bus: string,
field: string,
newValueStr: string,
scenario: UnitCommitmentScenario,
): [UnitCommitmentScenario, ValidationError | null] => {
// Load (MW) // Load (MW)
const match = field.match(/Load (\d+)/); const match = field.match(/Load (\d+)/);
if(match) { if (match) {
const newValueFloat = parseFloat(newValueStr);
if (isNaN(newValueFloat)) {
return [scenario, { message: `Invalid value: ${newValueStr}` }];
}
const idx = parseInt(match[1]!, 10); const idx = parseInt(match[1]!, 10);
const newLoad = [...scenario.Buses[bus]!["Load (MW)"]]; const newLoad = [...scenario.Buses[bus]!["Load (MW)"]];
newLoad[idx] = parseFloat(newValue); newLoad[idx] = newValueFloat;
return { return [
{
...scenario, ...scenario,
Buses: { Buses: {
...scenario.Buses, ...scenario.Buses,
[bus]: { [bus]: {
"Load (MW)": newLoad, "Load (MW)": newLoad,
} },
} },
}; },
null,
];
} }
throw Error(`Unknown field: ${field}`); throw Error(`Unknown field: ${field}`);
} };
export function deleteBus(bus: string, scenario: UnitCommitmentScenario) { export const deleteBus = (bus: string, scenario: UnitCommitmentScenario) => {
const { [bus]: _, ...newBuses} = scenario.Buses; const { [bus]: _, ...newBuses } = scenario.Buses;
return { return {
...scenario, ...scenario,
Buses: newBuses Buses: newBuses,
}; };
} };
export function renameBus(oldName: string, newName: string, scenario: UnitCommitmentScenario) { export const renameBus = (
oldName: string,
newName: string,
scenario: UnitCommitmentScenario,
): [UnitCommitmentScenario, ValidationError | null] => {
if (newName in scenario.Buses) {
return [scenario, { message: `Bus ${newName} already exists` }];
}
const newBuses: Buses = Object.keys(scenario.Buses).reduce((acc, val) => { const newBuses: Buses = Object.keys(scenario.Buses).reduce((acc, val) => {
if(val === oldName) { if (val === oldName) {
acc[newName] = scenario.Buses[val]!; acc[newName] = scenario.Buses[val]!;
} else { } else {
acc[val] = scenario.Buses[val]!; acc[val] = scenario.Buses[val]!;
} }
return acc; return acc;
}, {} as Buses); }, {} as Buses);
return { return [
{
...scenario, ...scenario,
Buses: newBuses Buses: newBuses,
}; },
} null,
];
};

@ -1,58 +0,0 @@
/*
* 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 SectionHeader from "../../Common/SectionHeader/SectionHeader";
import {UnitCommitmentScenario} from "../../../core/data";
import BusesTable, {generateBusesCsv, parseBusesCsv} from "./BusesTable";
import SectionButton from "../../Common/Buttons/SectionButton";
import {faDownload, faPlus, faUpload} from "@fortawesome/free-solid-svg-icons";
import {offerDownload} from "../../Common/io";
import FileUploadElement from "../../Common/Buttons/FileUploadElement";
import {useRef} from "react";
interface BusesProps {
scenario: UnitCommitmentScenario,
onBusCreated: () => void,
onBusDataChanged: (bus: string, field: string, newValue: string) => void,
onBusDeleted: (bus: string) => void,
onBusRenamed: (oldName: string, newName: string) => void,
onDataChanged: (scenario: UnitCommitmentScenario) => void,
}
function BusesComponent(props: BusesProps) {
const fileUploadElem = useRef<FileUploadElement>(null);
const onDownload = () => {
const csvContents = generateBusesCsv(props.scenario);
offerDownload(csvContents, "text/csv", "buses.csv");
};
const onUpload = () => {
fileUploadElem.current!.showFilePicker((csvContents: any) => {
const newScenario = parseBusesCsv(props.scenario, csvContents);
props.onDataChanged(newScenario);
});
};
return (
<div>
<SectionHeader title="Buses">
<SectionButton icon={faPlus} tooltip="Add" onClick={props.onBusCreated}/>
<SectionButton icon={faDownload} tooltip="Download" onClick={onDownload}/>
<SectionButton icon={faUpload} tooltip="Upload" onClick={onUpload}/>
</SectionHeader>
<BusesTable
scenario={props.scenario}
onBusDataChanged={props.onBusDataChanged}
onBusDeleted={props.onBusDeleted}
onBusRenamed={props.onBusRenamed}
/>
<FileUploadElement ref={fileUploadElem} accept=".csv"/>
</div>
);
}
export default BusesComponent;

@ -0,0 +1,75 @@
/*
* 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 SectionHeader from "../../Common/SectionHeader/SectionHeader";
import { UnitCommitmentScenario } from "../../../core/data";
import BusesTable, { generateBusesCsv, parseBusesCsv } from "./BusesTable";
import SectionButton from "../../Common/Buttons/SectionButton";
import {
faDownload,
faPlus,
faUpload,
} from "@fortawesome/free-solid-svg-icons";
import { offerDownload } from "../../Common/io";
import FileUploadElement from "../../Common/Buttons/FileUploadElement";
import { useRef } from "react";
import { ValidationError } from "../../../core/Validation/validate";
interface BusesProps {
scenario: UnitCommitmentScenario;
onBusCreated: () => void;
onBusDataChanged: (
bus: string,
field: string,
newValue: string,
) => ValidationError | null;
onBusDeleted: (bus: string) => void;
onBusRenamed: (oldName: string, newName: string) => ValidationError | null;
onDataChanged: (scenario: UnitCommitmentScenario) => void;
}
function BusesComponent(props: BusesProps) {
const fileUploadElem = useRef<FileUploadElement>(null);
const onDownload = () => {
const csvContents = generateBusesCsv(props.scenario);
offerDownload(csvContents, "text/csv", "buses.csv");
};
const onUpload = () => {
fileUploadElem.current!.showFilePicker((csvContents: any) => {
const newScenario = parseBusesCsv(props.scenario, csvContents);
props.onDataChanged(newScenario);
});
};
return (
<div>
<SectionHeader title="Buses">
<SectionButton
icon={faPlus}
tooltip="Add"
onClick={props.onBusCreated}
/>
<SectionButton
icon={faDownload}
tooltip="Download"
onClick={onDownload}
/>
<SectionButton icon={faUpload} tooltip="Upload" onClick={onUpload} />
</SectionHeader>
<BusesTable
scenario={props.scenario}
onBusDataChanged={props.onBusDataChanged}
onBusDeleted={props.onBusDeleted}
onBusRenamed={props.onBusRenamed}
/>
<FileUploadElement ref={fileUploadElem} accept=".csv" />
</div>
);
}
export default BusesComponent;

@ -5,8 +5,8 @@
*/ */
import assert from "node:assert"; import assert from "node:assert";
import {generateBusesCsv, parseBusesCsv} from "./BusesTable"; import { generateBusesCsv, parseBusesCsv } from "./BusesTable";
import {BUS_TEST_DATA_1} from "./BusOperations.test"; import { BUS_TEST_DATA_1 } from "./BusOperations.test";
test("generate CSV", () => { test("generate CSV", () => {
const actualCsv = generateBusesCsv(BUS_TEST_DATA_1); const actualCsv = generateBusesCsv(BUS_TEST_DATA_1);
@ -25,26 +25,13 @@ test("parse valid CSV", () => {
"b3,27.3729,26.29698,25.58005,25.15675,25.4268"; "b3,27.3729,26.29698,25.58005,25.15675,25.4268";
const newScenario = parseBusesCsv(BUS_TEST_DATA_1, csvContents); const newScenario = parseBusesCsv(BUS_TEST_DATA_1, csvContents);
assert.deepEqual(newScenario.Buses, { assert.deepEqual(newScenario.Buses, {
"b1": { b1: {
"Load (MW)": [ "Load (MW)": [0, 1, 2, 3, 4],
0,
1,
2,
3,
4,
]
}, },
"b3": { b3: {
"Load (MW)": [ "Load (MW)": [27.3729, 26.29698, 25.58005, 25.15675, 25.4268],
27.3729,
26.29698,
25.58005,
25.15675,
25.4268,
]
}, },
}); });
}); });
test("parse invalid CSV (wrong headers)", () => { test("parse invalid CSV (wrong headers)", () => {

@ -4,10 +4,15 @@
* Released under the modified BSD license. See COPYING.md for more details. * Released under the modified BSD license. See COPYING.md for more details.
*/ */
import Papa from 'papaparse'; import Papa from "papaparse";
import {Buses, UnitCommitmentScenario} from "../../../core/data"; import { Buses, UnitCommitmentScenario } from "../../../core/data";
import {useEffect, useRef} from "react"; import { useEffect, useRef } from "react";
import {CellComponent, ColumnDefinition, TabulatorFull as Tabulator} from "tabulator-tables"; import {
CellComponent,
ColumnDefinition,
TabulatorFull as Tabulator,
} from "tabulator-tables";
import { ValidationError } from "../../../core/Validation/validate";
const generateBusesTableData = (scenario: UnitCommitmentScenario) => { const generateBusesTableData = (scenario: UnitCommitmentScenario) => {
const tableData: { [name: string]: any }[] = []; const tableData: { [name: string]: any }[] = [];
@ -22,7 +27,9 @@ const generateBusesTableData = (scenario: UnitCommitmentScenario) => {
return tableData; return tableData;
}; };
const generateBusesTableColumns = (scenario: UnitCommitmentScenario): [ColumnDefinition] => { const generateBusesTableColumns = (
scenario: UnitCommitmentScenario,
): [ColumnDefinition] => {
const timeHorizonHours = scenario["Parameters"]["Time horizon (h)"]; const timeHorizonHours = scenario["Parameters"]["Time horizon (h)"];
const timeStepMin = scenario["Parameters"]["Time step (min)"]; const timeStepMin = scenario["Parameters"]["Time step (min)"];
const columnsCommonAttrs: ColumnDefinition = { const columnsCommonAttrs: ColumnDefinition = {
@ -46,10 +53,14 @@ const generateBusesTableColumns = (scenario: UnitCommitmentScenario): [ColumnDef
width: 150, width: 150,
}, },
]; ];
for (let m = 0, offset = 0; m < timeHorizonHours * 60; m += timeStepMin, offset += 1) { for (
let m = 0, offset = 0;
m < timeHorizonHours * 60;
m += timeStepMin, offset += 1
) {
const hours = Math.floor(m / 60); const hours = Math.floor(m / 60);
const mins = m % 60; const mins = m % 60;
const formattedTime = `${String(hours).padStart(2, '0')}:${String(mins).padStart(2, '0')}`; const formattedTime = `${String(hours).padStart(2, "0")}:${String(mins).padStart(2, "0")}`;
columns.push({ columns.push({
...columnsCommonAttrs, ...columnsCommonAttrs,
title: `Load (MW)<div class="subtitle">${formattedTime}</div>`, title: `Load (MW)<div class="subtitle">${formattedTime}</div>`,
@ -62,24 +73,33 @@ const generateBusesTableColumns = (scenario: UnitCommitmentScenario): [ColumnDef
export const generateBusesCsv = (scenario: UnitCommitmentScenario) => { export const generateBusesCsv = (scenario: UnitCommitmentScenario) => {
const columns = generateBusesTableColumns(scenario); const columns = generateBusesTableColumns(scenario);
const csvHeader = columns.map(row => row.field).join(","); const csvHeader = columns.map((row) => row.field).join(",");
const csvBody = Object.entries(scenario.Buses).map(([busName, busData]) => { const csvBody = Object.entries(scenario.Buses)
.map(([busName, busData]) => {
const csvLoad = busData["Load (MW)"].join(","); const csvLoad = busData["Load (MW)"].join(",");
return `${busName},${csvLoad}`; return `${busName},${csvLoad}`;
}).join("\n"); })
.join("\n");
return `${csvHeader}\n${csvBody}`; return `${csvHeader}\n${csvBody}`;
}; };
function getNumTimesteps(scenario: UnitCommitmentScenario) { function getNumTimesteps(scenario: UnitCommitmentScenario) {
return scenario.Parameters["Time horizon (h)"] * scenario.Parameters["Time step (min)"] / 60; return (
(scenario.Parameters["Time horizon (h)"] *
scenario.Parameters["Time step (min)"]) /
60
);
} }
export const parseBusesCsv = (scenario: UnitCommitmentScenario, csvData: string): UnitCommitmentScenario => { export const parseBusesCsv = (
scenario: UnitCommitmentScenario,
csvData: string,
): UnitCommitmentScenario => {
const results = Papa.parse(csvData, { const results = Papa.parse(csvData, {
header: true, header: true,
skipEmptyLines: true, skipEmptyLines: true,
transformHeader: (header) => header.trim(), transformHeader: (header) => header.trim(),
transform: (value) => value.trim() transform: (value) => value.trim(),
}); });
// Check for parsing errors // Check for parsing errors
@ -88,7 +108,9 @@ export const parseBusesCsv = (scenario: UnitCommitmentScenario, csvData: string)
} }
// Check CSV headers // Check CSV headers
const expectedFields = generateBusesTableColumns(scenario).map(col => col.field)!; const expectedFields = generateBusesTableColumns(scenario).map(
(col) => col.field,
)!;
const actualFields = results.meta.fields!; const actualFields = results.meta.fields!;
for (let i = 0; i < expectedFields.length; i++) { for (let i = 0; i < expectedFields.length; i++) {
if (expectedFields[i] !== actualFields[i]) { if (expectedFields[i] !== actualFields[i]) {
@ -107,7 +129,7 @@ export const parseBusesCsv = (scenario: UnitCommitmentScenario, csvData: string)
busLoad[j] = parseFloat(row[`Load ${j}`]); busLoad[j] = parseFloat(row[`Load ${j}`]);
} }
buses[busName] = { buses[busName] = {
"Load (MW)": busLoad "Load (MW)": busLoad,
}; };
} }
return { return {
@ -117,61 +139,60 @@ export const parseBusesCsv = (scenario: UnitCommitmentScenario, csvData: string)
}; };
interface BusesTableProps { interface BusesTableProps {
scenario: UnitCommitmentScenario scenario: UnitCommitmentScenario;
onBusDataChanged: (bus: string, field: string, newValue: string) => void, onBusDataChanged: (
onBusDeleted: (bus: string) => void, bus: string,
onBusRenamed: (oldName: string, newName: string) => void, field: string,
newValue: string,
) => ValidationError | null;
onBusDeleted: (bus: string) => void;
onBusRenamed: (oldName: string, newName: string) => ValidationError | null;
} }
function BusesTable(props: BusesTableProps) { function BusesTable(props: BusesTableProps) {
const tableContainerRef = useRef<HTMLDivElement | null>(null); const tableContainerRef = useRef<HTMLDivElement | null>(null);
useEffect(() => { useEffect(() => {
const scenario = props.scenario;
const onCellEdited = (cell: CellComponent) => { const onCellEdited = (cell: CellComponent) => {
let newValue = cell.getValue(); let newValue = cell.getValue();
let oldValue = cell.getOldValue(); let oldValue = cell.getOldValue();
if (newValue === oldValue) return; // eslint-disable-next-line eqeqeq
if (newValue == oldValue) return;
if (cell.getField() === "Name") { if (cell.getField() === "Name") {
if (newValue === "") { if (newValue === "") {
props.onBusDeleted(oldValue); props.onBusDeleted(oldValue);
cell.getRow().delete(); cell.getRow().delete();
} else { } else {
props.onBusRenamed( const err = props.onBusRenamed(oldValue, newValue);
oldValue, if (err) {
newValue, cell.restoreOldValue();
); }
} }
} else { } else {
const row = cell.getRow().getData(); const row = cell.getRow().getData();
const bus = row["Name"]; const bus = row["Name"];
props.onBusDataChanged( const err = props.onBusDataChanged(bus, cell.getField(), newValue);
bus, cell.getField(), newValue if (err) {
); cell.restoreOldValue();
}
} }
}; };
if (tableContainerRef.current === null) return; if (tableContainerRef.current === null) return;
const table = new Tabulator(tableContainerRef.current, { const table = new Tabulator(tableContainerRef.current, {
layout: "fitColumns", layout: "fitColumns",
data: generateBusesTableData(props.scenario), data: generateBusesTableData(scenario),
columns: generateBusesTableColumns(props.scenario), columns: generateBusesTableColumns(scenario),
maxHeight: "500px", maxHeight: "500px",
}); });
table.on("cellEdited", (cell) => { table.on("cellEdited", (cell) => {
onCellEdited(cell); onCellEdited(cell);
}); });
table.on("cellEditing", (cell) => { }, [props]);
});
// table.on("scrollHorizontal", (left, leftDir) => { return <div className="tableContainer" ref={tableContainerRef} />;
// console.log(left, leftDir);
// });
table.rowManager.scrollHorizontal(100, false);
// table.columnManager.scrollHorizontal(100, false);
}, [props, props.scenario]);
return <div className="tableContainer" ref={tableContainerRef}/>;
} }
export default BusesTable; export default BusesTable;

@ -6,16 +6,25 @@
import Header from "./Header/Header"; import Header from "./Header/Header";
import Parameters from "./Parameters/Parameters"; import Parameters from "./Parameters/Parameters";
import BusesComponent from "./Buses/Buses"; import BusesComponent from "./Buses/BusesComponent";
import {BLANK_SCENARIO, TEST_SCENARIO, UnitCommitmentScenario} from "../../core/data"; import {
BLANK_SCENARIO,
TEST_SCENARIO,
UnitCommitmentScenario,
} from "../../core/data";
import "tabulator-tables/dist/css/tabulator.min.css"; import "tabulator-tables/dist/css/tabulator.min.css";
import "../Common/Forms/Tables.css"; import "../Common/Forms/Tables.css";
import {useState} from "react"; import { useState } from "react";
import Footer from "./Footer/Footer"; import Footer from "./Footer/Footer";
import {validate} from "../../core/Validation/validate"; import { validate, ValidationError } from "../../core/Validation/validate";
import {offerDownload} from "../Common/io"; import { offerDownload } from "../Common/io";
import {changeBusData, createBus, deleteBus, renameBus} from "./Buses/BusOperations"; import {
changeBusData,
createBus,
deleteBus,
renameBus,
} from "./Buses/BusOperations";
const CaseBuilder = () => { const CaseBuilder = () => {
const [scenario, setScenario] = useState(TEST_SCENARIO); const [scenario, setScenario] = useState(TEST_SCENARIO);
@ -27,8 +36,8 @@ const CaseBuilder = () => {
const onSave = () => { const onSave = () => {
offerDownload( offerDownload(
JSON.stringify(scenario, null, 2), JSON.stringify(scenario, null, 2),
'application/json', "application/json",
'case.json', "case.json",
); );
}; };
@ -37,9 +46,18 @@ const CaseBuilder = () => {
setScenario(newScenario); setScenario(newScenario);
}; };
const onBusDataChanged = (bus: string, field: string, newValue: string) => { const onBusDataChanged = (
const newScenario = changeBusData(bus, field, newValue, scenario); bus: string,
field: string,
newValue: string,
): ValidationError | null => {
const [newScenario, err] = changeBusData(bus, field, newValue, scenario);
if (err) {
console.log(err);
return err;
}
setScenario(newScenario); setScenario(newScenario);
return null;
}; };
const onBusDeleted = (bus: string) => { const onBusDeleted = (bus: string) => {
@ -47,9 +65,17 @@ const CaseBuilder = () => {
setScenario(newScenario); setScenario(newScenario);
}; };
const onBusRenamed = (oldName: string, newName: string) => { const onBusRenamed = (
const newScenario = renameBus(oldName, newName, scenario); oldName: string,
newName: string,
): ValidationError | null => {
const [newScenario, err] = renameBus(oldName, newName, scenario);
if (err) {
console.log(err);
return err;
}
setScenario(newScenario); setScenario(newScenario);
return null;
}; };
const onDataChanged = (newScenario: UnitCommitmentScenario) => { const onDataChanged = (newScenario: UnitCommitmentScenario) => {
@ -64,14 +90,11 @@ const CaseBuilder = () => {
setScenario(scenario); setScenario(scenario);
}; };
return <div> return (
<Header <div>
onClear={onClear} <Header onClear={onClear} onSave={onSave} onLoad={onLoad} />
onSave={onSave}
onLoad={onLoad}
/>
<div className="content"> <div className="content">
<Parameters scenario={scenario}/> <Parameters scenario={scenario} />
<BusesComponent <BusesComponent
scenario={scenario} scenario={scenario}
onBusCreated={onBusCreated} onBusCreated={onBusCreated}
@ -81,8 +104,9 @@ const CaseBuilder = () => {
onDataChanged={onDataChanged} onDataChanged={onDataChanged}
/> />
</div> </div>
<Footer/> <Footer />
</div>; </div>
);
}; };
export default CaseBuilder; export default CaseBuilder;

@ -9,7 +9,8 @@ import styles from "./Footer.module.css";
function Footer() { function Footer() {
return ( return (
<div className={styles.Footer}> <div className={styles.Footer}>
UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment <br/> UnitCommitment.jl: Optimization Package for Security-Constrained Unit
Commitment <br />
Copyright (C) 2020-2025, UChicago Argonne, LLC. All rights reserved. Copyright (C) 2020-2025, UChicago Argonne, LLC. All rights reserved.
</div> </div>
); );

@ -18,7 +18,8 @@
min-width: var(--site-min-width); min-width: var(--site-min-width);
} }
.HeaderContent h1, h2 { .HeaderContent h1,
h2 {
color: var(--contrast-100); color: var(--contrast-100);
display: inline-block; display: inline-block;
line-height: 48px; line-height: 48px;
@ -38,5 +39,3 @@
float: right; float: right;
padding: 16px 12px; padding: 16px 12px;
} }

@ -6,14 +6,14 @@
import styles from "./Header.module.css"; import styles from "./Header.module.css";
import SiteHeaderButton from "../../Common/Buttons/SiteHeaderButton"; import SiteHeaderButton from "../../Common/Buttons/SiteHeaderButton";
import {UnitCommitmentScenario} from "../../../core/data"; import { UnitCommitmentScenario } from "../../../core/data";
import {useRef} from "react"; import { useRef } from "react";
import FileUploadElement from "../../Common/Buttons/FileUploadElement"; import FileUploadElement from "../../Common/Buttons/FileUploadElement";
interface HeaderProps { interface HeaderProps {
onClear: () => void onClear: () => void;
onSave: () => void onSave: () => void;
onLoad: (data: UnitCommitmentScenario) => void onLoad: (data: UnitCommitmentScenario) => void;
} }
function Header(props: HeaderProps) { function Header(props: HeaderProps) {
@ -32,11 +32,11 @@ function Header(props: HeaderProps) {
<h1>UnitCommitment.jl</h1> <h1>UnitCommitment.jl</h1>
<h2>Case Builder</h2> <h2>Case Builder</h2>
<div className={styles.buttonContainer}> <div className={styles.buttonContainer}>
<SiteHeaderButton title="Clear" onClick={props.onClear}/> <SiteHeaderButton title="Clear" onClick={props.onClear} />
<SiteHeaderButton title="Load" onClick={onLoad}/> <SiteHeaderButton title="Load" onClick={onLoad} />
<SiteHeaderButton title="Save" onClick={props.onSave}/> <SiteHeaderButton title="Save" onClick={props.onSave} />
</div> </div>
<FileUploadElement ref={fileElem} accept=".json"/> <FileUploadElement ref={fileElem} accept=".json" />
</div> </div>
</div> </div>
); );

@ -7,17 +7,16 @@
import SectionHeader from "../../Common/SectionHeader/SectionHeader"; import SectionHeader from "../../Common/SectionHeader/SectionHeader";
import Form from "../../Common/Forms/Form"; import Form from "../../Common/Forms/Form";
import TextInputRow from "../../Common/Forms/TextInputRow"; import TextInputRow from "../../Common/Forms/TextInputRow";
import {UnitCommitmentScenario} from "../../../core/data"; import { UnitCommitmentScenario } from "../../../core/data";
interface ParametersProps { interface ParametersProps {
scenario: UnitCommitmentScenario scenario: UnitCommitmentScenario;
} }
function Parameters({scenario}: ParametersProps) { function Parameters({ scenario }: ParametersProps) {
return ( return (
<div> <div>
<SectionHeader title="Parameters"> <SectionHeader title="Parameters"></SectionHeader>
</SectionHeader>
<Form> <Form>
<TextInputRow <TextInputRow
label="Time horizon" label="Time horizon"

@ -4,7 +4,7 @@
* Released under the modified BSD license. See COPYING.md for more details. * Released under the modified BSD license. See COPYING.md for more details.
*/ */
import React, {Component} from "react"; import React, { Component } from "react";
class FileUploadElement extends Component<any> { class FileUploadElement extends Component<any> {
private inputRef = React.createRef<HTMLInputElement>(); private inputRef = React.createRef<HTMLInputElement>();
@ -25,17 +25,19 @@ class FileUploadElement extends Component<any> {
}; };
reader.readAsText(file); reader.readAsText(file);
} }
event.target.value = ''; event.target.value = "";
}; };
override render() { override render() {
return <input return (
<input
ref={this.inputRef} ref={this.inputRef}
type="file" type="file"
accept={this.props.accept} accept={this.props.accept}
style={{ display: "none" }} style={{ display: "none" }}
onChange={this.onFileSelected} onChange={this.onFileSelected}
/>; />
);
} }
} }

@ -5,16 +5,15 @@
*/ */
import styles from "./HelpButton.module.css"; import styles from "./HelpButton.module.css";
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {faCircleQuestion} from '@fortawesome/free-regular-svg-icons'; import { faCircleQuestion } from "@fortawesome/free-regular-svg-icons";
function HelpButton({ text }: { text: String }) {
function HelpButton({text}: { text: String }) {
return ( return (
<button className={styles.HelpButton}> <button className={styles.HelpButton}>
<span className={styles.tooltip}>{text}</span> <span className={styles.tooltip}>{text}</span>
<span className={styles.icon}> <span className={styles.icon}>
<FontAwesomeIcon icon={faCircleQuestion}/> <FontAwesomeIcon icon={faCircleQuestion} />
</span> </span>
</button> </button>
); );

@ -4,14 +4,14 @@
* Released under the modified BSD license. See COPYING.md for more details. * Released under the modified BSD license. See COPYING.md for more details.
*/ */
import {IconDefinition} from "@fortawesome/fontawesome-svg-core"; import { IconDefinition } from "@fortawesome/fontawesome-svg-core";
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import styles from "./SectionButton.module.css"; import styles from "./SectionButton.module.css";
interface SectionButtonProps { interface SectionButtonProps {
icon: IconDefinition, icon: IconDefinition;
tooltip: string, tooltip: string;
onClick?: () => void, onClick?: () => void;
} }
function SectionButton(props: SectionButtonProps) { function SectionButton(props: SectionButtonProps) {
@ -21,7 +21,7 @@ function SectionButton(props: SectionButtonProps) {
title={props.tooltip} title={props.tooltip}
onClick={props.onClick} onClick={props.onClick}
> >
<FontAwesomeIcon icon={props.icon}/> <FontAwesomeIcon icon={props.icon} />
</button> </button>
); );
} }

@ -6,11 +6,15 @@
import styles from "./SiteHeaderButton.module.css"; import styles from "./SiteHeaderButton.module.css";
function SiteHeaderButton({title, onClick}: { title: string, onClick?: () => void }) { function SiteHeaderButton({
title,
onClick,
}: {
title: string;
onClick?: () => void;
}) {
return ( return (
<button <button className={styles.SiteHeaderButton} onClick={onClick}>
className={styles.SiteHeaderButton}
onClick={onClick}>
{title} {title}
</button> </button>
); );

@ -4,10 +4,10 @@
* Released under the modified BSD license. See COPYING.md for more details. * Released under the modified BSD license. See COPYING.md for more details.
*/ */
import {ReactNode} from 'react'; import { ReactNode } from "react";
import styles from "./Form.module.css"; import styles from "./Form.module.css";
function Form({children}: { children: ReactNode }) { function Form({ children }: { children: ReactNode }) {
return <div className={styles.Form}>{children}</div>; return <div className={styles.Form}>{children}</div>;
} }

@ -7,12 +7,18 @@
import formStyles from "./Form.module.css"; import formStyles from "./Form.module.css";
import HelpButton from "../Buttons/HelpButton"; import HelpButton from "../Buttons/HelpButton";
function TextInputRow({label, unit, tooltip, currentValue, defaultValue}: { function TextInputRow({
label: string, label,
unit: string, unit,
tooltip: string, tooltip,
currentValue: string, currentValue,
defaultValue: string, defaultValue,
}: {
label: string;
unit: string;
tooltip: string;
currentValue: string;
defaultValue: string;
}) { }) {
return ( return (
<div className={formStyles.FormRow}> <div className={formStyles.FormRow}>
@ -20,12 +26,8 @@ function TextInputRow({label, unit, tooltip, currentValue, defaultValue}: {
{label} {label}
<span className={formStyles.FormRow_unit}> ({unit})</span> <span className={formStyles.FormRow_unit}> ({unit})</span>
</label> </label>
<input <input type="text" placeholder={defaultValue} value={currentValue} />
type="text" <HelpButton text={tooltip} />
placeholder={defaultValue}
value={currentValue}
/>
<HelpButton text={tooltip}/>
</div> </div>
); );
} }

@ -5,20 +5,17 @@
*/ */
import styles from "./SectionHeader.module.css"; import styles from "./SectionHeader.module.css";
import {ReactNode} from "react"; import { ReactNode } from "react";
interface SectionHeaderProps { interface SectionHeaderProps {
title: string, title: string;
children: ReactNode children?: ReactNode;
} }
function SectionHeader({ title, children }: SectionHeaderProps) {
function SectionHeader({title, children}: SectionHeaderProps) {
return ( return (
<div className={styles.SectionHeader}> <div className={styles.SectionHeader}>
<div className={styles.SectionButtonsContainer}> <div className={styles.SectionButtonsContainer}>{children}</div>
{children}
</div>
<h1>{title}</h1> <h1>{title}</h1>
</div> </div>
); );

@ -5,9 +5,9 @@
*/ */
export function offerDownload(data: string, type: string, filename: string) { export function offerDownload(data: string, type: string, filename: string) {
const dataBlob = new Blob([data], {type: type}); const dataBlob = new Blob([data], { type: type });
const url = URL.createObjectURL(dataBlob); const url = URL.createObjectURL(dataBlob);
const link = document.createElement('a'); const link = document.createElement("a");
link.href = url; link.href = url;
link.download = filename; link.download = filename;
document.body.appendChild(link); document.body.appendChild(link);

@ -11,53 +11,53 @@ export const schema = {
Parameters: { Parameters: {
type: "object", type: "object",
properties: { properties: {
"Version": { Version: {
type: "string", type: "string",
const: "0.4", const: "0.4",
description: "Version of UnitCommitment.jl" description: "Version of UnitCommitment.jl",
}, },
"Time horizon (min)": { "Time horizon (min)": {
type: "number", type: "number",
exclusiveMinimum: 0, exclusiveMinimum: 0,
description: "Length of the planning horizon in minutes" description: "Length of the planning horizon in minutes",
}, },
"Time horizon (h)": { "Time horizon (h)": {
type: "number", type: "number",
exclusiveMinimum: 0, exclusiveMinimum: 0,
description: "Length of the planning horizon in hours" description: "Length of the planning horizon in hours",
}, },
"Time step (min)": { "Time step (min)": {
type: "number", type: "number",
default: 60, default: 60,
enum: [60, 30, 20, 15, 12, 10, 6, 5, 4, 3, 2, 1], enum: [60, 30, 20, 15, 12, 10, 6, 5, 4, 3, 2, 1],
description: "Must be a divisor of 60" description: "Must be a divisor of 60",
}, },
"Power balance penalty ($/MW)": { "Power balance penalty ($/MW)": {
type: "number", type: "number",
default: 1000.0, default: 1000.0,
minimum: 0, minimum: 0,
description: "Penalty for system-wide shortage or surplus" description: "Penalty for system-wide shortage or surplus",
}, },
"Scenario name": { "Scenario name": {
type: "string", type: "string",
default: "s1", default: "s1",
description: "Name of the scenario" description: "Name of the scenario",
}, },
"Scenario weight": { "Scenario weight": {
type: "number", type: "number",
default: 1.0, default: 1.0,
exclusiveMinimum: 0, exclusiveMinimum: 0,
description: "Weight of the scenario" description: "Weight of the scenario",
} },
}, },
required: ["Time step (min)", "Power balance penalty ($/MW)"], required: ["Time step (min)", "Power balance penalty ($/MW)"],
oneOf: [ oneOf: [
{ required: ["Time horizon (min)"] }, { required: ["Time horizon (min)"] },
{ required: ["Time horizon (h)"] } { required: ["Time horizon (h)"] },
], ],
not: { not: {
required: ["Time horizon (min)", "Time horizon (h)"] required: ["Time horizon (min)", "Time horizon (h)"],
} },
}, },
Bus: { Bus: {
type: "object", type: "object",
@ -71,15 +71,12 @@ export const schema = {
{ {
type: "array", type: "array",
items: { items: {
oneOf: [ oneOf: [{ type: "number" }, { type: "null" }],
{ type: "number" }, },
{ type: "null" } },
] ],
} },
} },
]
}
}
}, },
}, },
TransmissionLines: { TransmissionLines: {
@ -95,36 +92,36 @@ export const schema = {
type: "string", type: "string",
minLength: 1, minLength: 1,
not: { not: {
const: { $data: "1/Source bus" } const: { $data: "1/Source bus" },
} },
}, },
"Susceptance (S)": { "Susceptance (S)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Normal flow limit (MW)": { "Normal flow limit (MW)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Emergency flow limit (MW)": { "Emergency flow limit (MW)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Flow limit penalty ($/MW)": { "Flow limit penalty ($/MW)": {
type: "number", type: "number",
minimum: 0, minimum: 0,
default: 5000.0 default: 5000.0,
} },
},
required: ["Source bus", "Target bus", "Susceptance (S)"],
}, },
required: ["Source bus", "Target bus", "Susceptance (S)"]
}
}, },
StorageUnits: { StorageUnits: {
type: "object", type: "object",
additionalProperties: { additionalProperties: {
type: "object", type: "object",
properties: { properties: {
"Bus": { Bus: {
type: "string", type: "string",
minLength: 1, minLength: 1,
}, },
@ -133,65 +130,65 @@ export const schema = {
}, },
"Maximum level (MWh)": { "Maximum level (MWh)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Allow simultaneous charging and discharging": { "Allow simultaneous charging and discharging": {
type: "boolean", type: "boolean",
default: true default: true,
}, },
"Charge cost ($/MW)": { "Charge cost ($/MW)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Discharge cost ($/MW)": { "Discharge cost ($/MW)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Charge efficiency": { "Charge efficiency": {
type: "number", type: "number",
minimum: 0, minimum: 0,
maximum: 1 maximum: 1,
}, },
"Discharge efficiency": { "Discharge efficiency": {
type: "number", type: "number",
minimum: 0, minimum: 0,
maximum: 1 maximum: 1,
}, },
"Loss factor": { "Loss factor": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Minimum charge rate (MW)": { "Minimum charge rate (MW)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Maximum charge rate (MW)": { "Maximum charge rate (MW)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Minimum discharge rate (MW)": { "Minimum discharge rate (MW)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Maximum discharge rate (MW)": { "Maximum discharge rate (MW)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Initial level (MWh)": { "Initial level (MWh)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Last period minimum level (MWh)": { "Last period minimum level (MWh)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Last period maximum level (MWh)": { "Last period maximum level (MWh)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
} },
},
required: ["Bus"],
}, },
required: ["Bus"]
}
}, },
Generators: { Generators: {
type: "object", type: "object",
@ -199,90 +196,90 @@ export const schema = {
type: "object", type: "object",
if: { if: {
properties: { properties: {
"Type": { const: "Thermal" } Type: { const: "Thermal" },
} },
}, },
then: { then: {
properties: { properties: {
"Bus": { Bus: {
type: "string", type: "string",
minLength: 1, minLength: 1,
}, },
"Type": { Type: {
type: "string", type: "string",
const: "Thermal" const: "Thermal",
}, },
"Production cost curve (MW)": { "Production cost curve (MW)": {
type: "array", type: "array",
items: { items: {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
minItems: 1 minItems: 1,
}, },
"Production cost curve ($)": { "Production cost curve ($)": {
type: "array", type: "array",
items: { items: {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
minItems: 1 minItems: 1,
}, },
"Startup costs ($)": { "Startup costs ($)": {
type: "array", type: "array",
items: { items: {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
default: [0.0] default: [0.0],
}, },
"Startup delays (h)": { "Startup delays (h)": {
type: "array", type: "array",
items: { items: {
type: "integer", type: "integer",
minimum: 1 minimum: 1,
}, },
default: [1] default: [1],
}, },
"Minimum uptime (h)": { "Minimum uptime (h)": {
type: "integer", type: "integer",
default: 1, default: 1,
minimum: 0 minimum: 0,
}, },
"Minimum downtime (h)": { "Minimum downtime (h)": {
type: "integer", type: "integer",
default: 1, default: 1,
minimum: 0 minimum: 0,
}, },
"Ramp up limit (MW)": { "Ramp up limit (MW)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Ramp down limit (MW)": { "Ramp down limit (MW)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Startup limit (MW)": { "Startup limit (MW)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Shutdown limit (MW)": { "Shutdown limit (MW)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Initial status (h)": { "Initial status (h)": {
type: "integer", type: "integer",
default: 1, default: 1,
not: { const: 0 } not: { const: 0 },
}, },
"Initial power (MW)": { "Initial power (MW)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
}, },
"Must run?": { "Must run?": {
type: "boolean", type: "boolean",
default: false default: false,
} },
}, },
required: [ required: [
"Bus", "Bus",
@ -290,13 +287,13 @@ export const schema = {
"Production cost curve (MW)", "Production cost curve (MW)",
"Production cost curve ($)", "Production cost curve ($)",
"Initial status (h)", "Initial status (h)",
"Initial power (MW)" "Initial power (MW)",
] ],
}, },
else: { else: {
properties: { properties: {
"Type": { const: "Profiled" }, Type: { const: "Profiled" },
"Bus": { Bus: {
type: "string", type: "string",
minLength: 1, minLength: 1,
}, },
@ -309,19 +306,18 @@ export const schema = {
type: "array", type: "array",
items: { items: {
type: "number", type: "number",
} },
} },
] ],
}, },
"Cost ($/MW)": { "Cost ($/MW)": {
type: "number", type: "number",
minimum: 0 minimum: 0,
} },
},
required: ["Type", "Bus", "Maximum power (MW)", "Cost ($/MW)"],
},
}, },
required: ["Type", "Bus", "Maximum power (MW)", "Cost ($/MW)"]
}
}
}, },
Contingencies: { Contingencies: {
type: "object", type: "object",
@ -331,36 +327,36 @@ export const schema = {
"Affected lines": { "Affected lines": {
type: "array", type: "array",
items: { items: {
type: "string" type: "string",
}, },
maxItems: 1, maxItems: 1,
minItems: 1 minItems: 1,
} },
},
required: ["Affected lines"],
},
}, },
required: ["Affected lines"]
}
}
}, },
type: "object", type: "object",
properties: { properties: {
Parameters: { Parameters: {
$ref: "#/definitions/Parameters" $ref: "#/definitions/Parameters",
}, },
Buses: { Buses: {
$ref: "#/definitions/Bus" $ref: "#/definitions/Bus",
}, },
"Transmission lines": { "Transmission lines": {
$ref: "#/definitions/TransmissionLines" $ref: "#/definitions/TransmissionLines",
}, },
"Storage units": { "Storage units": {
$ref: "#/definitions/StorageUnits" $ref: "#/definitions/StorageUnits",
}, },
"Generators": { Generators: {
$ref: "#/definitions/Generators" $ref: "#/definitions/Generators",
},
Contingencies: {
$ref: "#/definitions/Contingencies",
}, },
"Contingencies": {
$ref: "#/definitions/Contingencies"
}
}, },
required: ["Parameters"], required: ["Parameters"],
}; };

@ -4,7 +4,7 @@
* Released under the modified BSD license. See COPYING.md for more details. * Released under the modified BSD license. See COPYING.md for more details.
*/ */
import { schema } from './schema'; import { schema } from "./schema";
import Ajv from "ajv"; import Ajv from "ajv";
// Create Ajv instance with detailed debug options // Create Ajv instance with detailed debug options
@ -14,4 +14,8 @@ const ajv = new Ajv({
$data: true, $data: true,
}); });
export interface ValidationError {
message: string;
}
export const validate = ajv.compile(schema); export const validate = ajv.compile(schema);

@ -10,191 +10,71 @@ export interface Buses {
export interface UnitCommitmentScenario { export interface UnitCommitmentScenario {
Parameters: { Parameters: {
Version: string, Version: string;
"Power balance penalty ($/MW)": number, "Power balance penalty ($/MW)": number;
"Time horizon (h)": number, "Time horizon (h)": number;
"Time step (min)": number, "Time step (min)": number;
}, };
Buses: Buses Buses: Buses;
} }
export const BLANK_SCENARIO: UnitCommitmentScenario = { export const BLANK_SCENARIO: UnitCommitmentScenario = {
"Parameters": { Parameters: {
"Version": "0.4", Version: "0.4",
"Power balance penalty ($/MW)": 1000.0, "Power balance penalty ($/MW)": 1000.0,
"Time horizon (h)": 24, "Time horizon (h)": 24,
"Time step (min)": 60, "Time step (min)": 60,
}, },
"Buses": {} Buses: {},
}; };
export const TEST_SCENARIO: UnitCommitmentScenario = { export const TEST_SCENARIO: UnitCommitmentScenario = {
"Parameters": { Parameters: {
"Version": "0.4", Version: "0.4",
"Power balance penalty ($/MW)": 1000.0, "Power balance penalty ($/MW)": 1000.0,
"Time horizon (h)": 36, "Time horizon (h)": 36,
"Time step (min)": 60, "Time step (min)": 60,
}, },
"Buses": { Buses: {
"b1": { b1: {
"Load (MW)": [ "Load (MW)": [
35.79534, 35.79534, 34.38835, 33.45083, 32.89729, 33.25044, 33.93851, 35.8654,
34.38835, 37.27098, 38.08378, 38.99327, 38.65134, 38.83212, 37.60031, 37.27939,
33.45083, 37.11823, 37.73063, 40.951, 44.77115, 43.67527, 44.40959, 44.33812,
32.89729, 42.29071, 40.07654, 37.42093, 35.61175, 34.28185, 32.74174, 33.17336,
33.25044, 33.5181, 35.63558, 38.12722, 39.61689, 40.80105, 42.55277, 42.76017,
33.93851, 42.12535,
35.8654, ],
37.27098,
38.08378,
38.99327,
38.65134,
38.83212,
37.60031,
37.27939,
37.11823,
37.73063,
40.951,
44.77115,
43.67527,
44.40959,
44.33812,
42.29071,
40.07654,
37.42093,
35.61175,
34.28185,
32.74174,
33.17336,
33.5181,
35.63558,
38.12722,
39.61689,
40.80105,
42.55277,
42.76017,
42.12535
]
}, },
"b2": { b2: {
"Load (MW)": [ "Load (MW)": [
14.03739, 14.03739, 13.48563, 13.11797, 12.9009, 13.03939, 13.30922, 14.06486,
13.48563, 14.61607, 14.93482, 15.29148, 15.15739, 15.22828, 14.74522, 14.61937,
13.11797, 14.55617, 14.79633, 16.05921, 17.55731, 17.12756, 17.41553, 17.3875,
12.9009, 16.58459, 15.71629, 14.67487, 13.96539, 13.44386, 12.8399, 13.00916,
13.03939, 13.14435, 13.97474, 14.95185, 15.53603, 16.00041, 16.68736, 16.76869,
13.30922, 16.51974,
14.06486, ],
14.61607,
14.93482,
15.29148,
15.15739,
15.22828,
14.74522,
14.61937,
14.55617,
14.79633,
16.05921,
17.55731,
17.12756,
17.41553,
17.3875,
16.58459,
15.71629,
14.67487,
13.96539,
13.44386,
12.8399,
13.00916,
13.14435,
13.97474,
14.95185,
15.53603,
16.00041,
16.68736,
16.76869,
16.51974
]
}, },
"b3": { b3: {
"Load (MW)": [ "Load (MW)": [
27.3729, 27.3729, 26.29698, 25.58005, 25.15675, 25.4268, 25.95298, 27.42649,
26.29698, 28.50134, 29.12289, 29.81839, 29.55691, 29.69515, 28.75318, 28.50777,
25.58005, 28.38453, 28.85284, 31.31547, 34.23676, 33.39874, 33.96028, 33.90562,
25.15675, 32.33996, 30.64676, 28.61601, 27.23252, 26.21553, 25.0378, 25.36786,
25.4268, 25.63149, 27.25074, 29.15611, 30.29527, 31.2008, 32.54035, 32.69895,
25.95298, 32.2135,
27.42649, ],
28.50134,
29.12289,
29.81839,
29.55691,
29.69515,
28.75318,
28.50777,
28.38453,
28.85284,
31.31547,
34.23676,
33.39874,
33.96028,
33.90562,
32.33996,
30.64676,
28.61601,
27.23252,
26.21553,
25.0378,
25.36786,
25.63149,
27.25074,
29.15611,
30.29527,
31.2008,
32.54035,
32.69895,
32.2135
]
}, },
"b4": { b4: {
"Load (MW)": [ "Load (MW)": [
27.3729, 27.3729, 26.29698, 25.58005, 25.15675, 25.4268, 25.95298, 27.42649,
26.29698, 28.50134, 29.12289, 29.81839, 29.55691, 29.69515, 28.75318, 28.50777,
25.58005, 28.38453, 28.85284, 31.31547, 34.23676, 33.39874, 33.96028, 33.90562,
25.15675, 32.33996, 30.64676, 28.61601, 27.23252, 26.21553, 25.0378, 25.36786,
25.4268, 25.63149, 27.25074, 29.15611, 30.29527, 31.2008, 32.54035, 32.69895,
25.95298, 32.2135,
27.42649, ],
28.50134, },
29.12289,
29.81839,
29.55691,
29.69515,
28.75318,
28.50777,
28.38453,
28.85284,
31.31547,
34.23676,
33.39874,
33.96028,
33.90562,
32.33996,
30.64676,
28.61601,
27.23252,
26.21553,
25.0378,
25.36786,
25.63149,
27.25074,
29.15611,
30.29527,
31.2008,
32.54035,
32.69895,
32.2135
]
}, },
}
}; };

@ -4,19 +4,19 @@
* Released under the modified BSD license. See COPYING.md for more details. * Released under the modified BSD license. See COPYING.md for more details.
*/ */
import React from 'react'; import React from "react";
import ReactDOM from 'react-dom/client'; import ReactDOM from "react-dom/client";
import reportWebVitals from './reportWebVitals'; import reportWebVitals from "./reportWebVitals";
import CaseBuilder from "./components/CaseBuilder/CaseBuilder"; import CaseBuilder from "./components/CaseBuilder/CaseBuilder";
const root = ReactDOM.createRoot( const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement document.getElementById("root") as HTMLElement,
); );
root.render( root.render(
<React.StrictMode> <React.StrictMode>
<CaseBuilder/> <CaseBuilder />
</React.StrictMode> </React.StrictMode>,
); );
reportWebVitals(); reportWebVitals();

@ -4,11 +4,11 @@
* Released under the modified BSD license. See COPYING.md for more details. * Released under the modified BSD license. See COPYING.md for more details.
*/ */
import {ReportHandler} from 'web-vitals'; import { ReportHandler } from "web-vitals";
const reportWebVitals = (onPerfEntry?: ReportHandler) => { const reportWebVitals = (onPerfEntry?: ReportHandler) => {
if (onPerfEntry && onPerfEntry instanceof Function) { if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({getCLS, getFID, getFCP, getLCP, getTTFB}) => { import("web-vitals").then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry); getCLS(onPerfEntry);
getFID(onPerfEntry); getFID(onPerfEntry);
getFCP(onPerfEntry); getFCP(onPerfEntry);

@ -4,4 +4,4 @@
* Released under the modified BSD license. See COPYING.md for more details. * Released under the modified BSD license. See COPYING.md for more details.
*/ */
import '@testing-library/jest-dom'; import "@testing-library/jest-dom";

@ -1,11 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es5", "target": "es5",
"lib": [ "lib": ["dom", "dom.iterable", "esnext"],
"dom",
"dom.iterable",
"esnext"
],
"allowJs": false, "allowJs": false,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"alwaysStrict": true, "alwaysStrict": true,
@ -35,7 +31,5 @@
"noUnusedParameters": false, "noUnusedParameters": false,
"checkJs": true "checkJs": true
}, },
"include": [ "include": ["src"]
"src"
]
} }

Loading…
Cancel
Save