yamanavijayavardhan commited on
Commit
5ed4851
·
1 Parent(s): b2d0a56

fix index.html new

Browse files
Files changed (2) hide show
  1. main.py +9 -5
  2. templates/index.html +15 -71
main.py CHANGED
@@ -359,7 +359,7 @@ def compute_marks():
359
  base_temp_dir = tempfile.mkdtemp()
360
  log_print(f"Created temporary directory: {base_temp_dir}")
361
 
362
- # Dictionary to store results by student folder
363
  results = {}
364
  failed_files = []
365
 
@@ -390,9 +390,9 @@ def compute_marks():
390
  })
391
  continue
392
 
 
393
  if student_folder not in results:
394
- results[student_folder] = [0] * len(correct_answers)
395
- log_print(f"Processing student folder: {student_folder}")
396
 
397
  # Save and process file
398
  student_dir = os.path.join(base_temp_dir, student_folder)
@@ -455,7 +455,7 @@ def compute_marks():
455
  continue
456
 
457
  marks = new_value(best_score, 0, 1, 0, 5)
458
- results[student_folder][best_answer_index] = round(marks, 2)
459
  log_print(f"Processed {filename} for {student_folder}: {marks} marks")
460
 
461
  except Exception as e:
@@ -485,7 +485,11 @@ def compute_marks():
485
  clean_results = {}
486
  for student, scores in results.items():
487
  clean_student = student.encode('ascii', 'ignore').decode('ascii')
488
- clean_results[clean_student] = scores
 
 
 
 
489
 
490
  response = jsonify({
491
  "results": clean_results,
 
359
  base_temp_dir = tempfile.mkdtemp()
360
  log_print(f"Created temporary directory: {base_temp_dir}")
361
 
362
+ # Dictionary to store results by student folder and image name
363
  results = {}
364
  failed_files = []
365
 
 
390
  })
391
  continue
392
 
393
+ # Initialize student results if not exists
394
  if student_folder not in results:
395
+ results[student_folder] = {}
 
396
 
397
  # Save and process file
398
  student_dir = os.path.join(base_temp_dir, student_folder)
 
455
  continue
456
 
457
  marks = new_value(best_score, 0, 1, 0, 5)
458
+ results[student_folder][filename] = round(marks, 2)
459
  log_print(f"Processed {filename} for {student_folder}: {marks} marks")
460
 
461
  except Exception as e:
 
485
  clean_results = {}
486
  for student, scores in results.items():
487
  clean_student = student.encode('ascii', 'ignore').decode('ascii')
488
+ clean_scores = {}
489
+ for filename, mark in scores.items():
490
+ clean_filename = filename.encode('ascii', 'ignore').decode('ascii')
491
+ clean_scores[clean_filename] = mark
492
+ clean_results[clean_student] = clean_scores
493
 
494
  response = jsonify({
495
  "results": clean_results,
templates/index.html CHANGED
@@ -1044,86 +1044,30 @@
1044
  }
1045
 
1046
  function displayMarks(results) {
1047
- const container = document.getElementById('marks-table-container');
1048
- container.innerHTML = '';
1049
-
1050
- if (!results || Object.keys(results).length === 0) {
1051
- container.innerHTML = '<p class="error-message">No marks were computed. Please check your input files and answers.</p>';
1052
- return;
1053
- }
1054
-
1055
- const table = document.createElement('table');
1056
- table.innerHTML = `
1057
- <thead>
1058
- <tr>
1059
- <th>Student Folder</th>
1060
- <th>Image Name</th>
1061
- <th>Marks</th>
1062
- </tr>
1063
- </thead>
1064
- <tbody>
1065
- </tbody>
1066
  `;
1067
-
1068
- const tbody = table.querySelector('tbody');
1069
- const studentGroups = {};
1070
 
1071
- // Process the object format
1072
- Object.entries(results).forEach(([student, marks]) => {
1073
- // Add row for individual marks
1074
- marks.forEach((mark, index) => {
1075
  const row = document.createElement('tr');
1076
  row.innerHTML = `
1077
  <td>${student}</td>
1078
- <td>answer${index + 1}.jpg</td>
1079
  <td>${mark}</td>
1080
  `;
1081
- tbody.appendChild(row);
1082
  });
1083
-
1084
- // Calculate average for this student
1085
- const total = marks.reduce((sum, mark) => sum + mark, 0);
1086
- studentGroups[student] = {
1087
- total: total,
1088
- count: marks.length
1089
- };
1090
  });
1091
-
1092
- // Add separator row
1093
- const separatorRow = document.createElement('tr');
1094
- separatorRow.innerHTML = '<td colspan="3" style="border-top: 2px solid #4361ee;"></td>';
1095
- tbody.appendChild(separatorRow);
1096
-
1097
- // Add average rows
1098
- Object.entries(studentGroups).forEach(([student, data]) => {
1099
- const averageRow = document.createElement('tr');
1100
- const average = (data.total / data.count).toFixed(2);
1101
- averageRow.innerHTML = `
1102
- <td>${student}</td>
1103
- <td><strong>Average</strong></td>
1104
- <td><strong>${average}</strong></td>
1105
- `;
1106
- averageRow.style.backgroundColor = '#f8f9fa';
1107
- tbody.appendChild(averageRow);
1108
- });
1109
-
1110
- container.appendChild(table);
1111
-
1112
- // Add summary section
1113
- const summary = document.createElement('div');
1114
- summary.className = 'marks-summary';
1115
-
1116
- const totalStudents = Object.keys(studentGroups).length;
1117
- const overallAverage = Object.values(studentGroups)
1118
- .reduce((acc, curr) => acc + (curr.total / curr.count), 0) / totalStudents;
1119
-
1120
- summary.innerHTML = `
1121
- <h4>Summary</h4>
1122
- <p>Total Students: ${totalStudents}</p>
1123
- <p>Overall Average: ${overallAverage.toFixed(2)}</p>
1124
- `;
1125
-
1126
- container.appendChild(summary);
1127
  }
1128
  </script>
1129
  </body>
 
1044
  }
1045
 
1046
  function displayMarks(results) {
1047
+ const tableBody = document.getElementById('marks-table-body');
1048
+ tableBody.innerHTML = '';
1049
+
1050
+ // Create table header
1051
+ const headerRow = document.createElement('tr');
1052
+ headerRow.innerHTML = `
1053
+ <th>Student Folder</th>
1054
+ <th>Image Name</th>
1055
+ <th>Marks</th>
 
 
 
 
 
 
 
 
 
 
1056
  `;
1057
+ tableBody.appendChild(headerRow);
 
 
1058
 
1059
+ // Add results
1060
+ Object.entries(results).forEach(([student, scores]) => {
1061
+ Object.entries(scores).forEach(([filename, mark]) => {
 
1062
  const row = document.createElement('tr');
1063
  row.innerHTML = `
1064
  <td>${student}</td>
1065
+ <td>${filename}</td>
1066
  <td>${mark}</td>
1067
  `;
1068
+ tableBody.appendChild(row);
1069
  });
 
 
 
 
 
 
 
1070
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1071
  }
1072
  </script>
1073
  </body>