-
Notifications
You must be signed in to change notification settings - Fork 26
/
baseline.js
800 lines (709 loc) · 19.5 KB
/
baseline.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
const queryHelper = window.require('./query-helpers');
//Move baseline logic into classes and use an interface to here. This will allow different
//algorithmes to be easily used fo clustering and scoring values
//
/*
* Compute baseline for Huawei 2G Cell level MOs
*/
async function computeHuaweiGCellBaselineScore(mo, parameter){
const sql = `
INSERT INTO baseline.scores
(vendor, technology, cluster, mo, parameter, value, score)
SELECT
'HUAWEI' as vendor,
'2G' as technology,
t3.data->>'SYSOBJECTID' AS "cluster",
'${mo}' AS "mo",
'${parameter}' AS "parameter",
t1.data->>'${parameter}' as "value",
COUNT(1) AS "score"
FROM
huawei_cm."${mo}" t1
INNER JOIN huawei_cm."GCELL" t2
ON t2.data->>'CELLID' = t1.data->>'CELLID'
INNER JOIN huawei_cm."SYS" t3
ON t3.data->>'FILENAME' = T2.data->>'FILENAME'
GROUP BY
t3.data->>'SYSOBJECTID',
t1.data->>'${parameter}'
ON CONFLICT ON CONSTRAINT unq_scores DO UPDATE SET
score=EXCLUDED.score + scores.score
`
log.info(sql)
const result = await queryHelper.runQuery(sql);
}
/*
* Compute baseline for Huawei 3G Cell level MOs
*/
async function computeHuaweiUCellBaselineScore(mo, parameter){
const sql = `
INSERT INTO baseline.scores
(vendor, technology, cluster, mo, parameter, value, score)
SELECT
'HUAWEI' as vendor,
'3G' as technology,
t3.data->>'SYSOBJECTID' AS "cluster",
'${mo}' AS "mo",
'${parameter}' AS "parameter",
t1.data->>'${parameter}' as "value",
COUNT(1) AS "score"
FROM
huawei_cm."${mo}" t1
INNER JOIN huawei_cm."UCELL" t2
ON t2.data->>'CELLID' = t1.data->>'CELLID'
INNER JOIN huawei_cm."SYS" t3
ON t3.data->>'FILENAME' = t2.data->>'FILENAME'
GROUP BY
t3.data->>'SYSOBJECTID',
t1.data->>'${parameter}'
ON CONFLICT ON CONSTRAINT unq_scores DO UPDATE SET
score=EXCLUDED.score + scores.score
`
const result = await queryHelper.runQuery(sql);
}
//Compute baseline value for a BSC or RNC
async function computeHuaweiBaselineScore(tech, mo, parameter){
let sql = `
INSERT INTO baseline.scores
(vendor, technology, cluster, mo, parameter, value, score)
SELECT
'HUAWEI' as vendor,
'${tech}' as technology,
t2.data->>'SYSOBJECTID' AS "cluster",
'${mo}' AS "mo",
'${parameter}' AS "parameter",
t1.data->>'${parameter}' as "value",
COUNT(1) AS "score"
FROM
huawei_cm."${mo}" t1
INNER JOIN huawei_cm."SYS" t2
ON t1.data->>'FILENAME' = t2.data->>'FILENAME'
GROUP BY
t2.data->>'SYSOBJECTID',
t1.data->>'${parameter}'
ON CONFLICT ON CONSTRAINT unq_scores DO UPDATE SET
score=EXCLUDED.score + scores.score
`
if(tech === '4G'){
sql = `
INSERT INTO baseline.scores
(vendor, technology, cluster, mo, parameter, value, score)
SELECT
'HUAWEI' as vendor,
'${tech}' as technology,
t2.data->>'TAC' AS "cluster",
'${mo}' AS "mo",
'${parameter}' AS "parameter",
t1.data->>'${parameter}' as "value",
COUNT(1) AS "score"
FROM
huawei_cm."${mo}" t1
INNER JOIN huawei_cm."CNOPERATORTA" t2
ON t2.data->>'FILENAME' = t1.data->>'FILENAME'
GROUP BY
t2.data->>'TAC',
t1.data->>'${parameter}'
ON CONFLICT ON CONSTRAINT unq_scores DO UPDATE SET
score=EXCLUDED.score + scores.score
`;
}
const result = await queryHelper.runQuery(sql);
}
/*
* Compute Nokia baseline scores for Nokia
*
*/
async function computeNokiaBaselineScore(tech, mo, parameter){
//2G
let sql = `
INSERT INTO baseline.scores
(vendor, technology, cluster, mo, parameter, value, score)
SELECT
'NOKIA' as vendor,
'${tech}' as technology,
t2.data->>'name' AS "cluster",
'${mo}' AS "mo",
'${parameter}' AS "parameter",
t1.data->>'${parameter}' as "value",
COUNT(1) AS "score"
FROM
nokia_cm."${mo}" t1
INNER JOIN nokia_cm."BSC" t2
ON SUBSTRING(t2.data->>'DISTNAME' FROM '^.*BSC-\\d+') = SUBSTRING(t1.data->>'DISTNAME' FROM '^.*BSC-\\d+')
WHERE
t2.data->>'name' IS NOT NULL
AND t1.data->>'FILENAME' = t2.data->>'FILENAME'
GROUP BY
t2.data->>'name',
t1.data->>'${parameter}'
ON CONFLICT ON CONSTRAINT unq_scores DO UPDATE SET
score=EXCLUDED.score + scores.score
`
if(tech === '3G'){
sql = `
INSERT INTO baseline.scores
(vendor, technology, cluster, mo, parameter, value, score)
SELECT
'NOKIA' as vendor,
'${tech}' as technology,
t2.data->>'name' AS "cluster",
'${mo}' AS "mo",
'${parameter}' AS "parameter",
t1.data->>'${parameter}' as "value",
COUNT(1) AS "score"
FROM
nokia_cm."${mo}" t1
INNER JOIN nokia_cm."RNC" t2
ON SUBSTRING(t2.data->>'DISTNAME' FROM '^.*RNC-\\d+') = SUBSTRING(t1.data->>'DISTNAME' FROM '^.*RNC-\\d+')
WHERE
t2.data->>'name' IS NOT NULL
AND t1.data->>'FILENAME' = t2.data->>'FILENAME'
GROUP BY
t2.data->>'name',
t1.data->>'${parameter}'
ON CONFLICT ON CONSTRAINT unq_scores DO UPDATE SET
score=EXCLUDED.score + scores.score
`
}
//@TODO: Change this grouping to TAC
if(tech === '4G'){
sql = `
INSERT INTO baseline.scores
(vendor, technology, cluster, mo, parameter, value, score)
SELECT
'NOKIA' as vendor,
'${tech}' as technology,
t2.data->>'name' AS "cluster",
'${mo}' AS "mo",
'${parameter}' AS "parameter",
t1.data->>'${parameter}' as "value",
COUNT(1) AS "score"
FROM
nokia_cm."${mo}" t1
INNER JOIN nokia_cm."MRBTS" t2
ON SUBSTRING(t2.data->>'DISTNAME' FROM '^.*MRBTS-\\d+') = SUBSTRING(t1.data->>'DISTNAME' FROM '^.*MRBTS-\\d+')
WHERE
t2.data->>'name' IS NOT NULL
AND t1.data->>'FILENAME' = t2.data->>'FILENAME'
GROUP BY
t2.data->>'name',
t1.data->>'${parameter}'
ON CONFLICT ON CONSTRAINT unq_scores DO UPDATE SET
score=EXCLUDED.score + scores.score
`
}
console.log(sql);
const result = await queryHelper.runQuery(sql);
}
async function computeEricssonBaselineScore(tech, mo, parameter){
let sql = `
INSERT INTO baseline.scores
(vendor, technology, cluster, mo, parameter, value, score)
SELECT
'ERICSSON' as vendor,
'${tech}' as technology,
t1.data->>'BSC_NAME' AS "cluster",
'${mo}' AS "mo",
'${parameter}' AS "parameter",
t1.data->>'${parameter}' as "value",
COUNT(1) AS "score"
FROM
ericsson_cm."${mo}" t1
WHERE
t1.data->>'BSC_NAME' IS NOT NULL
AND TRIM(t1.data->>'BSC_NAME') != ''
GROUP BY
t1.data->>'BSC_NAME',
t1.data->>'${parameter}'
ON CONFLICT ON CONSTRAINT unq_scores DO UPDATE SET
score=EXCLUDED.score + scores.score
`
if(tech === '3G'){
sql = `
INSERT INTO baseline.scores
(vendor, technology, cluster, mo, parameter, value, score)
SELECT
'ERICSSON' as vendor,
'${tech}' as technology,
t1.data->>'SubNetwork_2_id' AS "cluster",
'${mo}' AS "mo",
'${parameter}' AS "parameter",
t1.data->>'${parameter}' as "value",
COUNT(1) AS "score"
FROM
ericsson_cm."${mo}" t1
WHERE
t1.data->>'SubNetwork_2_id' IS NOT NULL
AND TRIM(t1.data->>'SubNetwork_2_id') != ''
GROUP BY
t1.data->>'SubNetwork_2_id',
t1.data->>'${parameter}'
ON CONFLICT ON CONSTRAINT unq_scores DO UPDATE SET
score=EXCLUDED.score + scores.score
`;
}
if(tech === '4G'){
sql = `
INSERT INTO baseline.scores
(vendor, technology, cluster, mo, parameter, value, score)
SELECT
'ERICSSON' as vendor,
'${tech}' as technology,
t1.data->>'meContext_id' AS "cluster",
'${mo}' AS "mo",
'${parameter}' AS "parameter",
t1.data->>'${parameter}' as "value",
COUNT(1) AS "score"
FROM
ericsson_cm."${mo}" t1
WHERE
TRIM(t1.data->>'meContext_id') IS NOT NULL
AND TRIM(t1.data->>'meContext_id') != ''
GROUP BY
t1.data->>'meContext_id',
t1.data->>'${parameter}'
ON CONFLICT ON CONSTRAINT unq_scores DO UPDATE SET
score=EXCLUDED.score + scores.score
`;
}
const result = await queryHelper.runQuery(sql);
}
async function computeZTEBaselineScore(tech, mo, parameter){
if(tech === '2G' || tech === '3G'){
sql = `
INSERT INTO baseline.scores
(vendor, technology, cluster, mo, parameter, value, score)
SELECT
'ZTE' as vendor,
'${tech}' as technology,
t1.data->>'SubNetwork_2_id' AS "cluster",
'${mo}' AS "mo",
'${parameter}' AS "parameter",
t1.data->>'${parameter}' as "value",
COUNT(1) AS "score"
FROM
zte_cm."${mo}" t1
WHERE
t1.data->>'SubNetwork_2_id' IS NOT NULL
AND TRIM(t1.data->>'SubNetwork_2_id') != ''
GROUP BY
t1.data->>'SubNetwork_2_id',
t1.data->>'${parameter}'
ON CONFLICT ON CONSTRAINT unq_scores DO UPDATE SET
score=EXCLUDED.score + scores.score
`;
}
if(tech === '4G'){
sql = `
INSERT INTO baseline.scores
(vendor, technology, cluster, mo, parameter, value, score)
SELECT
'ZTE' as vendor,
'${tech}' as technology,
t1.data->>'meContext_id' AS "cluster",
'${mo}' AS "mo",
'${parameter}' AS "parameter",
t1.data->>'${parameter}' as "value",
COUNT(1) AS "score"
FROM
zte_cm."${mo}" t1
WHERE
TRIM(t1.data->>'meContext_id') IS NOT NULL
AND TRIM(t1.data->>'meContext_id') != ''
GROUP BY
t1.data->>'meContext_id',
t1.data->>'${parameter}'
ON CONFLICT ON CONSTRAINT unq_scores DO UPDATE SET
score=EXCLUDED.score + scores.score
`;
}
const result = await queryHelper.runQuery(sql);
}
/*
* Update the baseline comparison report query
*/
async function updateBaselineComparisonQuery(){
const res = await queryHelper.runQuery('SELECT DISTINCT cluster FROM baseline.values ORDER BY 1');
const clusterColStr = "\"" + res.rows.map(v => v.cluster).join('","') + "\""
const clusterCtStr = "\"" + res.rows.map(v => v.cluster).join('" character varying,"') + "\" character varying"
//Update table cell options
//color for baseline values is green
//color differences red
//empty values are not colored
let rptStyles = {}
rptStyles['BASELINE_VALUE'] = {
conditions:[
{
property: "background-color",
propertyValue: "green",
styleConditions: [
{
op: "EQUAL TO",
rValType: "COLUMN",
rValue: "BASELINE_VALUE",
}
]
},
{
property: "color",
propertyValue: "white",
styleConditions: [
{
op: "EQUAL TO",
rValType: "COLUMN",
rValue: "BASELINE_VALUE"
}
]
}
]
}
for(var i in res.rows){
const field = res.rows[i].cluster
rptStyles[field] = {
conditions:[
{
property: "background-color",
propertyValue: "red",
styleConditions: [
{
op: "NOT EQUAL TO",
rValType: "COLUMN",
rValue: "BASELINE_VALUE",
},
{
op: "LENGTH GREATER THAN",
rValType: "INPUT",
rValue: "0",
}
]
},
{
property: "color",
propertyValue: "white",
styleConditions: [
{
op: "NOT EQUAL TO",
rValType: "COLUMN",
rValue: "BASELINE_VALUE"
},
{
op: "LENGTH GREATER THAN",
rValType: "INPUT",
rValue: "0",
}
]
}
]
}
}
const rptOptions = JSON.stringify({type: "Table", tableStyles: rptStyles})
const sql = `
UPDATE reports.reports
SET
options = \$\$${rptOptions}\$\$,
query = \$\$
SELECT
vendor as "VENDOR",
technology AS "TECHNOLOGY",
mo AS "MO",
parameter AS "PARAMETER",
baseline AS "BASELINE_VALUE",
${clusterColStr}
FROM
crosstab(
'
SELECT
RANK() OVER (ORDER BY t1.vendor, t1.technology, t1.mo, t1.parameter, t1.cluster)::int AS row_name,
t1.vendor,
t1.technology,
t1.mo,
t1.parameter,
t2.baseline as baseline,
t1.cluster as category,
t1.value as "value"
from
baseline.values t1
LEFT join baseline.configuration t2
ON t2.vendor = t1.vendor
AND t2.technology = t1.technology
AND t2.mo = t1.mo
AND t2.parameter = t1.parameter
order by 1',
'
SELECT
DISTINCT cluster
FROM
baseline.values
ORDER BY 1
'
)
AS
ct(
row_name int,
vendor character varying,
technology character varying,
mo character varying,
parameter character varying,
baseline character varying,
${clusterCtStr}
)
\$\$
WHERE id = ( SELECT id as rpt_id FROM reports.reports WHERE name = 'Baseline Comparison' )
`
log.info(sql)
await queryHelper.runQuery(sql);
}
/*
* Cluster network based on provided algorithm
*
* @param string algorithm Clustering algorithm
*/
async function clusterNetwork(algorithm){
}
async function computeScores(scoreAlgo){
//Select MOs and parameters from baseline.configuration
const results = await queryHelper.runQuery("SELECT * FROM baseline.vw_configuration")
const rows = results.rows
if(rows.length > 0){
for(let v of rows) {
log.info(`Processing vendor:${v.vendor} tech:${v.technology} mo:${v.mo} parameter:${v.parameter}`)
if(v.vendor === 'HUAWEI'){
await computeHuaweiBaselineScore(v.technology, v.mo, v.parameter);
}
if(v.vendor === 'ERICSSON'){
await computeEricssonBaselineScore(v.technology, v.mo, v.parameter);
}
if(v.vendor === 'NOKIA'){
await computeNokiaBaselineScore(v.technology, v.mo, v.parameter);
}
if(v.vendor === 'ZTE'){
await computeZTEBaselineScore(v.technology, v.mo, v.parameter);
}
if(v.vendor === 'MOTOROLA'){
//@TODO: Implement ZTE baseline scoring
}
}
}
}
/*
* Compute baseline value for each cluster, mo, and parameter
*/
async function computeBaselineValues(){
log.info("Computing baseline values...")
const sql = `
INSERT INTO baseline.values
(cluster, vendor, technology, mo, parameter, "value")
SELECT cluster, vendor, technology, mo, parameter, value
FROM baseline.scores t1
WHERE
score = (
SELECT MAX(score)
FROM baseline.scores t2
WHERE
t2.vendor = t1.vendor
and t2.technology = t1.technology
and t2.cluster = t1.cluster
and t2.mo = t1.mo
and t2.parameter = t1.parameter
)
`
log.info(sql);
await queryHelper.runQuery(sql);
log.info("Computing baseline value done.")
}
/*
* Upload/import user baseline
*
* This is the operator baseline to use for auditing network
*
* @param string baselineFile Full path to baseline file
* @param boolean truncate Whether to truncate the table before importing the data
*/
async function uploadUserBaseline(baselineFile, truncate){
let parameterList = ['vendor', 'technology', 'mo', 'parameter', 'baseline'];
let paramIndices = []
//Add exclude logic
let updatePhrase = parameterList.map( p => `${p} = EXCLUDED.${p}`);
if(truncate === true ){
queryHelper.runQuery('TRUNCATE TABLE baseline.configuration RESTART IDENTITY');
}
await new Promise((resolve, reject) => {
csv({output: "csv", noheader:true, trim:true})
.fromFile(baselineFile)
.subscribe(async (csvRow, index)=>{
//Header column
if(index === 0){
//parameterList = csvRow;
//Populate parameter indices
//only consider values in the parameterList i.e with a filter
paramIndices = parameterList
.map(v => v.toLowerCase())
.map( v => csvRow.indexOf(v)).filter(v => v > -1)
return;
}
let values = paramIndices.map(v => csvRow[v])
const sql = `INSERT INTO baseline."configuration"
(${parameterList.join(",")})
VALUES
('${values.join("','")}')
ON CONFLICT ON CONSTRAINT unq_configuration DO UPDATE
SET
${updatePhrase.join(",")}
`;
log.log(sql);
await queryHelper.runQuery(sql);
},(err) => {//onError
log.error(`csvJoJson.onError: ${err.toString()}`);
resolve();
},
()=>{//onComplete
log.info(`End of csvToJson for ${baselineFile}.`)
resolve();
});
});//eof: promise
}
/*
* Auto generate parameter reference
*
*/
async function autoGenerateParameterRef(clearTableBefore){
if(clearTableBefore === true ){
await queryHelper.runQuery("TRUNCATE TABLE telecomlib.parameter_reference");
}
const VENDOR_CM_INFO = [
{
vendor: "HUAWEI",
cm_schema: "huawei_cm"
},
{
vendor: "ERICSSON",
cm_schema: "ericsson_cm"
},
{
vendor: "NOKIA",
cm_schema: "nokia_cm"
},
{
vendor: "ZTE",
cm_schema: "zte_cm"
}
];
for(let v of VENDOR_CM_INFO){
const colSql = `SELECT DISTINCT table_name
FROM information_schema.tables
WHERE table_schema = '${v.cm_schema}'
AND table_type = 'BASE TABLE'`;
const colSqlRes = await queryHelper.runQuery(colSql);
for( let t of colSqlRes.rows){
const sql = `
INSERT INTO telecomlib.parameter_reference
(vendor, technology, mo, parameter_id, parameter_name, granurality)
SELECT
'${v.vendor}' as vendor,
COALESCE(t2.technology,'UNKNOWN') AS technology,
'${t.table_name}' as mo,
key as parameter_id,
key as parameter_name,
COALESCE(t2.granurality, 'UNKNOWN') as granurality
FROM (
SELECT DISTINCT jsonb_object_keys(data) AS key
FROM
${v.cm_schema}."${t.table_name}"
) t1
LEFT JOIN telecomlib.managed_objects t2
ON t2.vendor = '${v.vendor}'
AND t2.mo = '${t.table_name}'
WHERE
t2.technology IS NOT NULL
ON CONFLICT ON CONSTRAINT unq_parameter_reference DO NOTHING
`;
console.log(sql)
await queryHelper.runQuery(sql);
}
}
}
/*
* Upload/import parameter reference
*
* @param string fileName Full path to parameter reference file
* @param boolean truncate Whether to truncate the table before importing the data
*/
async function uploadParameterReference(fileName, truncate){
let parameterList = ['vendor', 'technology', 'mo', 'parameter_id', 'parameter_name', 'is_key', 'granurality', 'description'];
let paramIndices = []
//Add exclude logic
let updatePhrase = parameterList.map( p => `${p} = EXCLUDED.${p}`);
if(truncate === true ){
queryHelper.runQuery('TRUNCATE TABLE telecomlib.parameter_reference RESTART IDENTITY');
}
await new Promise((resolve, reject) => {
csv({output: "csv", noheader:true, trim:true})
.fromFile(fileName)
.subscribe(async (csvRow, index)=>{
//Header column
if(index === 0){
//parameterList = csvRow;
//Populate parameter indices
//only consider values in the parameterList i.e with a filter
paramIndices = parameterList
.map(v => v.toLowerCase())
.map( v => csvRow.indexOf(v)).filter(v => v > -1)
return;
}
let values = paramIndices.map(v => csvRow[v])
const sql = `INSERT INTO telecomlib."parameter_reference"
(${parameterList.join(",")})
VALUES
('${values.join("','")}')
ON CONFLICT ON CONSTRAINT unq_configuration DO UPDATE
SET
${updatePhrase.join(",")}
`;
log.log(sql);
await queryHelper.runQuery(sql);
},(err) => {//onError
log.error(`csvJoJson.onError: ${err.toString()}`);
resolve();
},
()=>{//onComplete
log.info(`End of csvToJson for ${fileName}.`)
resolve();
});
});//eof: promise
}
async function updateBaselineParameter(vendor, tech, mo, parameter, baseline){
const sql = `INSERT INTO baseline."configuration"
(vendor, technology, mo, parameter, baseline)
VALUES
('${vendor}', '${tech}', '${mo}', '${parameter}', '${baseline}')
ON CONFLICT ON CONSTRAINT unq_configuration DO UPDATE
SET
baseline = EXCLUDED.baseline
`;
const result = await queryHelper.runQuery(sql);
}
/*
* Compute baseline
*
* @param string clustering Clustering algorithm
* @param string scoring Scoring algorithm
*/
async function computeBaseline(clustering, scoring){
//Clear previous scores
await queryHelper.runQuery("TRUNCATE TABLE baseline.scores RESTART IDENTITY");
await queryHelper.runQuery("TRUNCATE TABLE baseline.values RESTART IDENTITY");
//Cluster network
await clusterNetwork(clustering);
//Compute scores. Get the counts
await computeScores(scoring);
//Compute baseline values from scores
await computeBaselineValues()
//Update baseline comparison query
await updateBaselineComparisonQuery();
}
exports.updateBaselineParameter = updateBaselineParameter;
exports.computeBaseline = computeBaseline;
exports.clusterNetwork = clusterNetwork ;
exports.uploadUserBaseline = uploadUserBaseline ;
exports.uploadParameterReference = uploadParameterReference;
exports.autoGenerateParameterRef = autoGenerateParameterRef;