-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscriptt3.js
More file actions
1233 lines (1062 loc) · 42.2 KB
/
scriptt3.js
File metadata and controls
1233 lines (1062 loc) · 42.2 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
window.onload = function() {
alert('Welcome to the next page!');
};
$(document).ready(() => {
fetchT1attainmentData()
.then(fetchT1CO)
.then(fetchT1CO2)
.then(fetchT1attainmentData2)
.catch(function(error) {
console.error('Error:', error);
});
fetchcdData();
fetchusername();
fetchcourse();
fetchuserrole();
const body = document.querySelector("body");
const darkLight = document.querySelector("#darkLight");
const sidebar = document.querySelector(".sidebar");
const submenuItems = document.querySelectorAll(".submenu_item");
const sidebarOpen = document.querySelector("#sidebarOpen");
const sidebarClose = document.querySelector(".collapse_sidebar");
const sidebarExpand = document.querySelector(".expand_sidebar");
sidebarOpen.addEventListener("click", () => sidebar.classList.toggle("close"));
sidebarClose.addEventListener("click", () => {
sidebar.classList.add("close", "hoverable");
});
sidebarExpand.addEventListener("click", () => {
sidebar.classList.remove("close", "hoverable");
});
sidebar.addEventListener("mouseenter", () => {
if (sidebar.classList.contains("hoverable")) {
sidebar.classList.remove("close");
}
});
sidebar.addEventListener("mouseleave", () => {
if (sidebar.classList.contains("hoverable")) {
sidebar.classList.add("close");
}
});
darkLight.addEventListener("click", () => {
body.classList.toggle("dark");
if (body.classList.contains("dark")) {
document.setI
darkLight.classList.replace("bx-sun", "bx-moon");
} else {
darkLight.classList.replace("bx-moon", "bx-sun");
}
});
let noc=10;
let noa=noc+3;
$(document).on('input', '.q-input', function () {
const row = $(this).closest('tr');
calculateAttainment1ForRow(row);
});
$('.add-row-buttonat').click(() => {
addEmptyRow3();
});
$('.save-buttonat').click(() => {
saveDataToServer3();
});
$('.add-qcolumn-buttonat').click(() => {
noc=addColumnsq(noc);
fetchT1attainmentData();
noa=noa+1;
});
$('.add-acolumn-buttonat').click(() => {
noa=addColumnsa(noa);
});
$(document).on('click', '.update-buttonat', function() {
const row = $(this).closest('tr');
const cells = row.find('td');
cells.attr('contenteditable', 'true'); // Make cells editable
row.find('.update-buttonat').hide();
row.find('.delete-buttonat').hide();
row.find('.save-buttonatu').show();
});
$(document).on('click', '.save-buttonatu', function() {
const row = $(this).closest('tr');
const moduleId = row.data('record-id'); // Use data('record-id') to retrieve the recordId
updateRowat(moduleId, row);
});
$(document).on('click', '.delete-buttonat', function() {
const row = $(this).closest('tr');
const moduleId = row.data('record-id');
deleteRowat(moduleId);
});
submenuItems.forEach((item, index) => {
item.addEventListener("click", () => {
item.classList.toggle("show_submenu");
submenuItems.forEach((item2, index2) => {
if (index !== index2) {
item2.classList.remove("show_submenu");
}
});
});
});
if (window.innerWidth < 768) {
sidebar.classList.add("close");
} else {
sidebar.classList.remove("close");
}
});
function savePage(){
const rows = $('#attainment-data tr'); // Replace '.row-class' with your actual row selector
// Assuming you want to start updating from the 4th row onwards
for (let i = 3; i < rows.length; i++) {
const row= rows[i];
const recordId = row.getAttribute('data-record-id'); // Extract the record ID from the row, if applicable
updateRowat(recordId, $(row)); // Call updateRowat function for each row starting from the 4th row
}
location.reload();
}
function confirmUpload() {
const fileInput = document.getElementById('file');
if (!fileInput.files[0]) {
alert('Please select a file.');
return;
}
// Optionally, you can ask the user for confirmation here.
const confirmation = confirm('Are you sure you want to upload the selected file?');
if (!confirmation) {
return;
}
const formData = new FormData();
formData.append('file', fileInput.files[0]);
fetch('/uploadt3', {
method: 'POST',
body: formData,
})
.then(response => response.json())
.then(data => {
alert('Upload successful');
location.reload();
})
.catch(error => {
console.error('Error:', error);
// Handle errors here
});
}
function updateRowat(recordId, row) {
const cells = row.find('td');
const updatedData = {
ModuleNo: parseInt(cells.eq(0).text()),
RollNo: cells.eq(1).text(),
Name: cells.eq(2).text(),
Batch: cells.eq(3).text()
};
const qIndices = [];
let coIndices = [];
let atIndices = [];
coIndices = fetchcoIndices(coIndices);
console.log(coIndices);
atIndices = fetchatindices(atIndices);
console.log(atIndices);
let qmarks = [];
qmarks = fetchmarks(qmarks);
console.log(qmarks);
const qValues = [];
const headerCells = $('#attainment-data thead th');
let totalIndex = headerCells.length; // Default to the length of the header cells
headerCells.each(function(index) {
if ($(this).text().trim() === "Total") {
totalIndex = index;
return false; // Break out of the loop
}
});
console.log(totalIndex);
for (let i = 4; i <totalIndex; i++) {
const cellText = cells.eq(i).text().trim();
qIndices.push(i);
qValues.push(cellText);
}
const containsAOrQuestionMark = qValues.some(value => value === "A");
// Initialize at1 to atn with zeros
const at = Array(atIndices.length).fill(0);
const marks = Array(atIndices.length).fill(0);
// Calculate at1 to atn only when coIndices and atIndices match
for (let i = 0; i < atIndices.length; i++) {
const atIndex = atIndices[i];
let atValue=0.0;
let atmarks=0.0;
// Check if coIndices has a corresponding entry and it matches
for (let j = 4; j < cells.length - 4; j++) {
if (coIndices[j-4] === atIndex) {
console.log(coIndices[j-4]);
console.log(atIndex);
atValue+=parseFloat(qValues[j-4]||0);
atmarks+=parseFloat(qmarks[j-4]||0);
}
console.log(atValue);
console.log(atmarks);
at[i] = atValue;
marks[i]=atmarks;
}
}
// ... [previous code remains unchanged]
// Calculate attainment values dynamically
const attainmentValues = [];
if (!containsAOrQuestionMark) {
for (let i = 0; i < atIndices.length; i++) {
attainmentValues.push(((at[i] / marks[i]) * 100).toFixed(1));
}
} else {
for (let i = 0; i < atIndices.length; i++) {
attainmentValues.push(0);
}
}
// Update the UI with new attainment values
attainmentValues.forEach((attainment, index) => {
cells.eq(cells.length - atIndices.length - 1 + index).text(attainment);
});
const total = qIndices.reduce((acc, index) => {
const qValue = parseFloat(cells.eq(index).text());
return isNaN(qValue) ? acc : acc + qValue;
}, 0);
// Update the UI with new values
cells.eq(totalIndex).text(total);
// Update the Total and Attainment values in the updatedData object
updatedData.Total = total;
attainmentValues.forEach((attainment, index) => {
updatedData[`Attainment${index + 1}`] = parseFloat(attainment);
});
$.ajax({
url: `/api/t3attainment/${recordId}`, // Update the URL to match your Express route for T1attainment data
type: 'PUT',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify(updatedData),
success: function(response) {
console.log('Data updated successfully:', response);
fetchT1attainmentData()
.then(fetchT1CO)
.then(fetchT1CO2)
.then(fetchT1attainmentData2)
.catch(function(error) {
console.error('Error:', error);
});
row.find('.q-input').trigger('input');
},
error: function(error) {
console.error('Error updating data:', error);
}
});
// Restore UI state
cells.attr('contenteditable', 'false');
row.find('.save-buttonuat').hide();
row.find('.update-buttonat').show();
row.find('.delete-buttonat').show();
}
function deleteRowat(moduleId) {
$.ajax({
url: `/api/t3attainment/${moduleId}`, // Change this URL to match your Express route
type: 'DELETE',
success: function() {
console.log('Data deleted successfully');
fetchT1attainmentData()
.then(fetchT1CO)
.then(fetchT1CO2)
.then(fetchT1attainmentData2)
.catch(function(error) {
console.error('Error:', error);
});
},
error: function(error) {
console.error('Error deleting data:', error);
}
});
}
function fetchuserrole(){
$.ajax({
url: '/api/get-userrole',
type: 'GET',
dataType: 'json',
success: function (data) {
const userrole = data.userrole;
console.log('Userrole:', userrole);
$('#userrole').text(userrole);
},
error: function (error) {
console.error('Error fetching userrole', error);
}
});
}
function fetchusername(){
$.ajax({
url: '/api/get-username',
type: 'GET',
dataType: 'json',
success: function (data) {
const username = data.username;
console.log('Username:', username);
$('#username').text(username);
$('#username1').text(username);
},
error: function (error) {
console.error('Error fetching username', error);
}
});
}
function fetchcourse(){
$.ajax({
url: '/api/get-usercourse',
type: 'GET',
dataType: 'json',
success: function (data) {
const usercourse = data.usercourse;
console.log('Userrole:', usercourse);
$('#course_code').text(usercourse);
},
error: function (error) {
console.error('Error fetching usercourse', error);
}
});
}
function fetchT1CO2(){
return new Promise((resolve, reject) => {
$.ajax({
url: '/api/t3marks', // Update the URL to match your Express route for T1attainment data
type: 'GET',
dataType: 'json',
success: function(dataco) {
const attainmentDataco2 = $('#attainment-data');
tableHtml = '<tbody>';
const tableHeaders = Object.keys(dataco[0]);
// Create an array for Q columns and sort them numerically
const qColumns = tableHeaders.filter(header => /^Q\d+$/.test(header));
qColumns.sort((a, b) => {
const aNumber = parseInt(a.slice(1));
const bNumber = parseInt(b.slice(1));
return aNumber - bNumber;
});
const aColumns = tableHeaders.filter(header => /^Attainment\d+$/.test(header));
aColumns.sort((a, b) => {
const aNumber = parseInt(a.slice(1));
const bNumber = parseInt(b.slice(1));
return aNumber - bNumber;
});
const desiredOrder = ['ModuleNo', 'RollNo', 'Name', 'Batch', ...qColumns, 'Total', ...aColumns];
dataco.forEach((record, index) => {
tableHtml += '<tr data-record-id="' + record._id + '">';
// For the first and second records, you can add placeholders or empty cells
desiredOrder.forEach(header => {
if (tableHeaders.includes(header)) {
if ( /^Q\d+$/.test(header)||header=='Total') {
tableHtml += `<td><strong>${record[header]}</strong></td>`;
}
else {
tableHtml += `<td></td>`;
}
}
});
tableHtml += `<td></td>`;
tableHtml += '</tr>';
});
tableHtml += '</tbody>';
attainmentDataco2.append(tableHtml);
resolve();
},
error: function(error) {
console.error('Error fetching data:', error);
reject(error);
}
});});
}
function fetchT1CO(){
return new Promise((resolve, reject) => {
$.ajax({
url: '/api/t3co', // Update the URL to match your Express route for T1attainment data
type: 'GET',
dataType: 'json',
success: function(dataco) {
const attainmentDataco = $('#attainment-data');
tableHtml = '<tbody>';
const tableHeaders = Object.keys(dataco[0]);
// Create an array for Q columns and sort them numerically
const qColumns = tableHeaders.filter(header => /^Q\d+$/.test(header));
qColumns.sort((a, b) => {
const aNumber = parseInt(a.slice(1));
const bNumber = parseInt(b.slice(1));
return aNumber - bNumber;
});
const aColumns = tableHeaders.filter(header => /^Attainment\d+$/.test(header));
aColumns.sort((a, b) => {
const aNumber = parseInt(a.slice(1));
const bNumber = parseInt(b.slice(1));
return aNumber - bNumber;
});
const desiredOrder = ['ModuleNo', 'RollNo', 'Name', 'Batch', ...qColumns, 'Total', ...aColumns];
dataco.forEach((record, index) => {
tableHtml += '<tr data-record-id="' + record._id + '">';
// For the first and second records, you can add placeholders or empty cells
desiredOrder.forEach(header => {
if (tableHeaders.includes(header)) {
if ( /^Q\d+$/.test(header)|| /^Attainment\d+$/.test(header)) {
tableHtml += `<td><strong>${record[header]}</strong></td>`;
}
else {
tableHtml += `<td></td>`;
}
}
});
tableHtml += `<td></td>`;
tableHtml += '</tr>';
});
tableHtml += '</tbody>';
attainmentDataco.append(tableHtml);
resolve();
},
error: function(error) {
console.error('Error fetching data:', error);
reject(error);
}
});});
}
function fetchT1attainmentData2(){
return new Promise((resolve, reject) => {
$.ajax({
url: '/api/t3attainment', // Update the URL to match your Express route for T1attainment data
type: 'GET',
dataType: 'json',
success: function(data) {
const attainmentData = $('#attainment-data');
if (data.length > 0) {
// Create an array of column headers based on the keys of the first record
const tableHeaders = Object.keys(data[0]);
const qColumns = tableHeaders.filter(header => /^Q\d+$/.test(header)).sort(numericSort);
const aColumns = tableHeaders.filter(header => /^Attainment\d+$/.test(header)).sort(numericSort);
qColumns.sort((a, b) => {
const aNumber = parseInt(a.slice(1));
const bNumber = parseInt(b.slice(1));
return aNumber - bNumber;
});
aColumns.sort((a, b) => {
const aNumber = parseInt(a.slice(1));
const bNumber = parseInt(b.slice(1));
return aNumber - bNumber;
});
// Specify the desired order of columns (S.No, RollNo, Name, Batch, Q1 to Qn, Total, Attainment, Action)
const desiredOrder = ['ModuleNo', 'RollNo', 'Name', 'Batch', ...qColumns, 'Total', ...aColumns];
tableHtml = '<tbody>';
data.forEach((record, index) => {
tableHtml += '<tr data-record-id="' + record._id + '">';
desiredOrder.forEach(header => {
if (tableHeaders.includes(header)) {
if (header === 'ModuleNo') {
tableHtml += `<td>${index+ 1}</td>`;
} else {
tableHtml += `<td>${record[header]}</td>`;
}
}
});
tableHtml += `
<td class="action-buttons">
<button class="btn btn-info update-buttonat">Edit</button>
<button class="btn btn-danger delete-buttonat">Delete</button>
<button class="btn btn-primary save-buttonatu" style="display: none;">Save</button>
</td>`;
tableHtml += '</tr>';
});
tableHtml += '</tbody>';
attainmentData.append(tableHtml);
const studentsAppeared = calculateStudentsAppeared(data);
let summaryRow = '<tbody>';
summaryRow += `<tr><th colspan="4">Total Students:</th><td colspan="${qColumns.length + 5}">${data.length}</td></tr>`;
summaryRow += `<tr><th colspan="4">Average Marks:</th><td colspan="${qColumns.length + 5}">${calculateAverageMarks(data)}</td></tr>`;
summaryRow += `<tr>
<th colspan="4">No. of Students Scored >= 50% </th>`;
aColumns.forEach(aCol => {
const studentsAboveTarget = calculateStudentsAboveTarget(data, aCol);
summaryRow += `
<td colspan="4">${studentsAboveTarget}</td>`;
});
summaryRow += `</tr>`;
summaryRow += `<tr>
<th colspan="4">% of Students Scored >= 50% </th>`;
aColumns.forEach(aCol => {
const percentageAboveTarget = calculatePercentageAboveTarget(data, aCol);
summaryRow += `
<td colspan="4">${percentageAboveTarget}</td>
`;
});
summaryRow += `</tr>`;
summaryRow += `<tr>
<th colspan="4">CO Attainment Level </th>`;
aColumns.forEach(aCol => {
const percentageAboveTarget = calculateCOAttainment(data, aCol);
summaryRow += `
<td colspan="4">${percentageAboveTarget}</td>
`;
});
summaryRow += `</tr>
<tr>
<th colspan="4">No. of Students Appeared in T1:</th>
<td colspan="${qColumns.length + 4}">${studentsAppeared}</td>
</tr>`;
summaryRow += '</tbody>';
attainmentData.append(summaryRow);
} else {
// Handle the case where there is no data
attainmentData.html('<p>No data available.</p>');
}
resolve();
},
error: function(error) {
console.error('Error fetching data:', error);
reject(error);
}
});
});
}
function calculateCOAttainment(data, attainmentField) {
const attainmentCount = data.filter(record => record[attainmentField] >= 50).length;
let attainmentLevel;
if (attainmentCount / data.length >= 0.8) {
attainmentLevel = 3;
} else if (attainmentCount / data.length >= 0.7) {
attainmentLevel = 2;
} else if (attainmentCount / data.length >= 0.6) {
attainmentLevel = 1;
} else {
attainmentLevel = 0;
}
return attainmentLevel;
}
function numericSort(a, b) {
return parseInt(a.match(/\d+/)[0], 10) - parseInt(b.match(/\d+/)[0], 10);
}
function calculateStudentsAboveTarget(data, attainmentField) {
return data.filter(record => parseFloat(record[attainmentField]) >= 50).length;
}
function calculatePercentageAboveTarget(data, attainmentField) {
const aboveTargetCount = calculateStudentsAboveTarget(data, attainmentField);
return ((aboveTargetCount / data.length) * 100).toFixed(2) + '%';
}
function fetchT1attainmentData() {
return new Promise((resolve, reject) => {
$.ajax({
url: '/api/t3attainment', // Update the URL to match your Express route for T1attainment data
type: 'GET',
dataType: 'json',
success: function(data) {
const attainmentData = $('#attainment-data');
attainmentData.empty();
if (data.length > 0) {
// Create an array of column headers based on the keys of the first record
const tableHeaders = Object.keys(data[0]);
// Create an array for Q columns and sort them numerically
const qColumns = tableHeaders.filter(header => /^Q\d+$/.test(header));
qColumns.sort((a, b) => {
const aNumber = parseInt(a.slice(1));
const bNumber = parseInt(b.slice(1));
return aNumber - bNumber;
});
const aColumns = tableHeaders.filter(header => /^Attainment\d+$/.test(header));
aColumns.sort((a, b) => {
const aNumber = parseInt(a.slice(1));
const bNumber = parseInt(b.slice(1));
return aNumber - bNumber;
});
// Specify the desired order of columns (S.No, RollNo, Name, Batch, Q1 to Qn, Total, Attainment, Action)
const desiredOrder = ['ModuleNo', 'RollNo', 'Name', 'Batch', ...qColumns, 'Total', ...aColumns];
// Create the table header row
let tableHtml = '<thead><tr>';
desiredOrder.forEach(header => {
if (tableHeaders.includes(header)) {
if (header === 'ModuleNo') {
tableHtml += '<th>S.No</th>';
} else {
tableHtml += `<th>${header}</th>`;
}
}
});
tableHtml += '<th class="action1">Action</th></tr></thead>';
attainmentData.append(tableHtml);
} else {
// Handle the case where there is no data
attainmentData.html('<p>No data available.</p>');
}
resolve();
},
error: function(error) {
console.error('Error fetching data:', error);
reject(error);
}
});});
}
function calculateAverageMarks(data) {
const totalMarks = data.reduce((acc, record) => acc + record.Total, 0);
return (totalMarks / data.length).toFixed(2);
}
function calculateStudentsAboveTarget1(data) {
return data.filter(record => record.Attainment1 >= 50).length;
}
function calculateStudentsAboveTarget2(data) {
return data.filter(record => record.Attainment2 >= 50).length;
}
function calculatePercentageAboveTarget1(data) {
const aboveTargetCount = calculateStudentsAboveTarget1(data);
return ((aboveTargetCount / (data.length)) * 100).toFixed(2) + '%';
}
function calculatePercentageAboveTarget2(data) {
const aboveTargetCount = calculateStudentsAboveTarget2(data);
return ((aboveTargetCount / (data.length)) * 100).toFixed(2) + '%';
}
function calculateStudentsAppeared(data) {
const presentStudents = data.filter(record => record.Total > 0).length;
return presentStudents;
}
let cno=0;
function updatenewco(columnName,co){
$.ajax({
url: '/api/updatedbcot2', // Update the URL to match your Express route for T1attainment data
type: 'POST',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({ columnName,co }), // Send columnNames as JSON data
success: function(response) {
console.log('Data saved successfully:', response);
// You can add code here to handle the success response
// and update your table as needed.
},
error: function(xhr, status, error) {
console.error('Error saving data:', error);
console.log('Status:', status);
console.log('Response:', xhr.responseText);
// You can add error handling code here if needed.
}
});
}
function updatenewmarks(columnName,marks){
$.ajax({
url: '/api/updatedbmarkst2', // Update the URL to match your Express route for T1attainment data
type: 'POST',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({ columnName,marks }), // Send columnNames as JSON data
success: function(response) {
console.log('Data saved successfully:', response);
// You can add code here to handle the success response
// and update your table as needed.
},
error: function(xhr, status, error) {
console.error('Error saving data:', error);
console.log('Status:', status);
console.log('Response:', xhr.responseText);
// You can add error handling code here if needed.
}
});
}
function addColumnsq(noc) {
// Get the table element.
let columnName;
cno = noc - 4 + 1;
columnName = "Q" + cno;
const table = document.getElementById('attainment-table');
// Find the rows to which you want to add the column (up to totalRows - 5).
const rows = table.querySelectorAll('tbody tr');
const co=prompt(`Enter the CO for question ${columnName}: `);
const marks=prompt(`Enter the marks for question ${columnName}: `);
updatenewco(columnName,co);
updatenewmarks(columnName,marks);
const numRowsToAddTo = Math.max(0, rows.length - 6);
// Add a new cell to the selected rows.
rows.forEach((row, index) => {
if (index < numRowsToAddTo && index>0) {
const cell = document.createElement('td');
cell.textContent = '0';
// Insert the new cell after the specified column (noc - 1 since columns are 0-indexed).
const targetCell = row.cells[noc - 1];
if (targetCell) {
row.insertBefore(cell, targetCell.nextSibling);
} else {
row.appendChild(cell);
}
}
});
// Add a new header cell for the added column.
const headerRow = table.querySelector('thead tr');
const headerCell = document.createElement('th');
headerCell.textContent = columnName;
// Insert the new header cell after the specified column (noc - 1 since columns are 0-indexed).
const targetHeaderCell = headerRow.cells[noc - 1];
if (targetHeaderCell) {
headerRow.insertBefore(headerCell, targetHeaderCell.nextSibling);
} else {
headerRow.appendChild(headerCell);
}
// Update the header text for the existing column with the specified columnName.
const existingHeaderCell = table.querySelector(`thead th[data-column-name="${columnName}"]`);
if (existingHeaderCell) {
existingHeaderCell.textContent = columnName;
}
$.ajax({
url: '/api/updatedb', // Update the URL to match your Express route for T1attainment data
type: 'POST',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({ columnName }), // Send columnNames as JSON data
success: function(response) {
console.log('Data saved successfully:', response);
// You can add code here to handle the success response
// and update your table as needed.
fetchT1attainmentData()
.then(fetchT1CO)
.then(fetchT1CO2)
.then(fetchT1attainmentData2)
.catch(function(error) {
console.error('Error:', error);
});
},
error: function(xhr, status, error) {
console.error('Error saving data:', error);
console.log('Status:', status);
console.log('Response:', xhr.responseText);
// You can add error handling code here if needed.
}
});
noc = noc + 1;
return noc;
}
let ano=3;
function addColumnsa(noa) {
// Get the table element.
let columnName;
columnName = "Attainment" + ano;
const table = document.getElementById('attainment-table');
// Find the rows to which you want to add the column (up to totalRows - 5).
const rows = table.querySelectorAll('tbody tr');
const numRowsToAddTo = Math.max(0, rows.length - 6);
// Add a new cell to the selected rows.
rows.forEach((row, index) => {
if (index < numRowsToAddTo && index>0) {
const cell = document.createElement('td');
cell.textContent = '0';
// Insert the new cell after the specified column (noc - 1 since columns are 0-indexed).
const targetCell = row.cells[noa - 1];
if (targetCell) {
row.insertBefore(cell, targetCell.nextSibling);
} else {
row.appendChild(cell);
}
}
});
// Add a new header cell for the added column.
const headerRow = table.querySelector('thead tr');
const headerCell = document.createElement('th');
headerCell.textContent = columnName;
// Insert the new header cell after the specified column (noc - 1 since columns are 0-indexed).
const targetHeaderCell = headerRow.cells[noa - 1];
if (targetHeaderCell) {
headerRow.insertBefore(headerCell, targetHeaderCell.nextSibling);
} else {
headerRow.appendChild(headerCell);
}
// Update the header text for the existing column with the specified columnName.
const existingHeaderCell = table.querySelector(`thead th[data-column-name="${columnName}"]`);
if (existingHeaderCell) {
existingHeaderCell.textContent = columnName;
}
$.ajax({
url: '/api/updatedb', // Update the URL to match your Express route for T1attainment data
type: 'POST',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({ columnName }), // Send columnNames as JSON data
success: function(response) {
console.log('Data saved successfully:', response);
// You can add code here to handle the success response
// and update your table as needed.
},
error: function(xhr, status, error) {
console.error('Error saving data:', error);
console.log('Status:', status);
console.log('Response:', xhr.responseText);
// You can add error handling code here if needed.
}
});
noa = noa + 1;
return noa;
}
function addColumnsar(noa) {
// Get the number of columns to add from the input field.
// Create an array of column names.
let columnName;
ano=noa-4+1;
columnName="Q"+ano;
// Get the table element.
const table = document.getElementById('attainment-table');
// Get the Q6 column header.
const q6ColumnHeader = table.querySelector(`thead th:nth-child(${noa})`);
// Add new columns to the table header after the Q6 column header.
const headerRow = table.querySelector('thead tr');
const headerCell = document.createElement('th');
headerCell.textContent = columnName;
headerRow.insertBefore(headerCell, q6ColumnHeader.nextSibling);
// Add new columns to the table body after the Q6 column.
const tableBody = table.querySelector('tbody');
for (const row of tableBody.querySelectorAll('tr')) {
const q6Cell = row.querySelector(`td:nth-child(${noa})`);
const cell = document.createElement('td');
cell.textContent = '0';
row.insertBefore(cell, q6Cell.nextSibling);
}
$.ajax({
url: '/api/updatedb', // Update the URL to match your Express route for T1attainment data
type: 'POST',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({ columnName }), // Send columnNames as JSON data
success: function(response) {
console.log('Data saved successfully:', response);
// You can add code here to handle the success response
// and update your table as needed.
},
error: function(xhr, status, error) {
console.error('Error saving data:', error);
console.log('Status:', status);
console.log('Response:', xhr.responseText);
// You can add error handling code here if needed.
}
});
// addColumnsToSchema(columnNames);
noa=noa+1;
return noa;
}
function fetchcdData() {
$.ajax({
url: '/api/cd', // Change this URL to match your Express route
type: 'GET',
dataType: 'json',
success: function (data) {
data.forEach(module => {
$('#co_code').text(module.co_code);
$('#sem').text(module.sem);
$('#co_name').text(module.co_name);
$('#credits').text(module.credits);
$('#contact_hours').text(module.contact_hours);
// Display coordinators as a comma-separated list
if (module.coordinators && module.coordinators.length > 0) {
const coordinatorsList = module.coordinators.join(', ');
$('#coordinators').text(coordinatorsList);
} else {
$('#coordinators').text('N/A'); // Handle case when there are no coordinators
}
$('#teacher').text(module.teachers);
});
},
error: function (error) {
console.error('Error fetching data:', error);
}
});
}
let newModuleNo1 = 0;
function addEmptyRow3() {
const rows = $('#attainment-data tr');
const lastRow = rows.last();
// Get the last row
const cells = lastRow.find('td');
const lastModuleNo = parseInt(rows.eq(rows.length - 7).find('td').eq(0).text()) || 0;
newModuleNo1 = lastModuleNo;
const newModuleNo = lastModuleNo + 1;
console.log('Last Module No:', lastModuleNo);