1
1
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' ;
3
4
4
5
let cbNum = 1 ;
5
6
let dsNum = 1 ;
@@ -135,7 +136,7 @@ function getValidCSWI(ied: Element, selectedCtlModel: string[]): Element[] {
135
136
export default class CompasAutogenerateSubstation extends LitElement {
136
137
@property ( ) doc ! : XMLDocument ;
137
138
@property ( ) iedNames ! : string [ ] ;
138
- @property ( ) substationSeperator = '__' ;
139
+ @property ( ) substationNameLength = 5 ;
139
140
@property ( ) voltageLevelNameLength = 3 ;
140
141
@property ( ) iedStartChar = 'A' ;
141
142
@@ -152,16 +153,30 @@ export default class CompasAutogenerateSubstation extends LitElement {
152
153
. map ( IED => IED . getAttribute ( 'name' ) || '' )
153
154
. filter ( value => ! lNodes . includes ( value ) ) ;
154
155
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
+ **/
156
161
const substationNames = this . extractNames (
157
162
this . iedNames
158
163
. filter (
159
164
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 ( '_ ')
162
167
)
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
+ } )
164
178
) ;
179
+
165
180
this . createSubstations ( substationNames ) ;
166
181
}
167
182
@@ -170,7 +185,7 @@ export default class CompasAutogenerateSubstation extends LitElement {
170
185
* If the substation element doesn't exist yet, a substation element will be created with the given name and a default
171
186
* description.
172
187
*
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.
174
189
* Afterwards the substation elements will be added to the document.
175
190
*/
176
191
createSubstations ( substationNames : string [ ] ) {
@@ -182,7 +197,10 @@ export default class CompasAutogenerateSubstation extends LitElement {
182
197
desc,
183
198
} ) ;
184
199
185
- await this . createVoltageLevels ( substation , name ) ;
200
+ await this . createVoltageLevels (
201
+ substation ,
202
+ name + '_' . repeat ( this . substationNameLength - name . length )
203
+ ) ;
186
204
187
205
this . dispatchEvent (
188
206
newActionEvent ( {
@@ -192,13 +210,18 @@ export default class CompasAutogenerateSubstation extends LitElement {
192
210
} ,
193
211
} )
194
212
) ;
213
+ this . createLog (
214
+ 0 ,
215
+ get ( 'compas.autogensubstation.substationGen' , {
216
+ substationname : name ,
217
+ } )
218
+ ) ;
195
219
}
196
220
} ) ;
197
221
}
198
222
199
223
/**
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.
202
225
* VoltageLevel elements will be created by getting the first voltageLevelNameLength characters of each element in the name content.
203
226
* The elements will be created based on the name and some default values.
204
227
*
@@ -211,14 +234,22 @@ export default class CompasAutogenerateSubstation extends LitElement {
211
234
createVoltageLevels ( substation : Element , substationName : string ) {
212
235
const substationContent = this . iedNames
213
236
. filter ( value => value . includes ( substationName ) )
214
- . map ( FullName => FullName ?. split ( this . substationSeperator ) [ 1 ] ) ;
237
+ . map ( FullName => FullName ?. substring ( this . substationNameLength ) ) ;
215
238
216
239
const voltageLevelNames = this . extractNames (
217
240
substationContent . map ( FullName =>
218
241
FullName ?. substring ( 0 , this . voltageLevelNameLength )
219
242
)
220
243
) . filter ( value => ! value . startsWith ( 'A00' ) ) ;
221
244
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
+
222
253
if ( voltageLevelNames . length == 0 ) return ;
223
254
224
255
voltageLevelNames . forEach ( name => {
@@ -237,16 +268,12 @@ export default class CompasAutogenerateSubstation extends LitElement {
237
268
) ;
238
269
239
270
const voltageLevelContent = substationContent
240
- . filter ( value => value . startsWith ( name ) )
271
+ . filter ( value => value ? .startsWith ( name ) )
241
272
. map ( FullName =>
242
273
FullName ?. substring ( this . voltageLevelNameLength , FullName . length )
243
274
) ;
244
275
245
- this . createBays (
246
- voltageLevel ,
247
- voltageLevelContent ,
248
- substationName + this . substationSeperator + name
249
- ) ;
276
+ this . createBays ( voltageLevel , voltageLevelContent , substationName + name ) ;
250
277
substation . appendChild ( voltageLevel ) ;
251
278
} ) ;
252
279
}
@@ -271,6 +298,16 @@ export default class CompasAutogenerateSubstation extends LitElement {
271
298
voltageLevelContent . map ( iedName => iedName . split ( this . iedStartChar ) [ 0 ] )
272
299
) ;
273
300
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
+
274
311
bayNames . forEach ( name => {
275
312
const desc = 'Bay generated by CoMPAS' ;
276
313
const bayElement = createElement ( voltageLevel . ownerDocument , 'Bay' , {
@@ -351,4 +388,13 @@ export default class CompasAutogenerateSubstation extends LitElement {
351
388
( value , index ) => value && content . indexOf ( value ) === index
352
389
) ;
353
390
}
391
+
392
+ createLog ( type : number , content : string ) {
393
+ this . dispatchEvent (
394
+ newLogEvent ( {
395
+ kind : type == 0 ? 'info' : 'error' ,
396
+ title : content ,
397
+ } )
398
+ ) ;
399
+ }
354
400
}
0 commit comments