-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrontend.html
More file actions
2275 lines (2044 loc) · 100 KB
/
Copy pathfrontend.html
File metadata and controls
2275 lines (2044 loc) · 100 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>Network Match Engine</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://d3js.org/d3.v7.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1400px;
margin: 0 auto;
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0,0,0,0.15);
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
color: white;
padding: 30px 40px;
text-align: center;
}
.header h1 {
font-size: 2.5em;
font-weight: 300;
margin-bottom: 10px;
}
.header p {
font-size: 1.1em;
opacity: 0.9;
}
.main-content {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0;
min-height: 600px;
}
.left-panel {
padding: 40px;
background: #f8f9fa;
}
.right-panel {
padding: 40px;
background: white;
border-left: 1px solid #e9ecef;
}
.section {
margin-bottom: 30px;
}
.section-title {
font-size: 1.4em;
font-weight: 600;
color: #2c3e50;
margin-bottom: 20px;
display: flex;
align-items: center;
gap: 10px;
}
.upload-area {
border: 3px dashed #3498db;
border-radius: 12px;
padding: 40px 20px;
text-align: center;
transition: all 0.3s ease;
cursor: pointer;
}
.upload-area:hover {
border-color: #2980b9;
background: rgba(52, 152, 219, 0.05);
}
.upload-area.dragover {
border-color: #27ae60;
background: rgba(39, 174, 96, 0.1);
}
.upload-area.has-file {
border-color: #27ae60;
background: rgba(39, 174, 96, 0.05);
}
input[type="file"] {
display: none;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
margin-bottom: 8px;
font-weight: 500;
color: #2c3e50;
}
.form-control {
width: 100%;
padding: 12px 16px;
border: 2px solid #e9ecef;
border-radius: 8px;
font-size: 14px;
transition: border-color 0.3s ease;
}
.form-control:focus {
outline: none;
border-color: #3498db;
}
.btn {
background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
color: white;
border: none;
padding: 14px 28px;
border-radius: 8px;
cursor: pointer;
font-size: 16px;
font-weight: 500;
transition: all 0.3s ease;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.btn:hover:not(:disabled) {
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(52, 152, 219, 0.4);
}
.btn:disabled {
background: #bdc3c7;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
.btn-secondary {
background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%);
}
.btn-primary {
background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
}
.project-options {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 15px;
margin-bottom: 25px;
}
.option-card {
background: white;
border: 2px solid #e9ecef;
border-radius: 12px;
padding: 20px;
text-align: center;
cursor: pointer;
transition: all 0.3s ease;
}
.option-card:hover {
border-color: #3498db;
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(52, 152, 219, 0.2);
}
.option-card.selected {
border-color: #27ae60;
background: rgba(39, 174, 96, 0.05);
}
.option-icon {
font-size: 32px;
margin-bottom: 10px;
}
.option-card h3 {
font-size: 16px;
font-weight: 600;
color: #2c3e50;
margin-bottom: 8px;
}
.option-card p {
font-size: 13px;
color: #7f8c8d;
margin: 0;
}
.load-job-area {
background: #f8f9fa;
border-radius: 12px;
padding: 20px;
}
.job-item {
background: white;
border: 2px solid #e9ecef;
border-radius: 8px;
padding: 15px;
margin-bottom: 10px;
cursor: pointer;
transition: all 0.3s ease;
}
.job-item:hover {
border-color: #3498db;
box-shadow: 0 4px 15px rgba(52, 152, 219, 0.2);
}
.job-item.completed {
border-color: #27ae60;
background: rgba(39, 174, 96, 0.05);
}
.job-item.failed {
border-color: #e74c3c;
background: rgba(231, 76, 60, 0.05);
}
.job-status {
display: inline-block;
padding: 4px 8px;
border-radius: 4px;
font-size: 12px;
font-weight: bold;
text-transform: uppercase;
}
.job-status.completed { background: #d4edda; color: #155724; }
.job-status.failed { background: #f8d7da; color: #721c24; }
.job-status.processing { background: #fff3cd; color: #856404; }
.job-status.queued { background: #cce5ff; color: #004085; }
.status-card {
padding: 20px;
border-radius: 12px;
margin-bottom: 20px;
font-weight: 500;
display: flex;
align-items: center;
gap: 12px;
}
.status-card.connected {
background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
color: #155724;
border: 2px solid #c3e6cb;
}
.status-card.disconnected {
background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
color: #721c24;
border: 2px solid #f5c6cb;
}
.status-card.processing {
background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
color: #856404;
border: 2px solid #ffeaa7;
}
.progress-container {
margin: 20px 0;
}
.progress-bar {
width: 100%;
height: 8px;
background: #e9ecef;
border-radius: 4px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #3498db 0%, #2980b9 100%);
width: 0%;
transition: width 0.5s ease;
}
.log-container {
background: #2c3e50;
border-radius: 12px;
height: 300px;
overflow: hidden;
display: flex;
flex-direction: column;
}
.log-header {
background: #34495e;
padding: 15px 20px;
color: white;
font-weight: 500;
}
.log-content {
flex: 1;
padding: 20px;
color: #ecf0f1;
font-family: 'Monaco', 'Consolas', monospace;
font-size: 13px;
overflow-y: auto;
line-height: 1.6;
}
.log-entry {
margin-bottom: 8px;
display: flex;
align-items: flex-start;
gap: 10px;
}
.timestamp {
color: #95a5a6;
font-size: 11px;
min-width: 60px;
margin-top: 2px;
}
.results-container {
margin-top: 30px;
}
.result-card {
background: linear-gradient(135deg, #e8f5e8 0%, #d4edda 100%);
border: 2px solid #c3e6cb;
border-radius: 15px;
padding: 30px;
margin-bottom: 25px;
}
.result-header {
display: flex;
align-items: center;
gap: 15px;
margin-bottom: 25px;
}
.result-icon {
width: 60px;
height: 60px;
background: #27ae60;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
color: white;
}
.result-title {
font-size: 1.8em;
font-weight: 600;
color: #27ae60;
}
.metrics-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.metric-card {
background: white;
padding: 20px;
border-radius: 10px;
text-align: center;
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
.metric-value {
font-size: 2em;
font-weight: bold;
color: #2c3e50;
}
.metric-label {
color: #7f8c8d;
margin-top: 5px;
font-size: 14px;
}
.members-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 15px;
margin-top: 20px;
}
.member-card {
background: white;
padding: 20px;
border-radius: 10px;
border-left: 4px solid #3498db;
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
transition: transform 0.2s ease;
}
.member-card:hover {
transform: translateY(-3px);
}
.community-card .community-header:hover {
background: rgba(52, 152, 219, 0.1);
border-radius: 5px;
padding: 5px;
margin: -5px;
}
.community-members-full {
border: 1px solid #e9ecef;
}
.community-members-full::-webkit-scrollbar {
width: 6px;
}
.community-members-full::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 3px;
}
.community-members-full::-webkit-scrollbar-thumb {
background: #c1c1c1;
border-radius: 3px;
}
.community-members-full::-webkit-scrollbar-thumb:hover {
background: #a1a1a1;
}
.member-name {
font-weight: 600;
color: #2c3e50;
margin-bottom: 8px;
}
.member-linkedin {
color: #3498db;
text-decoration: none;
font-size: 14px;
}
.member-linkedin:hover {
text-decoration: underline;
}
.graph-container {
margin-top: 30px;
background: white;
border-radius: 15px;
padding: 30px;
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}
.graph-canvas {
width: 100%;
height: 500px;
border: 1px solid #e9ecef;
border-radius: 10px;
position: relative;
}
.graph-controls {
position: absolute;
top: 10px;
left: 10px;
z-index: 10;
background: rgba(255, 255, 255, 0.9);
padding: 10px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
display: none;
}
.graph-controls label {
display: block;
margin-bottom: 5px;
font-size: 12px;
font-weight: 500;
}
.graph-controls input[type="range"] {
width: 120px;
margin-right: 8px;
}
.graph-controls select {
padding: 4px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 12px;
}
.graph-legend {
position: absolute;
top: 10px;
right: 10px;
background: rgba(255, 255, 255, 0.94);
padding: 10px 12px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
font-size: 12px;
z-index: 10;
display: none;
}
.graph-legend-item {
display: flex;
align-items: center;
gap: 8px;
margin: 6px 0;
}
.graph-legend-dot {
width: 12px;
height: 12px;
border-radius: 50%;
}
.graph-tooltip {
position: absolute;
pointer-events: none;
background: rgba(0,0,0,.82);
color: #fff;
padding: 8px 10px;
border-radius: 6px;
font-size: 12px;
z-index: 1000;
transform: translate(-50%,-120%);
white-space: nowrap;
opacity: 0;
}
.tabs {
display: flex;
border-bottom: 2px solid #e9ecef;
margin-bottom: 20px;
}
.tab {
padding: 12px 24px;
cursor: pointer;
border-bottom: 3px solid transparent;
font-weight: 500;
color: #7f8c8d;
transition: all 0.3s ease;
}
.tab.active {
color: #3498db;
border-bottom-color: #3498db;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
.advanced-options {
background: #f8f9fa;
border-radius: 10px;
padding: 20px;
margin-top: 20px;
}
.collapse-header {
cursor: pointer;
display: flex;
align-items: center;
justify-content: space-between;
font-weight: 500;
color: #2c3e50;
}
.collapse-content {
margin-top: 15px;
display: none;
}
.collapse-content.show {
display: block;
}
@media (max-width: 1024px) {
.main-content {
grid-template-columns: 1fr;
}
.left-panel, .right-panel {
border-left: none;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🔗 Network Match Engine</h1>
<p>AI-powered dense subgraph analysis for strategic networking and team building</p>
</div>
<div class="main-content">
<!-- Left Panel: Upload & Controls -->
<div class="left-panel">
<div class="section">
<div class="section-title">
📊 Project Options
</div>
<!-- Project Options -->
<div class="project-options" id="projectOptions">
<div class="option-card" id="newProjectCard">
<div class="option-icon">🆕</div>
<h3>Create New Project</h3>
<p>Start a fresh analysis with new data</p>
</div>
<div class="option-card" id="loadProjectCard">
<div class="option-icon">📂</div>
<h3>Load Previous Job</h3>
<p>Resume analysis using job ID</p>
</div>
</div>
<!-- File Upload Area (hidden initially) -->
<div class="upload-area" id="uploadArea" style="display: none;">
<div class="form-group">
<label for="newProjectUserId">Your User ID</label>
<input type="text" id="newProjectUserId" class="form-control" placeholder="e.g., user123" value="1">
</div>
<div>
<div style="font-size: 48px; margin-bottom: 15px;">📁</div>
<h3>Upload Professional Data CSV</h3>
<p style="margin: 10px 0; color: #7f8c8d;">Drag and drop your CSV file here or click to select</p>
<input type="file" id="fileInput" accept=".csv">
<button class="btn btn-secondary" onclick="document.getElementById('fileInput').click()">
Choose File
</button>
</div>
<button id="backToOptions" class="btn btn-secondary" style="margin-top: 15px;">← Back to Options</button>
</div>
<!-- Load Job Area (hidden initially) -->
<div class="load-job-area" id="loadJobArea" style="display: none;">
<div class="form-group">
<label for="userIdInput">Enter User ID</label>
<input type="text" id="userIdInput" class="form-control" placeholder="e.g., user123">
</div>
<div style="display: flex; gap: 10px; margin-bottom: 20px;">
<button id="fetchJobsBtn" class="btn btn-primary">Show My Jobs</button>
<button id="backToOptionsFromLoad" class="btn btn-secondary">← Back to Options</button>
</div>
<!-- Jobs List (hidden initially) -->
<div id="jobsList" style="display: none;">
<h4>Your Previous Jobs:</h4>
<div id="jobsContainer"></div>
</div>
<!-- Manual Job ID Entry -->
<div style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
<div class="form-group">
<label for="jobIdInput">Or Enter Job ID Directly</label>
<input type="text" id="jobIdInput" class="form-control" placeholder="e.g., 12345678-1234-5678-9abc-123456789012">
</div>
<button id="loadJobBtn" class="btn btn-primary">Load Job</button>
</div>
</div>
</div>
<div class="section">
<div class="section-title">
⚙️ Analysis Configuration
</div>
<div class="form-group">
<label for="minDensity">Minimum Density Threshold</label>
<input type="number" id="minDensity" class="form-control" value="0.3" step="0.1" min="0" max="1"
title="Minimum density for subgraph extraction (0.0 - 1.0)">
</div>
<div class="form-group">
<label for="promptInput">User Intent (Optional)</label>
<textarea id="promptInput" class="form-control" rows="3"
placeholder="e.g., 'I want to hire for my startup', 'I need peer networking', 'I want business partnerships'"
title="Describe your networking intent to tune the algorithm"></textarea>
</div>
<div class="advanced-options">
<div class="collapse-header" onclick="toggleAdvanced()">
🔧 Advanced Options
<span id="advancedToggle">▼</span>
</div>
<div class="collapse-content" id="advancedContent">
<div class="form-group">
<label for="fileId">File ID (Optional)</label>
<input type="text" id="fileId" class="form-control"
placeholder="Custom file ID for cache isolation"
title="Use same file ID to reuse cached matrices">
</div>
</div>
</div>
<button class="btn" id="analyzeBtn" onclick="startAnalysis()" disabled style="width: 100%; margin-top: 20px;">
🚀 Start Analysis
</button>
</div>
<div class="status-card disconnected" id="connectionStatus">
<span style="font-size: 20px;">🔌</span>
<span>Connecting to WebSocket...</span>
</div>
<div class="progress-container" id="progressContainer" style="display: none;">
<div style="margin-bottom: 10px; font-weight: 500; color: #2c3e50;">Analysis Progress</div>
<div class="progress-bar">
<div class="progress-fill" id="progressFill"></div>
</div>
<div style="margin-top: 8px; font-size: 14px; color: #7f8c8d;" id="progressText">Initializing...</div>
</div>
</div>
<!-- Right Panel: Logs & Results -->
<div class="right-panel">
<div class="section">
<div class="section-title">
📡 Real-time Logs
</div>
<div class="log-container">
<div class="log-header">
System Status
</div>
<div class="log-content" id="log">
<div class="log-entry">
<span class="timestamp">--:--</span>
<span>🌟 System initialized. Waiting for WebSocket connection...</span>
</div>
</div>
</div>
</div>
<div class="results-container" id="resultsContainer" style="display: none;">
</div>
</div>
</div>
</div>
<script>
let websocket = null;
let selectedFile = null;
let currentJobId = null;
let selectedRerunFile = null;
let heartbeatInterval = null;
let reconnectAttempts = 0;
let maxReconnectAttempts = 10;
let lastJobConfig = null;
function clearPreviousJob() {
currentJobId = null;
// Reset UI
document.getElementById('resultsContainer').style.display = 'none';
updateProgress(0);
updateConnectionStatus(true);
logMessage('✅ Previous job cleared, ready for new analysis', 'success');
}
let analysisSteps = [
'Initializing GraphBuilder',
'Loading data',
'Preprocessing tags and embeddings',
'Creating feature embeddings',
'Building optimized graph',
'Finding dense subgraph',
'Analyzing results'
];
let currentStep = 0;
function connectWebSocket() {
let clientId = localStorage.getItem('ws_client_id');
if (!clientId) {
clientId = 'web_client_' + Math.random().toString(36).substr(2, 9);
localStorage.setItem('ws_client_id', clientId);
}
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsUrl = `${wsProtocol}//${window.location.host}/ws/${clientId}`;
websocket = new WebSocket(wsUrl);
websocket.onopen = function() {
updateConnectionStatus(true);
logMessage('🔗 WebSocket connected successfully!', 'success');
reconnectAttempts = 0;
startHeartbeat();
if (currentJobId) {
logMessage(`🔄 Resuming job monitoring: ${currentJobId.substring(0, 8)}`, 'info');
websocket.send(JSON.stringify({
type: 'resume_job',
job_id: currentJobId
}));
}
};
websocket.onmessage = function(event) {
const data = JSON.parse(event.data);
if (data.type === 'pong') {
return;
}
handleWebSocketMessage(data);
};
websocket.onclose = function(event) {
updateConnectionStatus(false);
stopHeartbeat();
if (reconnectAttempts < maxReconnectAttempts) {
const delay = Math.min(1000 * Math.pow(2, reconnectAttempts), 30000);
logMessage(`🔌 WebSocket connection closed (${event.code}). Reconnecting in ${delay/1000}s... (${reconnectAttempts + 1}/${maxReconnectAttempts})`, 'warning');
reconnectAttempts++;
setTimeout(connectWebSocket, delay);
} else {
logMessage('❌ Max reconnection attempts reached. Please refresh the page.', 'error');
}
};
websocket.onerror = function(error) {
logMessage('❌ WebSocket error occurred', 'error');
stopHeartbeat();
};
}
function startHeartbeat() {
heartbeatInterval = setInterval(function() {
if (websocket && websocket.readyState === WebSocket.OPEN) {
websocket.send(JSON.stringify({ type: 'ping' }));
}
}, 30000);
}
function stopHeartbeat() {
if (heartbeatInterval) {
clearInterval(heartbeatInterval);
heartbeatInterval = null;
}
}
function updateConnectionStatus(connected) {
const status = document.getElementById('connectionStatus');
if (connected) {
status.className = 'status-card connected';
status.innerHTML = '<span style="font-size: 20px;">🔗</span><span>Connected to Server</span>';
document.getElementById('analyzeBtn').disabled = !selectedFile;
} else {
status.className = 'status-card disconnected';
status.innerHTML = '<span style="font-size: 20px;">🔌</span><span>Disconnected - Reconnecting...</span>';
document.getElementById('analyzeBtn').disabled = true;
}
}
function updateProgress(step, total = analysisSteps.length) {
const progressContainer = document.getElementById('progressContainer');
const progressFill = document.getElementById('progressFill');
const progressText = document.getElementById('progressText');
if (step > 0) {
progressContainer.style.display = 'block';
const percentage = (step / total) * 100;
progressFill.style.width = percentage + '%';
if (step <= analysisSteps.length) {
progressText.textContent = `Step ${step}/${total}: ${analysisSteps[step-1]}`;
} else {
progressText.textContent = 'Analysis Complete!';
}
} else {
progressContainer.style.display = 'none';
}
}
function handleWebSocketMessage(data) {
if (data.type === 'job_update') {
const jobId = data.job_id.substring(0, 8);
const status = data.status;
const progress = data.progress || '';
// Store the full job_id for rerun functionality
if (data.job_id) {
currentJobId = data.job_id;
}
if (status === 'processing') {
// Update progress based on message content
currentStep = Math.min(analysisSteps.findIndex(step =>
progress.toLowerCase().includes(step.toLowerCase())) + 1, analysisSteps.length);
if (currentStep <= 0) currentStep = Math.min(currentStep + 1, analysisSteps.length);
updateProgress(currentStep);
logMessage(`🔄 ${progress}`, 'info');
const connectionStatus = document.getElementById('connectionStatus');
connectionStatus.className = 'status-card processing';
connectionStatus.innerHTML = `<span style="font-size: 20px;">⏳</span><span>${progress}</span>`;
} else if (status === 'completed') {
updateProgress(analysisSteps.length + 1);
logMessage(`✅ Analysis completed successfully!`, 'success');
const connectionStatus = document.getElementById('connectionStatus');
connectionStatus.className = 'status-card connected';
connectionStatus.innerHTML = '<span style="font-size: 20px;">🎉</span><span>Analysis Complete!</span>';
// The result should already be in the WebSocket message
if (data.result) {
showResults(data.result);
} else {
// Fallback: fetch from API if result not in WebSocket message
logMessage('⚠️ Result not in WebSocket, fetching from API...', 'warning');
fetchJobResult(data.job_id);
}
// Re-enable buttons
setTimeout(() => {
updateProgress(0);
updateConnectionStatus(true);
document.getElementById('analyzeBtn').disabled = !selectedFile;
document.getElementById('rerunAnalysisBtn').disabled = !selectedRerunFile;
}, 3000);
} else if (status === 'failed') {
updateProgress(0);
logMessage(`❌ Analysis failed: ${data.error}`, 'error');
const connectionStatus = document.getElementById('connectionStatus');
connectionStatus.className = 'status-card disconnected';
connectionStatus.innerHTML = '<span style="font-size: 20px;">❌</span><span>Analysis Failed</span>';
setTimeout(() => updateConnectionStatus(true), 5000);
}
}
}
function logMessage(message, type = 'info') {
const log = document.getElementById('log');
const entry = document.createElement('div');
entry.className = 'log-entry';
const timestamp = new Date().toLocaleTimeString().substring(0, 5);
const icon = type === 'success' ? '✅' : type === 'error' ? '❌' : type === 'warning' ? '⚠️' : '📝';
entry.innerHTML = `
<span class="timestamp">${timestamp}</span>
<span>${message}</span>
`;
log.appendChild(entry);
log.scrollTop = log.scrollHeight;
}
async function fetchJobResult(jobId) {
try {
logMessage('📊 Fetching detailed job results...', 'info');
const response = await fetch(`/jobs/${jobId}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const jobResult = await response.json();
if (jobResult.status === 'completed' && jobResult.result) {
logMessage('✅ Final results retrieved successfully!', 'success');
showResults(jobResult.result);
} else {
logMessage('⚠️ Job not completed yet, using WebSocket result', 'warning');
}
} catch (error) {
logMessage(`❌ Failed to fetch job result: ${error.message}`, 'error');
logMessage('ℹ️ Using WebSocket result as fallback', 'info');
}
}
function showResults(result) {
const container = document.getElementById('resultsContainer');
container.style.display = 'block';
// Store the current job configuration for rerun
lastJobConfig = {
minDensity: document.getElementById('minDensity') ? document.getElementById('minDensity').value : '0.3',
prompt: document.getElementById('promptInput') ? document.getElementById('promptInput').value : '',
fileId: document.getElementById('fileId') ? document.getElementById('fileId').value : ''
};
let html = `
<div class="result-card">
<div class="result-header">
<div class="result-icon">🎯</div>
<div>
<div class="result-title">Dense Subgraph Found</div>
<div style="color: #7f8c8d;">Professional Network Analysis Results</div>
</div>
</div>
<div class="metrics-grid">
<div class="metric-card">
<div class="metric-value">${result.size}</div>
<div class="metric-label">People</div>
</div>
<div class="metric-card">
<div class="metric-value">${result.density ? result.density.toFixed(3) : 'N/A'}</div>
<div class="metric-label">Density</div>
</div>
<div class="metric-card">
<div class="metric-value">${result.avg_edge_weight ? result.avg_edge_weight.toFixed(3) : 'N/A'}</div>
<div class="metric-label">Avg. Connection Strength</div>
</div>
<div class="metric-card">
<div class="metric-value">${result.edges || 'N/A'}</div>
<div class="metric-label">Total Connections</div>
</div>
</div>
<div class="tabs">
<div class="tab active" onclick="switchTab('members')">👥 Network Members</div>
<div class="tab" onclick="switchTab('graph')">🕸️ Network Graph</div>
<div class="tab" onclick="switchTab('insights')">💡 Basic Insights</div>
<div class="tab" onclick="switchTab('communities')">🏘️ Communities</div>
<div class="tab" onclick="switchTab('cycles')">🔄 Max Cycles</div>
<div class="tab" onclick="switchTab('features')">📊 Feature Analysis</div>
<div class="tab" onclick="switchTab('profiles')">👤 Member Profiles</div>
</div>
<div class="tab-content active" id="members-tab">
<h4 style="margin-bottom: 20px; color: #2c3e50;">Network Members (${result.members ? result.members.length : 0})</h4>
<div class="members-grid">
`;
if (result.members && result.members.length > 0) {
result.members.forEach(member => {
html += `
<div class="member-card">
<div class="member-name">${member.name}</div>
${member.linkedin ?
`<a href="${member.linkedin}" class="member-linkedin" target="_blank">View LinkedIn Profile</a>` :
'<span style="color: #bdc3c7;">LinkedIn not available</span>'
}
</div>
`;
});
} else {
html += '<div style="text-align: center; color: #7f8c8d; padding: 40px;">No members data available</div>';
}