Skip to content

Commit 67f47d4

Browse files
authored
Merge pull request #260 from com-pas/259-autogenerate-substation-fails
fix: autogen bugfix and multistation support
2 parents 71b9b18 + 440d5fc commit 67f47d4

File tree

3 files changed

+75
-17
lines changed

3 files changed

+75
-17
lines changed

src/compas-editors/autogen-substation.ts

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LitElement, property } from 'lit-element';
2-
import { createElement, newActionEvent } from '../foundation.js';
2+
import { createElement, newActionEvent, newLogEvent } from '../foundation.js';
3+
import { get } from 'lit-translate';
34

45
let cbNum = 1;
56
let dsNum = 1;
@@ -135,7 +136,7 @@ function getValidCSWI(ied: Element, selectedCtlModel: string[]): Element[] {
135136
export default class CompasAutogenerateSubstation extends LitElement {
136137
@property() doc!: XMLDocument;
137138
@property() iedNames!: string[];
138-
@property() substationSeperator = '__';
139+
@property() substationNameLength = 5;
139140
@property() voltageLevelNameLength = 3;
140141
@property() iedStartChar = 'A';
141142

@@ -152,16 +153,30 @@ export default class CompasAutogenerateSubstation extends LitElement {
152153
.map(IED => IED.getAttribute('name') || '')
153154
.filter(value => !lNodes.includes(value));
154155

155-
//Get all the substation names by splitting the names on the '__' (seperator) and getting the characters in front of it
156+
/**
157+
* Get all the substation names by getting the first substationNameLength of characters.
158+
* If the voltageLevel element starts with A00 it can be skipped and if '_' characters are used after the substation name its invalid and will be skipped.
159+
* The optional underscore seperators will be left out to get a more visible appealing substation name.
160+
**/
156161
const substationNames = this.extractNames(
157162
this.iedNames
158163
.filter(
159164
value =>
160-
value.includes(this.substationSeperator) &&
161-
!value.split(this.substationSeperator)[1].startsWith('A00')
165+
!value?.substring(this.substationNameLength)?.startsWith('A00') &&
166+
!value?.substring(this.substationNameLength)?.includes('_')
162167
)
163-
.map(FullName => FullName?.split(this.substationSeperator)[0])
168+
.map(FullName =>
169+
FullName?.substring(0, this.substationNameLength).replace(/_/g, '')
170+
)
171+
);
172+
173+
this.createLog(
174+
substationNames.length == 0 ? 1 : 0,
175+
get('compas.autogensubstation.substationAmount', {
176+
amount: substationNames.length,
177+
})
164178
);
179+
165180
this.createSubstations(substationNames);
166181
}
167182

@@ -170,7 +185,7 @@ export default class CompasAutogenerateSubstation extends LitElement {
170185
* If the substation element doesn't exist yet, a substation element will be created with the given name and a default
171186
* description.
172187
*
173-
* The created substation element with its name will be used to create voltageLevels as child elements to the substations.
188+
* The created substation element with its name and optional underscore seperators will be used to create voltageLevels as child elements to the substations.
174189
* Afterwards the substation elements will be added to the document.
175190
*/
176191
createSubstations(substationNames: string[]) {
@@ -182,7 +197,10 @@ export default class CompasAutogenerateSubstation extends LitElement {
182197
desc,
183198
});
184199

185-
await this.createVoltageLevels(substation, name);
200+
await this.createVoltageLevels(
201+
substation,
202+
name + '_'.repeat(this.substationNameLength - name.length)
203+
);
186204

187205
this.dispatchEvent(
188206
newActionEvent({
@@ -192,13 +210,18 @@ export default class CompasAutogenerateSubstation extends LitElement {
192210
},
193211
})
194212
);
213+
this.createLog(
214+
0,
215+
get('compas.autogensubstation.substationGen', {
216+
substationname: name,
217+
})
218+
);
195219
}
196220
});
197221
}
198222

199223
/**
200-
* The name-content of the child elements will be extracted by splitting the ied name on the substationSeperator ('__' by default)
201-
* character and getting the characters after it.
224+
* The name-content of the child elements will be extracted by getting the substring after the substationNameLength of characters.
202225
* VoltageLevel elements will be created by getting the first voltageLevelNameLength characters of each element in the name content.
203226
* The elements will be created based on the name and some default values.
204227
*
@@ -211,14 +234,22 @@ export default class CompasAutogenerateSubstation extends LitElement {
211234
createVoltageLevels(substation: Element, substationName: string) {
212235
const substationContent = this.iedNames
213236
.filter(value => value.includes(substationName))
214-
.map(FullName => FullName?.split(this.substationSeperator)[1]);
237+
.map(FullName => FullName?.substring(this.substationNameLength));
215238

216239
const voltageLevelNames = this.extractNames(
217240
substationContent.map(FullName =>
218241
FullName?.substring(0, this.voltageLevelNameLength)
219242
)
220243
).filter(value => !value.startsWith('A00'));
221244

245+
this.createLog(
246+
voltageLevelNames.length == 0 ? 1 : 0,
247+
get('compas.autogensubstation.voltagelevelAmount', {
248+
amount: voltageLevelNames.length,
249+
substationname: substationName.replace(/_/g, ''),
250+
})
251+
);
252+
222253
if (voltageLevelNames.length == 0) return;
223254

224255
voltageLevelNames.forEach(name => {
@@ -237,16 +268,12 @@ export default class CompasAutogenerateSubstation extends LitElement {
237268
);
238269

239270
const voltageLevelContent = substationContent
240-
.filter(value => value.startsWith(name))
271+
.filter(value => value?.startsWith(name))
241272
.map(FullName =>
242273
FullName?.substring(this.voltageLevelNameLength, FullName.length)
243274
);
244275

245-
this.createBays(
246-
voltageLevel,
247-
voltageLevelContent,
248-
substationName + this.substationSeperator + name
249-
);
276+
this.createBays(voltageLevel, voltageLevelContent, substationName + name);
250277
substation.appendChild(voltageLevel);
251278
});
252279
}
@@ -271,6 +298,16 @@ export default class CompasAutogenerateSubstation extends LitElement {
271298
voltageLevelContent.map(iedName => iedName.split(this.iedStartChar)[0])
272299
);
273300

301+
this.createLog(
302+
bayNames.length == 0 ? 1 : 0,
303+
get('compas.autogensubstation.bayAmount', {
304+
amount: bayNames.length,
305+
voltagelevelname: substationVoltageLevelName.substring(
306+
this.substationNameLength
307+
),
308+
})
309+
);
310+
274311
bayNames.forEach(name => {
275312
const desc = 'Bay generated by CoMPAS';
276313
const bayElement = createElement(voltageLevel.ownerDocument, 'Bay', {
@@ -351,4 +388,13 @@ export default class CompasAutogenerateSubstation extends LitElement {
351388
(value, index) => value && content.indexOf(value) === index
352389
);
353390
}
391+
392+
createLog(type: number, content: string) {
393+
this.dispatchEvent(
394+
newLogEvent({
395+
kind: type == 0 ? 'info' : 'error',
396+
title: content,
397+
})
398+
);
399+
}
354400
}

src/translations/de.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,12 @@ export const de: Translations = {
984984
explainExpiredWithoutProject: '???',
985985
saveProject: '???',
986986
},
987+
autogensubstation: {
988+
substationAmount: '???',
989+
voltagelevelAmount: '???',
990+
bayAmount: '???',
991+
substationGen: '???',
992+
},
987993
},
988994
locamation: {
989995
vmu: {

src/translations/en.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,12 @@ export const en = {
988988
'To continue working you need to reload the browser to login again.',
989989
saveProject: 'Save project',
990990
},
991+
autogensubstation: {
992+
substationAmount: 'Found {{amount}} substation(s) to be created!',
993+
voltagelevelAmount: `Generating {{amount}} Voltage Level(s) for {{substationname}} substation!`,
994+
bayAmount: `Generating {{amount}} Bay Element(s) for {{voltagelevelname}} Voltage Level!`,
995+
substationGen: `Generated {{substationname}} substation with content!`,
996+
},
991997
},
992998
locamation: {
993999
vmu: {

0 commit comments

Comments
 (0)