Compare commits
No commits in common. '8e2769dc0e23d5df6790632ce72c408fb72940e7' and '5fbf9af28659ae04c6981569746014563928d396' have entirely different histories.
8e2769dc0e
...
5fbf9af286
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 3.8 KiB |
@ -1,175 +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 DataTable, {
|
|
||||||
ColumnSpec,
|
|
||||||
generateCsv,
|
|
||||||
generateTableColumns,
|
|
||||||
generateTableData,
|
|
||||||
parseCsv,
|
|
||||||
} from "../Common/Forms/DataTable";
|
|
||||||
import { CaseBuilderSectionProps } from "./CaseBuilder";
|
|
||||||
import { useRef } from "react";
|
|
||||||
import FileUploadElement from "../Common/Buttons/FileUploadElement";
|
|
||||||
import { ValidationError } from "../../core/Data/validate";
|
|
||||||
import SectionHeader from "../Common/SectionHeader/SectionHeader";
|
|
||||||
import SectionButton from "../Common/Buttons/SectionButton";
|
|
||||||
import {
|
|
||||||
faDownload,
|
|
||||||
faPlus,
|
|
||||||
faUpload,
|
|
||||||
} from "@fortawesome/free-solid-svg-icons";
|
|
||||||
import { UnitCommitmentScenario } from "../../core/Data/types";
|
|
||||||
import { ColumnDefinition } from "tabulator-tables";
|
|
||||||
import {
|
|
||||||
changePriceSensitiveLoadData,
|
|
||||||
createPriceSensitiveLoad,
|
|
||||||
deletePriceSensitiveLoad,
|
|
||||||
renamePriceSensitiveLoad,
|
|
||||||
} from "../../core/Operations/psloadOps";
|
|
||||||
import { offerDownload } from "../Common/io";
|
|
||||||
|
|
||||||
export const PriceSensitiveLoadsColumnSpec: ColumnSpec[] = [
|
|
||||||
{
|
|
||||||
title: "Name",
|
|
||||||
type: "string",
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Bus",
|
|
||||||
type: "busRef",
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Revenue ($/MW)",
|
|
||||||
type: "number",
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Demand (MW)",
|
|
||||||
type: "number[T]",
|
|
||||||
width: 70,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export const generatePriceSensitiveLoadsData = (
|
|
||||||
scenario: UnitCommitmentScenario,
|
|
||||||
): [any[], ColumnDefinition[]] => {
|
|
||||||
const columns = generateTableColumns(scenario, PriceSensitiveLoadsColumnSpec);
|
|
||||||
const data = generateTableData(
|
|
||||||
scenario["Price-sensitive loads"],
|
|
||||||
PriceSensitiveLoadsColumnSpec,
|
|
||||||
scenario,
|
|
||||||
);
|
|
||||||
return [data, columns];
|
|
||||||
};
|
|
||||||
|
|
||||||
const PriceSensitiveLoadsComponent = (props: CaseBuilderSectionProps) => {
|
|
||||||
const fileUploadElem = useRef<FileUploadElement>(null);
|
|
||||||
|
|
||||||
const onDownload = () => {
|
|
||||||
const [data, columns] = generatePriceSensitiveLoadsData(props.scenario);
|
|
||||||
const csvContents = generateCsv(data, columns);
|
|
||||||
offerDownload(csvContents, "text/csv", "psloads.csv");
|
|
||||||
};
|
|
||||||
|
|
||||||
const onUpload = () => {
|
|
||||||
fileUploadElem.current!.showFilePicker((csv: any) => {
|
|
||||||
// Parse provided CSV file
|
|
||||||
const [psloads, err] = parseCsv(
|
|
||||||
csv,
|
|
||||||
PriceSensitiveLoadsColumnSpec,
|
|
||||||
props.scenario,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Handle validation errors
|
|
||||||
if (err) {
|
|
||||||
props.onError(err.message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate new scenario
|
|
||||||
props.onDataChanged({
|
|
||||||
...props.scenario,
|
|
||||||
"Price-sensitive loads": psloads,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const onAdd = () => {
|
|
||||||
const [newScenario, err] = createPriceSensitiveLoad(props.scenario);
|
|
||||||
if (err) {
|
|
||||||
props.onError(err.message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
props.onDataChanged(newScenario);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onDelete = (name: string): ValidationError | null => {
|
|
||||||
const newScenario = deletePriceSensitiveLoad(name, props.scenario);
|
|
||||||
props.onDataChanged(newScenario);
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const onDataChanged = (
|
|
||||||
name: string,
|
|
||||||
field: string,
|
|
||||||
newValue: string,
|
|
||||||
): ValidationError | null => {
|
|
||||||
const [newScenario, err] = changePriceSensitiveLoadData(
|
|
||||||
name,
|
|
||||||
field,
|
|
||||||
newValue,
|
|
||||||
props.scenario,
|
|
||||||
);
|
|
||||||
if (err) {
|
|
||||||
props.onError(err.message);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
props.onDataChanged(newScenario);
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const onRename = (
|
|
||||||
oldName: string,
|
|
||||||
newName: string,
|
|
||||||
): ValidationError | null => {
|
|
||||||
const [newScenario, err] = renamePriceSensitiveLoad(
|
|
||||||
oldName,
|
|
||||||
newName,
|
|
||||||
props.scenario,
|
|
||||||
);
|
|
||||||
if (err) {
|
|
||||||
props.onError(err.message);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
props.onDataChanged(newScenario);
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<SectionHeader title="Price-sensitive loads">
|
|
||||||
<SectionButton icon={faPlus} tooltip="Add" onClick={onAdd} />
|
|
||||||
<SectionButton
|
|
||||||
icon={faDownload}
|
|
||||||
tooltip="Download"
|
|
||||||
onClick={onDownload}
|
|
||||||
/>
|
|
||||||
<SectionButton icon={faUpload} tooltip="Upload" onClick={onUpload} />
|
|
||||||
</SectionHeader>
|
|
||||||
<DataTable
|
|
||||||
onRowDeleted={onDelete}
|
|
||||||
onRowRenamed={onRename}
|
|
||||||
onDataChanged={onDataChanged}
|
|
||||||
generateData={() => generatePriceSensitiveLoadsData(props.scenario)}
|
|
||||||
/>
|
|
||||||
<FileUploadElement ref={fileUploadElem} accept=".csv" />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default PriceSensitiveLoadsComponent;
|
|
@ -1,235 +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 DataTable, {
|
|
||||||
ColumnSpec,
|
|
||||||
generateCsv,
|
|
||||||
generateTableColumns,
|
|
||||||
generateTableData,
|
|
||||||
parseCsv,
|
|
||||||
} from "../Common/Forms/DataTable";
|
|
||||||
import { CaseBuilderSectionProps } from "./CaseBuilder";
|
|
||||||
import { useRef } from "react";
|
|
||||||
import FileUploadElement from "../Common/Buttons/FileUploadElement";
|
|
||||||
import { ValidationError } from "../../core/Data/validate";
|
|
||||||
import SectionHeader from "../Common/SectionHeader/SectionHeader";
|
|
||||||
import SectionButton from "../Common/Buttons/SectionButton";
|
|
||||||
import {
|
|
||||||
faDownload,
|
|
||||||
faPlus,
|
|
||||||
faUpload,
|
|
||||||
} from "@fortawesome/free-solid-svg-icons";
|
|
||||||
import { UnitCommitmentScenario } from "../../core/Data/types";
|
|
||||||
import { ColumnDefinition } from "tabulator-tables";
|
|
||||||
import {
|
|
||||||
changeStorageUnitData,
|
|
||||||
createStorageUnit,
|
|
||||||
deleteStorageUnit,
|
|
||||||
renameStorageUnit,
|
|
||||||
} from "../../core/Operations/storageOps";
|
|
||||||
import { offerDownload } from "../Common/io";
|
|
||||||
|
|
||||||
export const StorageUnitsColumnSpec: ColumnSpec[] = [
|
|
||||||
{
|
|
||||||
title: "Name",
|
|
||||||
type: "string",
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Bus",
|
|
||||||
type: "busRef",
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Minimum level (MWh)",
|
|
||||||
type: "number",
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Maximum level (MWh)",
|
|
||||||
type: "number",
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Charge cost ($/MW)",
|
|
||||||
type: "number",
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Discharge cost ($/MW)",
|
|
||||||
type: "number",
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Charge efficiency",
|
|
||||||
type: "number",
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Discharge efficiency",
|
|
||||||
type: "number",
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Loss factor",
|
|
||||||
type: "number",
|
|
||||||
width: 80,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Minimum charge rate (MW)",
|
|
||||||
type: "number",
|
|
||||||
width: 140,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Maximum charge rate (MW)",
|
|
||||||
type: "number",
|
|
||||||
width: 140,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Minimum discharge rate (MW)",
|
|
||||||
type: "number",
|
|
||||||
width: 140,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Maximum discharge rate (MW)",
|
|
||||||
type: "number",
|
|
||||||
width: 150,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Initial level (MWh)",
|
|
||||||
type: "number",
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Last period minimum level (MWh)",
|
|
||||||
type: "number",
|
|
||||||
width: 160,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Last period maximum level (MWh)",
|
|
||||||
type: "number",
|
|
||||||
width: 160,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export const generateStorageUnitsData = (
|
|
||||||
scenario: UnitCommitmentScenario,
|
|
||||||
): [any[], ColumnDefinition[]] => {
|
|
||||||
const columns = generateTableColumns(scenario, StorageUnitsColumnSpec);
|
|
||||||
const data = generateTableData(
|
|
||||||
scenario["Storage units"],
|
|
||||||
StorageUnitsColumnSpec,
|
|
||||||
scenario,
|
|
||||||
);
|
|
||||||
return [data, columns];
|
|
||||||
};
|
|
||||||
|
|
||||||
const StorageUnitsComponent = (props: CaseBuilderSectionProps) => {
|
|
||||||
const fileUploadElem = useRef<FileUploadElement>(null);
|
|
||||||
|
|
||||||
const onDownload = () => {
|
|
||||||
const [data, columns] = generateStorageUnitsData(props.scenario);
|
|
||||||
const csvContents = generateCsv(data, columns);
|
|
||||||
offerDownload(csvContents, "text/csv", "storage_units.csv");
|
|
||||||
};
|
|
||||||
|
|
||||||
const onUpload = () => {
|
|
||||||
fileUploadElem.current!.showFilePicker((csv: any) => {
|
|
||||||
// Parse provided CSV file
|
|
||||||
const [storageUnits, err] = parseCsv(
|
|
||||||
csv,
|
|
||||||
StorageUnitsColumnSpec,
|
|
||||||
props.scenario,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Handle validation errors
|
|
||||||
if (err) {
|
|
||||||
props.onError(err.message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate new scenario
|
|
||||||
props.onDataChanged({
|
|
||||||
...props.scenario,
|
|
||||||
"Storage units": storageUnits,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const onAdd = () => {
|
|
||||||
const [newScenario, err] = createStorageUnit(props.scenario);
|
|
||||||
if (err) {
|
|
||||||
props.onError(err.message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
props.onDataChanged(newScenario);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onDelete = (name: string): ValidationError | null => {
|
|
||||||
const newScenario = deleteStorageUnit(name, props.scenario);
|
|
||||||
props.onDataChanged(newScenario);
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const onDataChanged = (
|
|
||||||
name: string,
|
|
||||||
field: string,
|
|
||||||
newValue: string,
|
|
||||||
): ValidationError | null => {
|
|
||||||
const [newScenario, err] = changeStorageUnitData(
|
|
||||||
name,
|
|
||||||
field,
|
|
||||||
newValue,
|
|
||||||
props.scenario,
|
|
||||||
);
|
|
||||||
if (err) {
|
|
||||||
props.onError(err.message);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
props.onDataChanged(newScenario);
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const onRename = (
|
|
||||||
oldName: string,
|
|
||||||
newName: string,
|
|
||||||
): ValidationError | null => {
|
|
||||||
const [newScenario, err] = renameStorageUnit(
|
|
||||||
oldName,
|
|
||||||
newName,
|
|
||||||
props.scenario,
|
|
||||||
);
|
|
||||||
if (err) {
|
|
||||||
props.onError(err.message);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
props.onDataChanged(newScenario);
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<SectionHeader title="Storage units">
|
|
||||||
<SectionButton icon={faPlus} tooltip="Add" onClick={onAdd} />
|
|
||||||
<SectionButton
|
|
||||||
icon={faDownload}
|
|
||||||
tooltip="Download"
|
|
||||||
onClick={onDownload}
|
|
||||||
/>
|
|
||||||
<SectionButton icon={faUpload} tooltip="Upload" onClick={onUpload} />
|
|
||||||
</SectionHeader>
|
|
||||||
<DataTable
|
|
||||||
onRowDeleted={onDelete}
|
|
||||||
onRowRenamed={onRename}
|
|
||||||
onDataChanged={onDataChanged}
|
|
||||||
generateData={() => generateStorageUnitsData(props.scenario)}
|
|
||||||
/>
|
|
||||||
<FileUploadElement ref={fileUploadElem} accept=".csv" />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default StorageUnitsComponent;
|
|
@ -1,60 +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 { TEST_DATA_1 } from "../Data/fixtures.test";
|
|
||||||
import assert from "node:assert";
|
|
||||||
import {
|
|
||||||
changePriceSensitiveLoadData,
|
|
||||||
createPriceSensitiveLoad,
|
|
||||||
deletePriceSensitiveLoad,
|
|
||||||
renamePriceSensitiveLoad,
|
|
||||||
} from "./psloadOps";
|
|
||||||
import { ValidationError } from "../Data/validate";
|
|
||||||
|
|
||||||
test("createPriceSensitiveLoad", () => {
|
|
||||||
const [newScenario, err] = createPriceSensitiveLoad(TEST_DATA_1);
|
|
||||||
assert(err === null);
|
|
||||||
assert.equal(Object.keys(newScenario["Price-sensitive loads"]).length, 2);
|
|
||||||
assert("ps2" in newScenario["Price-sensitive loads"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("renamePriceSensitiveLoad", () => {
|
|
||||||
const [newScenario, err] = renamePriceSensitiveLoad(
|
|
||||||
"ps1",
|
|
||||||
"ps2",
|
|
||||||
TEST_DATA_1,
|
|
||||||
);
|
|
||||||
assert(err === null);
|
|
||||||
assert.deepEqual(
|
|
||||||
newScenario["Price-sensitive loads"]["ps2"],
|
|
||||||
TEST_DATA_1["Price-sensitive loads"]["ps1"],
|
|
||||||
);
|
|
||||||
assert.equal(Object.keys(newScenario["Price-sensitive loads"]).length, 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("changePriceSensitiveLoadData", () => {
|
|
||||||
let scenario = TEST_DATA_1;
|
|
||||||
let err: ValidationError | null;
|
|
||||||
[scenario, err] = changePriceSensitiveLoadData("ps1", "Bus", "b3", scenario);
|
|
||||||
assert.equal(err, null);
|
|
||||||
[scenario, err] = changePriceSensitiveLoadData(
|
|
||||||
"ps1",
|
|
||||||
"Demand (MW) 00:00",
|
|
||||||
"99",
|
|
||||||
scenario,
|
|
||||||
);
|
|
||||||
assert.equal(err, null);
|
|
||||||
assert.deepEqual(scenario["Price-sensitive loads"]["ps1"], {
|
|
||||||
Bus: "b3",
|
|
||||||
"Revenue ($/MW)": 23,
|
|
||||||
"Demand (MW)": [99, 50, 50, 50, 50],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("deletePriceSensitiveLoad", () => {
|
|
||||||
const newScenario = deletePriceSensitiveLoad("ps1", TEST_DATA_1);
|
|
||||||
assert.equal(Object.keys(newScenario["Price-sensitive loads"]).length, 0);
|
|
||||||
});
|
|
@ -1,88 +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 { ValidationError } from "../Data/validate";
|
|
||||||
import { PriceSensitiveLoad, UnitCommitmentScenario } from "../Data/types";
|
|
||||||
import {
|
|
||||||
assertBusesNotEmpty,
|
|
||||||
changeData,
|
|
||||||
generateUniqueName,
|
|
||||||
renameItemInObject,
|
|
||||||
} from "./commonOps";
|
|
||||||
import { PriceSensitiveLoadsColumnSpec } from "../../components/CaseBuilder/Psload";
|
|
||||||
import { generateTimeslots } from "../../components/Common/Forms/DataTable";
|
|
||||||
|
|
||||||
export const createPriceSensitiveLoad = (
|
|
||||||
scenario: UnitCommitmentScenario,
|
|
||||||
): [UnitCommitmentScenario, ValidationError | null] => {
|
|
||||||
const err = assertBusesNotEmpty(scenario);
|
|
||||||
if (err) return [scenario, err];
|
|
||||||
const busName = Object.keys(scenario.Buses)[0]!;
|
|
||||||
const timeslots = generateTimeslots(scenario);
|
|
||||||
const name = generateUniqueName(scenario["Price-sensitive loads"], "ps");
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
...scenario,
|
|
||||||
"Price-sensitive loads": {
|
|
||||||
...scenario["Price-sensitive loads"],
|
|
||||||
[name]: {
|
|
||||||
Bus: busName,
|
|
||||||
"Revenue ($/MW)": 0,
|
|
||||||
"Demand (MW)": Array(timeslots.length).fill(0),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const renamePriceSensitiveLoad = (
|
|
||||||
oldName: string,
|
|
||||||
newName: string,
|
|
||||||
scenario: UnitCommitmentScenario,
|
|
||||||
): [UnitCommitmentScenario, ValidationError | null] => {
|
|
||||||
const [newObj, err] = renameItemInObject(
|
|
||||||
oldName,
|
|
||||||
newName,
|
|
||||||
scenario["Price-sensitive loads"],
|
|
||||||
);
|
|
||||||
if (err) return [scenario, err];
|
|
||||||
return [{ ...scenario, "Price-sensitive loads": newObj }, null];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const changePriceSensitiveLoadData = (
|
|
||||||
name: string,
|
|
||||||
field: string,
|
|
||||||
newValueStr: string,
|
|
||||||
scenario: UnitCommitmentScenario,
|
|
||||||
): [UnitCommitmentScenario, ValidationError | null] => {
|
|
||||||
const [newObj, err] = changeData(
|
|
||||||
field,
|
|
||||||
newValueStr,
|
|
||||||
scenario["Price-sensitive loads"][name]!,
|
|
||||||
PriceSensitiveLoadsColumnSpec,
|
|
||||||
scenario,
|
|
||||||
);
|
|
||||||
if (err) return [scenario, err];
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
...scenario,
|
|
||||||
"Price-sensitive loads": {
|
|
||||||
...scenario["Price-sensitive loads"],
|
|
||||||
[name]: newObj as PriceSensitiveLoad,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const deletePriceSensitiveLoad = (
|
|
||||||
name: string,
|
|
||||||
scenario: UnitCommitmentScenario,
|
|
||||||
): UnitCommitmentScenario => {
|
|
||||||
const { [name]: _, ...newContainer } = scenario["Price-sensitive loads"];
|
|
||||||
return { ...scenario, "Price-sensitive loads": newContainer };
|
|
||||||
};
|
|
@ -1,75 +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 { TEST_DATA_1 } from "../Data/fixtures.test";
|
|
||||||
import assert from "node:assert";
|
|
||||||
import {
|
|
||||||
changeStorageUnitData,
|
|
||||||
createStorageUnit,
|
|
||||||
deleteStorageUnit,
|
|
||||||
renameStorageUnit,
|
|
||||||
} from "./storageOps";
|
|
||||||
import { ValidationError } from "../Data/validate";
|
|
||||||
|
|
||||||
test("createStorageUnit", () => {
|
|
||||||
const [newScenario, err] = createStorageUnit(TEST_DATA_1);
|
|
||||||
assert(err === null);
|
|
||||||
assert.equal(Object.keys(newScenario["Storage units"]).length, 2);
|
|
||||||
assert("su2" in newScenario["Storage units"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("renameStorageUnit", () => {
|
|
||||||
const [newScenario, err] = renameStorageUnit("su1", "su2", TEST_DATA_1);
|
|
||||||
assert(err === null);
|
|
||||||
assert.deepEqual(
|
|
||||||
newScenario["Storage units"]["su2"],
|
|
||||||
TEST_DATA_1["Storage units"]["su1"],
|
|
||||||
);
|
|
||||||
assert.equal(Object.keys(newScenario["Storage units"]).length, 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("changeStorageUnitData", () => {
|
|
||||||
let scenario = TEST_DATA_1;
|
|
||||||
let err: ValidationError | null;
|
|
||||||
[scenario, err] = changeStorageUnitData("su1", "Bus", "b3", scenario);
|
|
||||||
assert.equal(err, null);
|
|
||||||
[scenario, err] = changeStorageUnitData(
|
|
||||||
"su1",
|
|
||||||
"Minimum level (MWh)",
|
|
||||||
"99",
|
|
||||||
scenario,
|
|
||||||
);
|
|
||||||
assert.equal(err, null);
|
|
||||||
[scenario, err] = changeStorageUnitData(
|
|
||||||
"su1",
|
|
||||||
"Maximum discharge rate (MW)",
|
|
||||||
"99",
|
|
||||||
scenario,
|
|
||||||
);
|
|
||||||
assert.equal(err, null);
|
|
||||||
assert.deepEqual(scenario["Storage units"]["su1"], {
|
|
||||||
Bus: "b3",
|
|
||||||
"Minimum level (MWh)": 99.0,
|
|
||||||
"Maximum level (MWh)": 100.0,
|
|
||||||
"Charge cost ($/MW)": 2.0,
|
|
||||||
"Discharge cost ($/MW)": 1.0,
|
|
||||||
"Charge efficiency": 0.8,
|
|
||||||
"Discharge efficiency": 0.85,
|
|
||||||
"Loss factor": 0.01,
|
|
||||||
"Minimum charge rate (MW)": 5.0,
|
|
||||||
"Maximum charge rate (MW)": 10.0,
|
|
||||||
"Minimum discharge rate (MW)": 4.0,
|
|
||||||
"Maximum discharge rate (MW)": 99.0,
|
|
||||||
"Initial level (MWh)": 20.0,
|
|
||||||
"Last period minimum level (MWh)": 21.0,
|
|
||||||
"Last period maximum level (MWh)": 22.0,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("deleteStorageUnit", () => {
|
|
||||||
const newScenario = deleteStorageUnit("su1", TEST_DATA_1);
|
|
||||||
assert.equal(Object.keys(newScenario["Storage units"]).length, 0);
|
|
||||||
});
|
|
@ -1,98 +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 { ValidationError } from "../Data/validate";
|
|
||||||
import { StorageUnit, UnitCommitmentScenario } from "../Data/types";
|
|
||||||
import {
|
|
||||||
assertBusesNotEmpty,
|
|
||||||
changeData,
|
|
||||||
generateUniqueName,
|
|
||||||
renameItemInObject,
|
|
||||||
} from "./commonOps";
|
|
||||||
import { StorageUnitsColumnSpec } from "../../components/CaseBuilder/StorageUnits";
|
|
||||||
|
|
||||||
export const createStorageUnit = (
|
|
||||||
scenario: UnitCommitmentScenario,
|
|
||||||
): [UnitCommitmentScenario, ValidationError | null] => {
|
|
||||||
const err = assertBusesNotEmpty(scenario);
|
|
||||||
if (err) return [scenario, err];
|
|
||||||
const busName = Object.keys(scenario.Buses)[0]!;
|
|
||||||
const name = generateUniqueName(scenario["Storage units"], "su");
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
...scenario,
|
|
||||||
"Storage units": {
|
|
||||||
...scenario["Storage units"],
|
|
||||||
[name]: {
|
|
||||||
Bus: busName,
|
|
||||||
"Minimum level (MWh)": 0,
|
|
||||||
"Maximum level (MWh)": 1,
|
|
||||||
"Charge cost ($/MW)": 0.0,
|
|
||||||
"Discharge cost ($/MW)": 0.0,
|
|
||||||
"Charge efficiency": 1,
|
|
||||||
"Discharge efficiency": 1,
|
|
||||||
"Loss factor": 0,
|
|
||||||
"Minimum charge rate (MW)": 1,
|
|
||||||
"Maximum charge rate (MW)": 1,
|
|
||||||
"Minimum discharge rate (MW)": 1,
|
|
||||||
"Maximum discharge rate (MW)": 1,
|
|
||||||
"Initial level (MWh)": 0,
|
|
||||||
"Last period minimum level (MWh)": 0,
|
|
||||||
"Last period maximum level (MWh)": 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const renameStorageUnit = (
|
|
||||||
oldName: string,
|
|
||||||
newName: string,
|
|
||||||
scenario: UnitCommitmentScenario,
|
|
||||||
): [UnitCommitmentScenario, ValidationError | null] => {
|
|
||||||
const [newObj, err] = renameItemInObject(
|
|
||||||
oldName,
|
|
||||||
newName,
|
|
||||||
scenario["Storage units"],
|
|
||||||
);
|
|
||||||
if (err) return [scenario, err];
|
|
||||||
return [{ ...scenario, "Storage units": newObj }, null];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const changeStorageUnitData = (
|
|
||||||
name: string,
|
|
||||||
field: string,
|
|
||||||
newValueStr: string,
|
|
||||||
scenario: UnitCommitmentScenario,
|
|
||||||
): [UnitCommitmentScenario, ValidationError | null] => {
|
|
||||||
const [newObj, err] = changeData(
|
|
||||||
field,
|
|
||||||
newValueStr,
|
|
||||||
scenario["Storage units"][name]!,
|
|
||||||
StorageUnitsColumnSpec,
|
|
||||||
scenario,
|
|
||||||
);
|
|
||||||
if (err) return [scenario, err];
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
...scenario,
|
|
||||||
"Storage units": {
|
|
||||||
...scenario["Storage units"],
|
|
||||||
[name]: newObj as StorageUnit,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const deleteStorageUnit = (
|
|
||||||
name: string,
|
|
||||||
scenario: UnitCommitmentScenario,
|
|
||||||
): UnitCommitmentScenario => {
|
|
||||||
const { [name]: _, ...newContainer } = scenario["Storage units"];
|
|
||||||
return { ...scenario, "Storage units": newContainer };
|
|
||||||
};
|
|
Loading…
Reference in new issue