Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -203,10 +203,13 @@ def calculate_student_stats(student, credit_map=None):
|
|
| 203 |
except ValueError:
|
| 204 |
pass
|
| 205 |
|
| 206 |
-
# If still not found anywhere,
|
| 207 |
if credits is None:
|
| 208 |
-
print(f"[
|
| 209 |
-
|
|
|
|
|
|
|
|
|
|
| 210 |
credits = 0
|
| 211 |
|
| 212 |
# Temporarily cache this mapping so we don't repeat the regex
|
|
@@ -270,14 +273,18 @@ def scrape_chunk():
|
|
| 270 |
|
| 271 |
results, skipped = fetch_vtu_results(usn_list, vtu_url, job_state=None)
|
| 272 |
|
|
|
|
| 273 |
if results:
|
| 274 |
results = [calculate_student_stats(r, fresh_credits) for r in results]
|
|
|
|
|
|
|
|
|
|
| 275 |
|
| 276 |
return jsonify({
|
| 277 |
'success': True,
|
| 278 |
-
'
|
| 279 |
-
'
|
| 280 |
-
'
|
| 281 |
})
|
| 282 |
except Exception as e:
|
| 283 |
print(f"[SCRAPE CHUNK ERROR] {e}")
|
|
@@ -651,6 +658,13 @@ def clear_database():
|
|
| 651 |
return jsonify({'success': True, 'message': msg}), 200
|
| 652 |
return jsonify({'success': False, 'message': msg}), 500
|
| 653 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 654 |
if __name__ == '__main__':
|
| 655 |
port = int(os.environ.get('PORT', 7860))
|
| 656 |
app.run(host='0.0.0.0', port=port, debug=True)
|
|
|
|
| 203 |
except ValueError:
|
| 204 |
pass
|
| 205 |
|
| 206 |
+
# If still not found anywhere, ask the user
|
| 207 |
if credits is None:
|
| 208 |
+
print(f"[MISSING CREDITS] Unknown subject '{subj_code}' encountered.")
|
| 209 |
+
if 'missing_subjects' not in student:
|
| 210 |
+
student['missing_subjects'] = []
|
| 211 |
+
if subj_code not in student['missing_subjects']:
|
| 212 |
+
student['missing_subjects'].append(subj_code)
|
| 213 |
credits = 0
|
| 214 |
|
| 215 |
# Temporarily cache this mapping so we don't repeat the regex
|
|
|
|
| 273 |
|
| 274 |
results, skipped = fetch_vtu_results(usn_list, vtu_url, job_state=None)
|
| 275 |
|
| 276 |
+
missing_subjects = set()
|
| 277 |
if results:
|
| 278 |
results = [calculate_student_stats(r, fresh_credits) for r in results]
|
| 279 |
+
for r in results:
|
| 280 |
+
if 'missing_subjects' in r:
|
| 281 |
+
missing_subjects.update(r['missing_subjects'])
|
| 282 |
|
| 283 |
return jsonify({
|
| 284 |
'success': True,
|
| 285 |
+
'results': results,
|
| 286 |
+
'skipped': skipped,
|
| 287 |
+
'missing_subjects': list(missing_subjects)
|
| 288 |
})
|
| 289 |
except Exception as e:
|
| 290 |
print(f"[SCRAPE CHUNK ERROR] {e}")
|
|
|
|
| 658 |
return jsonify({'success': True, 'message': msg}), 200
|
| 659 |
return jsonify({'success': False, 'message': msg}), 500
|
| 660 |
|
| 661 |
+
@app.route('/api/recalculate', methods=['POST'])
|
| 662 |
+
def recalculate_batch():
|
| 663 |
+
students = request.json.get('students', [])
|
| 664 |
+
fresh_credits = db.get_all_credits()
|
| 665 |
+
updated_students = [calculate_student_stats(s, fresh_credits) for s in students]
|
| 666 |
+
return jsonify({'success': True, 'results': updated_students})
|
| 667 |
+
|
| 668 |
if __name__ == '__main__':
|
| 669 |
port = int(os.environ.get('PORT', 7860))
|
| 670 |
app.run(host='0.0.0.0', port=port, debug=True)
|