mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-06 00:08:52 -06:00
web: Propagate bus deletion and renaming
This commit is contained in:
@@ -48,13 +48,20 @@ test("deleteBus", () => {
|
||||
});
|
||||
|
||||
test("renameBus", () => {
|
||||
let [scenario, err] = renameBus("b2", "b99", TEST_DATA_1);
|
||||
let [scenario, err] = renameBus("b1", "b99", TEST_DATA_1);
|
||||
assert(err === null);
|
||||
assert.deepEqual(scenario.Buses, {
|
||||
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)": [35.79534, 34.38835, 33.45083, 32.89729, 33.25044] },
|
||||
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] },
|
||||
});
|
||||
assert.deepEqual(scenario.Generators["pu1"], {
|
||||
Bus: "b99",
|
||||
Type: "Profiled",
|
||||
"Cost ($/MW)": 12.5,
|
||||
"Maximum power (MW)": [10, 12, 13, 15, 20],
|
||||
"Minimum power (MW)": [0, 0, 0, 0, 0],
|
||||
});
|
||||
});
|
||||
|
||||
test("renameBus with duplicated name", () => {
|
||||
|
||||
@@ -56,7 +56,14 @@ export const changeBusData = (
|
||||
|
||||
export const deleteBus = (bus: string, scenario: UnitCommitmentScenario) => {
|
||||
const { [bus]: _, ...newBuses } = scenario.Buses;
|
||||
return { ...scenario, Buses: newBuses };
|
||||
const newGenerators = { ...scenario.Generators };
|
||||
|
||||
// Update generators
|
||||
for (const genName in scenario.Generators) {
|
||||
let gen = scenario.Generators[genName]!;
|
||||
if (gen["Bus"] === bus) delete newGenerators[genName];
|
||||
}
|
||||
return { ...scenario, Buses: newBuses, Generators: newGenerators };
|
||||
};
|
||||
|
||||
export const renameBus = (
|
||||
@@ -66,5 +73,14 @@ export const renameBus = (
|
||||
): [UnitCommitmentScenario, ValidationError | null] => {
|
||||
const [newBuses, err] = renameItemInObject(oldName, newName, scenario.Buses);
|
||||
if (err) return [scenario, err];
|
||||
return [{ ...scenario, Buses: newBuses }, null];
|
||||
|
||||
// Update generators
|
||||
const newGenerators = { ...scenario.Generators };
|
||||
for (const genName in scenario.Generators) {
|
||||
let gen = newGenerators[genName]!;
|
||||
if (gen["Bus"] === oldName) {
|
||||
newGenerators[genName] = { ...gen, Bus: newName };
|
||||
}
|
||||
}
|
||||
return [{ ...scenario, Buses: newBuses, Generators: newGenerators }, null];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user