-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
2276 lines (2003 loc) · 90.4 KB
/
index.html
File metadata and controls
2276 lines (2003 loc) · 90.4 KB
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
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Telecom Data Analyzer</title>
<!-- PapaParse for CSV parsing -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.4.1/papaparse.min.js"></script>
<!-- SheetJS for Excel parsing -->
<script src="https://cdn.sheetjs.com/xlsx-0.20.1/package/dist/xlsx.full.min.js"></script>
<!-- Add Bootstrap for better styling -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #f2f2f2; cursor: pointer; }
input, select, button { margin: 5px 10px 5px 0; }
.filter-group { margin: 10px 0; }
.name-mapping { border: 1px solid #ddd; padding: 10px; margin-bottom: 20px; }
.nav-tabs { margin-bottom: 20px; }
.tab-content { padding: 20px 0; }
.data-type-config { border: 1px solid #ddd; padding: 15px; margin-bottom: 15px; border-radius: 5px; }
.field-mapping { margin-bottom: 10px; }
.dropdown-menu { max-height: 300px; overflow-y: auto; }
</style>
</head>
<body>
<div class="container-fluid">
<!-- Add Tutorial Button -->
<div class="text-end mb-3">
<a href="https://github.com/ColinVaughn/CSV-Tower-Viewer/tree/main" target="_blank" class="btn btn-info">
<i class="bi bi-github"></i> Tutorial & Source Code
</a>
</div>
<!-- Main Tabs -->
<ul class="nav nav-tabs" id="mainTabs" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="viewer-tab" data-bs-toggle="tab" data-bs-target="#viewer" type="button" role="tab">Data Viewer</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="config-tab" data-bs-toggle="tab" data-bs-target="#config" type="button" role="tab">Data Type Configuration</button>
</li>
</ul>
<div class="tab-content" id="mainTabsContent">
<!-- Data Viewer Tab -->
<div class="tab-pane fade show active" id="viewer" role="tabpanel" aria-labelledby="viewer-tab">
<!-- Name Mapping Section Moved to the Top -->
<div class="card mb-3">
<div class="card-header">
<h5>Name Mapping</h5>
</div>
<div class="card-body">
<div class="row mb-2">
<div class="col-md-4">
<input type="text" class="form-control" id="mapPhone" placeholder="Phone Number">
</div>
<div class="col-md-4">
<input type="text" class="form-control" id="mapName" placeholder="Assign Name">
</div>
<div class="col-md-4">
<button class="btn btn-primary" onclick="assignName()">Assign Name</button>
</div>
</div>
<div class="row">
<div class="col-md-6">
<button class="btn btn-secondary" onclick="exportNameMapping()">Export Name Mapping CSV</button>
</div>
<div class="col-md-6">
<div class="input-group">
<input type="file" class="form-control" id="importMappingFile" accept=".csv" onchange="importNameMapping(event)">
<label class="input-group-text" for="importMappingFile">Import Mapping</label>
</div>
</div>
</div>
</div>
</div>
<div class="card mb-3">
<div class="card-header">
<h5>Upload Files</h5>
</div>
<div class="card-body">
<div class="row mb-2">
<div class="col-md-6">
<input type="file" class="form-control" id="csvFile" multiple accept=".csv,.xlsx,.xls">
</div>
<div class="col-md-3">
<button class="btn btn-primary" onclick="processFiles()">Process Files</button>
</div>
<div class="col-md-3">
<select class="form-select" id="fileTypeSelector">
<option value="auto">Auto-detect File Type</option>
<option value="call">Call Records</option>
<option value="text">Text/MMS Records</option>
<option value="device">Device Info</option>
<option value="payment">Payment Records</option>
<option value="account">Account Info</option>
<option value="other">Other</option>
</select>
</div>
</div>
<div id="fileTypeDetection" class="alert alert-info" style="display: none;">
File type detected: <span id="detectedFileType"></span>
<button class="btn btn-sm btn-outline-primary ms-3" id="createTypeBtn" style="display: none;">Create Custom Type</button>
</div>
</div>
</div>
<div class="card mb-3">
<div class="card-header d-flex justify-content-between">
<h5>Search & Filters</h5>
<div>
<button class="btn btn-sm btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#searchCollapse">
Toggle Search Panel
</button>
</div>
</div>
<div class="collapse show" id="searchCollapse">
<div class="card-body">
<div class="row mb-2">
<div class="col-md-6">
<input type="text" class="form-control" id="searchBox" placeholder="Search by any text" oninput="searchTable()">
</div>
<div class="col-md-3">
<select class="form-select" id="activeDataType">
<option value="all">All Data Types</option>
<!-- Will be populated dynamically -->
</select>
</div>
<div class="col-md-3">
<div class="btn-group" role="group">
<button class="btn btn-outline-primary" onclick="applyAdvancedFilters()">Apply Filters</button>
<button class="btn btn-outline-secondary" onclick="resetFilters()">Reset</button>
</div>
</div>
</div>
<div id="dynamicFilters">
<!-- Dynamic filter UI will be inserted here based on file type -->
</div>
<div class="mt-3" id="callDataFilters">
<h6>Call Record Filters</h6>
<div class="row">
<div class="col-md-3">
<label for="startDate">Start Date:</label>
<input type="datetime-local" class="form-control" id="startDate">
</div>
<div class="col-md-3">
<label for="endDate">End Date:</label>
<input type="datetime-local" class="form-control" id="endDate">
</div>
<div class="col-md-3">
<label for="minDuration">Min Duration (s):</label>
<input type="number" class="form-control" id="minDuration" placeholder="Min Duration">
</div>
<div class="col-md-3">
<label for="maxDuration">Max Duration (s):</label>
<input type="number" class="form-control" id="maxDuration" placeholder="Max Duration">
</div>
</div>
<div class="row mt-2">
<div class="col-md-3">
<label for="cellTower">Cell Tower ID:</label>
<input type="text" class="form-control" id="cellTower" placeholder="Enter Tower ID">
</div>
<div class="col-md-3">
<label for="callDirection">Call Direction:</label>
<select class="form-select" id="callDirection">
<option value="">Any</option>
<option value="incoming">Incoming</option>
<option value="outgoing">Outgoing</option>
</select>
</div>
<div class="col-md-3">
<label for="searchMsisdn">Msisdn Search:</label>
<input type="text" class="form-control" id="searchMsisdn" placeholder="Enter Phone Number">
</div>
<div class="col-md-3">
<label for="searchLocation">Search Location:</label>
<input type="text" class="form-control" id="searchLocation" placeholder="e.g., Address, Location">
</div>
</div>
<div class="row mt-2">
<div class="col-md-3">
<label for="minTowers">Min Towers:</label>
<input type="number" class="form-control" id="minTowers" placeholder="Min Towers">
</div>
<div class="col-md-3">
<label for="maxTowers">Max Towers:</label>
<input type="number" class="form-control" id="maxTowers" placeholder="Max Towers">
</div>
<div class="col-md-6 mt-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="groupByPhone">
<label class="form-check-label" for="groupByPhone">
Group by Phone (Aggregate Towers & Locations)
</label>
</div>
</div>
</div>
</div>
<div class="mt-3" id="messageDataFilters" style="display: none;">
<h6>Message Record Filters</h6>
<div class="row">
<div class="col-md-3">
<label for="msgStartDate">Start Date:</label>
<input type="datetime-local" class="form-control" id="msgStartDate">
</div>
<div class="col-md-3">
<label for="msgEndDate">End Date:</label>
<input type="datetime-local" class="form-control" id="msgEndDate">
</div>
<div class="col-md-3">
<label for="msgType">Message Type:</label>
<select class="form-select" id="msgType">
<option value="">Any</option>
<option value="sms">SMS</option>
<option value="mms">MMS</option>
</select>
</div>
<div class="col-md-3">
<label for="msgDirection">Direction:</label>
<select class="form-select" id="msgDirection">
<option value="">Any</option>
<option value="MO">Outgoing (MO)</option>
<option value="MT">Incoming (MT)</option>
</select>
</div>
</div>
<div class="row mt-2">
<div class="col-md-6">
<label for="msgContent">Message Content:</label>
<input type="text" class="form-control" id="msgContent" placeholder="Search message content">
</div>
<div class="col-md-3">
<label for="msgSender">Sender:</label>
<input type="text" class="form-control" id="msgSender" placeholder="Sender phone/address">
</div>
<div class="col-md-3">
<label for="msgRecipient">Recipient:</label>
<input type="text" class="form-control" id="msgRecipient" placeholder="Recipient phone/address">
</div>
</div>
</div>
<div class="mt-3" id="deviceDataFilters" style="display: none;">
<h6>Device Info Filters</h6>
<div class="row">
<div class="col-md-4">
<label for="deviceId">Device ID/IMEI:</label>
<input type="text" class="form-control" id="deviceId" placeholder="Device ID or IMEI">
</div>
<div class="col-md-4">
<label for="deviceType">Device Type:</label>
<input type="text" class="form-control" id="deviceType" placeholder="Device type">
</div>
<div class="col-md-4">
<label for="deviceMfg">Manufacturer:</label>
<input type="text" class="form-control" id="deviceMfg" placeholder="Manufacturer name">
</div>
</div>
</div>
<div class="mt-3" id="dataSessionFilters" style="display: none;">
<h6>Data Session Filters</h6>
<div class="row">
<div class="col-md-3">
<label for="dsStartDate">Start Date:</label>
<input type="datetime-local" class="form-control" id="dsStartDate">
</div>
<div class="col-md-3">
<label for="dsEndDate">End Date:</label>
<input type="datetime-local" class="form-control" id="dsEndDate">
</div>
<div class="col-md-3">
<label for="dsTowerId">Tower ID:</label>
<input type="text" class="form-control" id="dsTowerId" placeholder="Enter Tower ID">
</div>
<div class="col-md-3">
<label for="dsCellId">Cell ID:</label>
<input type="text" class="form-control" id="dsCellId" placeholder="Enter Cell ID">
</div>
</div>
<div class="row mt-2">
<div class="col-md-3">
<label for="dsMinDuration">Min Duration (s):</label>
<input type="number" class="form-control" id="dsMinDuration" placeholder="Min Duration">
</div>
<div class="col-md-3">
<label for="dsMaxDuration">Max Duration (s):</label>
<input type="number" class="form-control" id="dsMaxDuration" placeholder="Max Duration">
</div>
<div class="col-md-3">
<label for="dsIpAddress">IP Address:</label>
<input type="text" class="form-control" id="dsIpAddress" placeholder="IP Address">
</div>
<div class="col-md-3">
<label for="dsNatIpAddress">NAT IP Address:</label>
<input type="text" class="form-control" id="dsNatIpAddress" placeholder="NAT IP Address">
</div>
</div>
<div class="row mt-2">
<div class="col-md-3">
<label for="dsTechnology">Network Technology:</label>
<select class="form-select" id="dsTechnology">
<option value="">Any</option>
<option value="4g">4G</option>
<option value="5g">5G</option>
<option value="lte">LTE</option>
<option value="nr">NR</option>
</select>
</div>
<div class="col-md-3">
<label for="dsLocation">Location/Address:</label>
<input type="text" class="form-control" id="dsLocation" placeholder="Enter location or address">
</div>
<div class="col-md-3">
<label for="dsMinDataVolume">Min Data Volume (KB):</label>
<input type="number" class="form-control" id="dsMinDataVolume" placeholder="Min KB">
</div>
<div class="col-md-3">
<label for="dsMaxDataVolume">Max Data Volume (KB):</label>
<input type="number" class="form-control" id="dsMaxDataVolume" placeholder="Max KB">
</div>
</div>
<div class="row mt-2">
<div class="col-md-3">
<label for="dsPortAllocTime">Port Alloc Date/Time:</label>
<input type="text" class="form-control" id="dsPortAllocTime" placeholder="Enter port alloc time">
</div>
<div class="col-md-9">
<!-- Placeholder for future filters -->
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header d-flex justify-content-between">
<h5 id="tableTitle">Data Analysis</h5>
<div>
<button class="btn btn-sm btn-success" onclick="exportCSV()">Export Filtered CSV</button>
</div>
</div>
<div class="card-body table-responsive">
<table id="resultTable" class="table table-striped table-hover">
<thead>
<tr id="tableHeader">
<!-- Header content will be set dynamically -->
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
<!-- Data Type Configuration Tab -->
<div class="tab-pane fade" id="config" role="tabpanel" aria-labelledby="config-tab">
<div class="card">
<div class="card-header">
<h5>Data Type Definitions</h5>
</div>
<div class="card-body">
<div class="row mb-3">
<div class="col-md-4">
<select class="form-select" id="dataTypeSelector">
<option value="">-- Select Data Type --</option>
<option value="new">Create New Data Type</option>
<!-- Will be populated dynamically -->
</select>
</div>
<div class="col-md-8">
<div class="btn-group" role="group">
<button class="btn btn-primary" id="editDataTypeBtn" disabled>Edit</button>
<button class="btn btn-success" id="saveDataTypeBtn">Save</button>
<button class="btn btn-danger" id="deleteDataTypeBtn" disabled>Delete</button>
<button class="btn btn-secondary" id="exportDataTypesBtn">Export Definitions</button>
<input type="file" id="importDataTypesFile" accept=".json" style="display: none;" onchange="importDataTypeDefinitions(event)">
<button class="btn btn-info" onclick="document.getElementById('importDataTypesFile').click()">Import Definitions</button>
</div>
</div>
</div>
<div id="dataTypeConfig" class="data-type-config">
<div class="row mb-3">
<div class="col-md-6">
<label for="dtName">Data Type Name:</label>
<input type="text" class="form-control" id="dtName" placeholder="e.g., Call Records, Text Messages">
</div>
<div class="col-md-6">
<label for="dtIdentifier">File Identifier Pattern:</label>
<input type="text" class="form-control" id="dtIdentifier" placeholder="e.g., VOLTE, TextDetail, Payment">
</div>
</div>
<h6>Field Definitions</h6>
<div id="fieldDefinitions">
<!-- Field definition template -->
<div class="field-mapping template" style="display: none;">
<div class="row">
<div class="col-md-3">
<input type="text" class="form-control field-name" placeholder="Display Name">
</div>
<div class="col-md-5">
<input type="text" class="form-control field-keys" placeholder="Possible column names (comma separated)">
</div>
<div class="col-md-2">
<select class="form-control field-type">
<option value="text">Text</option>
<option value="number">Number</option>
<option value="date">Date</option>
<option value="boolean">Boolean</option>
</select>
</div>
<div class="col-md-2">
<div class="btn-group btn-group-sm" role="group">
<button class="btn btn-sm btn-danger remove-field">Remove</button>
</div>
</div>
</div>
</div>
</div>
<button class="btn btn-outline-primary mt-3" id="addFieldBtn">Add Field</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
// Global variables
let currentDataset = [];
let currentFilteredDataset = []; // To store the filtered dataset
let nameMapping = {}; // Global mapping for phone numbers to names
let dataTypeDefinitions = {}; // To store data type definitions
let detectedDataTypes = new Set(); // Currently detected data types
let currentFields; // To store current fields for dynamic filtering
// Global variables for sorting
let sortColumn = -1;
let sortDirection = 1; // 1 for ascending, -1 for descending
// Initialize with built-in data types
function initializeDataTypes() {
// Call Records data type
dataTypeDefinitions.call = {
name: "Call Records",
identifier: "volte|voci|call|cdr",
fields: [
{ name: "Msisdn", keys: ["msisdn", "volte msisdn"], type: "text" },
{ name: "Search Value", keys: ["search value", "volte search value"], type: "text" },
{ name: "Search Start", keys: ["search start (gmt)", "volte search start (gmt)", "search start", "start date"], type: "date" },
{ name: "Search End", keys: ["search end (gmt)", "volte search end (gmt)", "search end", "end date"], type: "date" },
{ name: "Record Open Time", keys: ["rcd open dt/tm (gmt)", "record open dt/tm(gmt)", "record open date/time", "volte rcd open dt/tm(gmt)", "volte record open date/time", "call date", "call time"], type: "date" },
{ name: "Duration", keys: ["timeusage", "sou", "duration"], type: "number" },
{ name: "Call Direction", keys: ["calldirection", "dir", "volte dir"], type: "text" },
{ name: "Calling Party", keys: ["calling party no", "cpn", "volte cpn", "volte calling party no"], type: "text" },
{ name: "Called Party", keys: ["called prty addr", "called #", "volte called #", "volte called prty addr"], type: "text" },
{ name: "Primary Tower", keys: ["mkt enodeb id", "enb id", "market id", "volte enb id", "volte market id", "volte mkt enodeb id"], type: "text" },
{ name: "Cell ID", keys: ["ani cell id", "cell id", "volte cell id", "volte ani cell id"], type: "text" },
{ name: "Cell Face", keys: ["cell face", "face", "sector", "cell_face"], type: "text" },
{ name: "RAT", keys: ["rat", "radio access type", "radio access technology"], type: "text" },
{ name: "SID", keys: ["sid", "system id"], type: "text" },
{ name: "NID", keys: ["nid", "network id"], type: "text" },
{ name: "ENDPOINT", keys: ["endpoint"], type: "text" },
{ name: "VZWNE/V4B", keys: ["vzwne/v4b"], type: "text" }
]
};
// Text Messages data type
dataTypeDefinitions.text = {
name: "Text Messages",
identifier: "sms|text|mms|message|textdetail",
fields: [
{ name: "Message Time", keys: ["messagearrival", "record date/time", "submission date/time", "date/time", "message date"], type: "date" },
{ name: "Message Type", keys: ["network element name"], type: "text" },
{ name: "Direction", keys: ["charge information"], type: "text" },
{ name: "Sender", keys: ["originator address", "originatingmdn"], type: "text" },
{ name: "Recipient", keys: ["recipient address", "recipient addresses", "terminatingmdn"], type: "text" },
{ name: "Content", keys: ["messagecontent"], type: "text" },
{ name: "Status", keys: ["messagefinalstatus", "finaldisposition"], type: "text" },
{ name: "Size", keys: ["message size"], type: "number" },
{ name: "Msisdn", keys: ["searchmtn", "mdn"], type: "text" }
]
};
// Device Info data type
dataTypeDefinitions.device = {
name: "Device Information",
identifier: "device|imei|deviceid",
fields: [
{ name: "Msisdn", keys: ["mtn"], type: "text" },
{ name: "MIN", keys: ["min"], type: "text" },
{ name: "Device ID", keys: ["device_id"], type: "text" },
{ name: "IMEI", keys: ["imei"], type: "text" },
{ name: "IMSI", keys: ["imsi"], type: "text" },
{ name: "Manufacturer", keys: ["mfg_name"], type: "text" },
{ name: "Device Name", keys: ["eqp_name"], type: "text" },
{ name: "Device Type", keys: ["device_type"], type: "text" },
{ name: "Status", keys: ["mtn_status"], type: "text" },
{ name: "Effective Date", keys: ["mtn_effective_date", "mtn status effective date", "status effective date"], type: "date" }
]
};
// Account Info data type
dataTypeDefinitions.account = {
name: "Account Information",
identifier: "account|actdeact|subscriber|ssn",
fields: [
{ name: "Msisdn", keys: ["search value", "mtn"], type: "text" },
{ name: "Account Number", keys: ["account number"], type: "text" },
{ name: "Name", keys: ["last name", "first name", "business name"], type: "text" },
{ name: "Status", keys: ["mtn status code"], type: "text" },
{ name: "Effective Date", keys: ["mtn effective date", "mtn status effective date"], type: "date" },
{ name: "Disconnect Date", keys: ["disconnect date"], type: "date" }
]
};
// Payment data type
dataTypeDefinitions.payment = {
name: "Payment Records",
identifier: "payment|invoice|bill",
fields: [
{ name: "Msisdn", keys: ["search mtn"], type: "text" },
{ name: "Account Number", keys: ["account number"], type: "text" },
{ name: "Date", keys: ["date", "invoice date", "bill cycle start date", "bill cycle end date"], type: "date" },
{ name: "Amount", keys: ["payment amount", "previous balance", "current charges", "total balance"], type: "number" },
{ name: "Payment Method", keys: ["payment method"], type: "text" },
{ name: "Payment Source", keys: ["payment source"], type: "text" },
{ name: "Payment Status", keys: ["payment status"], type: "text" }
]
};
// Data Session/Cell Site data type
dataTypeDefinitions.datasession = {
name: "Data Session Records",
identifier: "cellsites|cell-sites|data_sessions|data sessions|4g|5g|tdr|ip|p-bdr",
fields: [
{ name: "MSISDN", keys: ["msisdn", "phone", "phonenumber", "number", "device_number", "calling_number"], type: "text" },
{ name: "Session Start", keys: ["session_start", "start_time", "starttime", "session_date", "date", "start_date"], type: "date" },
{ name: "Session End", keys: ["session_end", "end_time", "endtime", "end_date"], type: "date" },
{ name: "Duration", keys: ["duration", "session_duration", "time_seconds", "seconds", "duration_sec", "duration_seconds"], type: "number" },
{ name: "Cell ID", keys: ["cell_id", "cellid", "cell", "sector", "sector_id", "sectorid"], type: "text" },
{ name: "Tower ID", keys: ["tower_id", "towerid", "tower", "site_id", "siteid"], type: "text" },
{ name: "Sector", keys: ["sector", "cell_sector", "sectorid", "sector_id"], type: "text" },
{ name: "Data Volume", keys: ["data_volume", "volume", "data_usage", "usage", "bytes", "kb", "mb", "data"], type: "number" },
{ name: "IP Address", keys: ["ip", "ip_address", "ipaddress", "mbl_ip", "mbl_ip_addr", "mbl ip addr"], type: "text" },
{ name: "NAT IP Address", keys: ["nat_ip", "nat_ip_address", "nat ipaddress", "nat ip addr", "ext_ip"], type: "text" },
{ name: "IMEI", keys: ["imei", "device_id", "deviceid", "equipment_id"], type: "text" },
{ name: "Location", keys: ["location", "cell_location", "tower_location", "site_location"], type: "text" },
{ name: "Technology", keys: ["technology", "tech", "network_type", "networktype", "service_type"], type: "text" },
{ name: "Port Alloc Date/Time", keys: ["port_alloc_date_time", "port_alloc_date", "port allocation date/time", "port_allocation_date", "port alloc"], type: "date" }
]
};
// Update data type selectors
updateDataTypeSelectors();
}
// Update data type selectors in the UI
function updateDataTypeSelectors() {
const dataTypeSelector = document.getElementById('dataTypeSelector');
const activeDataType = document.getElementById('activeDataType');
// Clear existing options except default ones
while (dataTypeSelector.options.length > 2) {
dataTypeSelector.remove(2);
}
while (activeDataType.options.length > 1) {
activeDataType.remove(1);
}
// Add options for each data type
for (const [key, dataType] of Object.entries(dataTypeDefinitions)) {
const option1 = document.createElement('option');
option1.value = key;
option1.textContent = dataType.name;
dataTypeSelector.appendChild(option1);
const option2 = document.createElement('option');
option2.value = key;
option2.textContent = dataType.name;
activeDataType.appendChild(option2);
}
// Add detected data types to active data type selector
detectedDataTypes.forEach(type => {
if (dataTypeDefinitions[type]) {
const option = document.createElement('option');
option.value = type;
option.textContent = dataTypeDefinitions[type].name;
if (!Array.from(activeDataType.options).some(opt => opt.value === type)) {
activeDataType.appendChild(option);
}
}
});
}
// Create field definition UI
function createFieldDefinitionUI(field = null) {
const template = document.querySelector('.field-mapping.template');
const newField = template.cloneNode(true);
newField.classList.remove('template');
newField.style.display = '';
if (field) {
newField.querySelector('.field-name').value = field.name;
newField.querySelector('.field-keys').value = field.keys.join(', ');
newField.querySelector('.field-type').value = field.type;
}
newField.querySelector('.remove-field').addEventListener('click', function() {
newField.remove();
});
document.getElementById('fieldDefinitions').appendChild(newField);
return newField;
}
// Helper function to get field value from a record using multiple possible keys
function getField(record, possibleKeys) {
// Special handling for cell face and tower-related fields
const nonDateFieldKeys = ['cell face', 'face', 'cell_face', 'sector', 'sid', 'nid', 'endpoint', 'vzwne/v4b', 'rat'];
const isNonDateField = possibleKeys.some(key => nonDateFieldKeys.includes(key.toLowerCase()));
// Special handling for duration fields to avoid confusion with datetime fields
const isDurationField = possibleKeys.some(key =>
['duration', 'session_duration', 'time_seconds', 'seconds', 'duration_sec', 'duration_seconds'].includes(key.toLowerCase())
);
// First attempt: check for exact key matches
for (const key of possibleKeys) {
if (record[key] !== undefined && record[key] !== null && record[key] !== "") {
// Special handling for duration field
if (isDurationField) {
// Ensure duration is treated as a number, not a date/time
const val = record[key];
// If the value is a string that looks like a date, it's probably not duration
if (typeof val === 'string' && (val.includes('/') || val.includes('-') && val.includes(':'))) {
continue; // Skip this value, it's likely not a duration
}
return val;
}
return record[key];
}
}
// Second attempt: try case-insensitive matching
const recordKeys = Object.keys(record);
for (const key of possibleKeys) {
const keyLower = key.toLowerCase();
// Special handling for IP address fields to prevent overlap
if (keyLower === "mbl ip addr" || keyLower === "ip address" || keyLower === "ip addr") {
// When looking for regular IP address, exclude NAT fields
for (const recordKey of recordKeys) {
const recordKeyLower = recordKey.toLowerCase();
if ((recordKeyLower.includes(keyLower) || keyLower.includes(recordKeyLower)) &&
!recordKeyLower.includes("nat")) {
return record[recordKey];
}
}
}
else if (keyLower === "mbl ip addr nat" || keyLower === "nat ip address" || keyLower.includes("nat")) {
// When looking for NAT IP address, only include NAT fields
for (const recordKey of recordKeys) {
const recordKeyLower = recordKey.toLowerCase();
if (recordKeyLower.includes("nat") &&
(recordKeyLower.includes("ip") || recordKeyLower.includes("address"))) {
return record[recordKey];
}
}
}
else if (isDurationField) {
// For duration fields, be more selective
for (const recordKey of recordKeys) {
const recordKeyLower = recordKey.toLowerCase();
if ((recordKeyLower.includes('duration') || recordKeyLower.includes('seconds')) &&
!recordKeyLower.includes('date') && !recordKeyLower.includes('time')) {
// Check if the value looks like a duration (number) and not a date
const val = record[recordKey];
if (typeof val === 'number' || (typeof val === 'string' && !val.includes(':') && !isNaN(parseFloat(val)))) {
return val;
}
}
}
}
else {
// Standard fuzzy matching for non-IP fields
for (const recordKey of recordKeys) {
const recordKeyLower = recordKey.toLowerCase();
if (recordKeyLower.includes(keyLower) || keyLower.includes(recordKeyLower)) {
// For non-date fields, return as is - don't convert to date even if it looks like one
if (isNonDateField) {
return record[recordKey].toString();
}
return record[recordKey];
}
}
}
}
// If no match found for duration, try to calculate it
if (isDurationField) {
try {
// See if we can calculate duration from start and end times
const startTimeStr = getField(record, ["session_start", "start_time", "starttime", "session_date", "date", "start_date"]);
const endTimeStr = getField(record, ["session_end", "end_time", "endtime", "end_date"]);
if (startTimeStr && endTimeStr) {
const startTime = new Date(startTimeStr);
const endTime = new Date(endTimeStr);
if (!isNaN(startTime.getTime()) && !isNaN(endTime.getTime())) {
const durationSeconds = Math.round((endTime - startTime) / 1000);
return durationSeconds > 0 ? durationSeconds : "";
}
}
} catch (e) {
console.log("Error calculating duration:", e);
}
}
// If still no match, return empty string
return "";
}
// Helper for VOLTE extras
function getVolteExtras(record) {
let extras = [];
const fields = [
{ label: "SID", keys: ["sid"] },
{ label: "NID", keys: ["nid"] },
{ label: "Cell Face", keys: ["cell face"] },
{ label: "RAT", keys: ["rat"] },
{ label: "ENDPOINT", keys: ["endpoint"] },
{ label: "VZWNE/V4B", keys: ["vzwne/v4b"] }
];
fields.forEach(f => {
let val = getField(record, f.keys);
if(val) extras.push(f.label + ": " + val);
});
return extras.join(" | ");
}
// Helper for VOCE offsets
function getVoceOffsets(record) {
let offsets = [];
const fields = [
{ label: "Rcd Open Ts Offset", keys: ["rcd open ts offset"] },
{ label: "RcdCloseTsOffset", keys: ["rcdclosetsoffset"] },
{ label: "GMT Offset", keys: ["gmt offset"] }
];
fields.forEach(f => {
let val = getField(record, f.keys);
if(val) offsets.push(f.label + ": " + val);
});
return offsets.join(" | ");
}
// Detect file type based on filename and header with improved pattern matching
function detectFileType(fileName, headers) {
// Convert headers to lowercase for case-insensitive matching
const lowerHeaders = headers.map(h => h.toLowerCase());
console.log("Detecting file type for:", fileName);
console.log("Available headers:", lowerHeaders);
// Special case for P-BDR data session files
if (fileName.toLowerCase().includes('p-bdr') &&
(fileName.toLowerCase().includes('data_sessions') ||
fileName.toLowerCase().includes('4g') ||
fileName.toLowerCase().includes('5g'))) {
console.log("Special case detected: P-BDR data session file");
return 'datasession';
}
// First try to match based on file name
for (const [key, definition] of Object.entries(dataTypeDefinitions)) {
const regex = new RegExp(definition.identifier, 'i');
if (regex.test(fileName)) {
console.log(`File type matched by name pattern: ${key} (${definition.name})`);
return key;
}
}
// If no match by filename, try to match by headers
const matchScores = {};
for (const [key, definition] of Object.entries(dataTypeDefinitions)) {
let matchCount = 0;
let totalKeyCount = 0;
definition.fields.forEach(field => {
field.keys.forEach(fieldKey => {
totalKeyCount++;
// Try exact match first
if (lowerHeaders.includes(fieldKey.toLowerCase())) {
matchCount += 2; // Give higher weight to exact matches
} else {
// Try partial/fuzzy matching
for (const header of lowerHeaders) {
if (header.includes(fieldKey.toLowerCase()) ||
fieldKey.toLowerCase().includes(header)) {
matchCount += 1;
break;
}
}
}
});
});
// Calculate match score as percentage of possible matches
const score = (matchCount / (totalKeyCount * 2)) * 100;
matchScores[key] = score;
console.log(`Match score for ${key}: ${score.toFixed(2)}%`);
}
// Find data type with highest match score
let bestMatch = null;
let bestScore = 20; // Threshold percentage - at least 20% match required
for (const [key, score] of Object.entries(matchScores)) {
if (score > bestScore) {
bestScore = score;
bestMatch = key;
}
}
if (bestMatch) {
console.log(`Best match by headers: ${bestMatch} (${dataTypeDefinitions[bestMatch].name}) with score ${bestScore.toFixed(2)}%`);
return bestMatch;
}
// Special case for cell site/data session files
if (fileName.toLowerCase().includes('cellsites') ||
fileName.toLowerCase().includes('data_sessions') ||
(fileName.toLowerCase().includes('4g') && fileName.toLowerCase().includes('session')) ||
(fileName.toLowerCase().includes('5g') && fileName.toLowerCase().includes('session')) ||
fileName.toLowerCase().includes('tdr')) {
return 'datasession';
}
console.log("No match found, returning unknown");
return 'unknown';
}
// Compute a score based on total duration and unique towers.
// (For example, score = (duration in minutes) + (unique towers * 10))
function computeScore(record) {
let durationMinutes = record["Total Duration"] / 60;
let towersScore = record["Unique Towers"] * 10;
return Math.round(durationMinutes + towersScore);
}
// Process selected files (CSV and Excel)
async function processFiles() {
const files = document.getElementById('csvFile').files;
if (files.length === 0) {
alert("Please select files to process.");
return;
}
currentDataset = [];
detectedDataTypes.clear();
// Check if user selected a specific file type
const manualFileType = document.getElementById('fileTypeSelector').value;
for (const file of Array.from(files)) {
try {
let fileData;
let headers = [];
if (file.name.toLowerCase().endsWith('.csv')) {
// Process CSV file
fileData = await new Promise((resolve, reject) => {
Papa.parse(file, {
header: true,
skipEmptyLines: true,
transformHeader: header => header.trim().toLowerCase(),
complete: function(results) {
headers = results.meta.fields;
resolve(results.data);
},
error: function(error) {
reject(error);
}
});
});
} else if (file.name.toLowerCase().endsWith('.xlsx') || file.name.toLowerCase().endsWith('.xls')) {
// Process Excel file
const excelData = await processExcelFile(file);
headers = excelData.headers;
fileData = excelData.rows;
} else {
console.warn(`Unsupported file type: ${file.name}`);
continue;
}
// Detect or use manual file type
let fileType = manualFileType !== 'auto' ? manualFileType : detectFileType(file.name, headers);
if (fileType === 'unknown') {
alert(`Could not automatically determine the type of file: ${file.name}. Using default processing.`);
// Show create type button for unknown files
document.getElementById('fileTypeDetection').style.display = 'block';
document.getElementById('detectedFileType').textContent = 'Unknown';
document.getElementById('createTypeBtn').style.display = 'inline-block';
document.getElementById('createTypeBtn').onclick = function() {
// Switch to config tab with headers pre-filled
document.getElementById('config-tab').click();
document.getElementById('dataTypeSelector').value = 'new';
// Pre-fill with detected headers
updateDataTypeConfig();
// Auto-generate field definitions from headers
headers.forEach(header => {
const field = {
name: header.charAt(0).toUpperCase() + header.slice(1),
keys: [header],
type: 'text'
};
createFieldDefinitionUI(field);
});
};
} else {
// Show detected file type
document.getElementById('fileTypeDetection').style.display = 'block';
document.getElementById('detectedFileType').textContent = dataTypeDefinitions[fileType] ?
dataTypeDefinitions[fileType].name : fileType;
document.getElementById('createTypeBtn').style.display = 'none';
// Add to detected data types
detectedDataTypes.add(fileType);
}
// Add the file type to each record
fileData.forEach(row => {
row.fileType = fileType;
// For call records, ensure duration field is properly processed
if (fileType === 'call') {
row.timeusage = parseInt(row["timeusage"] || row["sou"], 10) || 0;
}
currentDataset.push(row);
});
} catch (error) {
console.error(`Error processing file ${file.name}:`, error);
alert(`Error processing file ${file.name}. Please check the file format and try again.`);
}
}
// Update data type selector with detected types
updateDataTypeSelectors();
// Initially, currentFilteredDataset is the full dataset
currentFilteredDataset = currentDataset.slice();
// Show appropriate filter section based on detected data types
updateFilterSections();
// Render the data
renderData();
}
// Update filter sections based on detected data types
function updateFilterSections() {
document.getElementById('callDataFilters').style.display = detectedDataTypes.has('call') ? 'block' : 'none';
document.getElementById('messageDataFilters').style.display = detectedDataTypes.has('text') ? 'block' : 'none';
document.getElementById('deviceDataFilters').style.display = detectedDataTypes.has('device') ? 'block' : 'none';
document.getElementById('dataSessionFilters').style.display = detectedDataTypes.has('datasession') ? 'block' : 'none';
}
// Render data based on data types
function renderData() {
const activeType = document.getElementById('activeDataType').value;
if (activeType === 'all') {
// If grouped by phone is checked and we have call data
if (document.getElementById('groupByPhone').checked && detectedDataTypes.has('call')) {
renderAggregatedLevel(buildAggregatedDataset());
} else {
// Use the first detected data type for display
const firstType = detectedDataTypes.size > 0 ?