Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -332,58 +332,53 @@ class TranscriptParser:
|
|
332 |
'format': 'miami_dade' # Add format identifier
|
333 |
}
|
334 |
|
335 |
-
# Parse student information
|
336 |
-
|
337 |
for i, line in enumerate(lines):
|
338 |
-
logging.debug(f"Processing line: {line}") # Added debug logging
|
339 |
if "DORAL ACADEMY HIGH SCHOOL" in line:
|
340 |
-
#
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
try:
|
346 |
-
# Parse school and cohort info - more defensive
|
347 |
-
school_info_parts = student_info_lines[0].split('|')
|
348 |
-
if len(school_info_parts) > 2:
|
349 |
-
data['student_info']['school'] = school_info_parts[1].strip() if len(school_info_parts) > 1 else ''
|
350 |
-
data['student_info']['district'] = school_info_parts[2].strip() if len(school_info_parts) > 2 else ''
|
351 |
|
352 |
-
#
|
353 |
-
if len(
|
354 |
-
|
355 |
-
if len(
|
356 |
-
name_parts =
|
357 |
if len(name_parts) > 1:
|
358 |
-
data['student_info']['student_id'] =
|
359 |
data['student_info']['student_name'] = name_parts[1].strip() + " " + name_parts[0].strip()
|
360 |
|
361 |
-
#
|
362 |
-
if len(
|
363 |
-
academic_info =
|
364 |
-
if len(academic_info) >
|
365 |
-
data['student_info']['current_grade'] = academic_info[1].split(':')[1].strip() if ':' in academic_info[1] else
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
|
|
|
|
|
|
381 |
|
382 |
# Parse graduation requirements
|
383 |
requirements_start = None
|
384 |
requirements_end = None
|
385 |
for i, line in enumerate(lines):
|
386 |
-
logging.debug(f"Processing line: {line}") # Added debug logging
|
387 |
if "Code" in line and "Description" in line and "Required" in line:
|
388 |
requirements_start = i + 1
|
389 |
if requirements_start and "Total" in line:
|
@@ -392,26 +387,21 @@ class TranscriptParser:
|
|
392 |
|
393 |
if requirements_start and requirements_end:
|
394 |
for line in lines[requirements_start:requirements_end]:
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
data['graduation_requirements'].append(req)
|
408 |
-
except Exception as e:
|
409 |
-
logging.warning(f"Error parsing requirement line: {line} - {str(e)}")
|
410 |
-
if strict_mode:
|
411 |
-
raise
|
412 |
|
413 |
# Parse total line
|
414 |
-
|
415 |
total_line = lines[requirements_end]
|
416 |
total_parts = [p.strip() for p in total_line.split('|') if p.strip()]
|
417 |
if len(total_parts) >= 5:
|
@@ -419,15 +409,10 @@ class TranscriptParser:
|
|
419 |
data['summary']['total_waived'] = total_parts[2]
|
420 |
data['summary']['total_completed'] = total_parts[3]
|
421 |
data['summary']['completion_percentage'] = total_parts[4]
|
422 |
-
except Exception as e:
|
423 |
-
logging.warning(f"Error parsing requirements summary: {str(e)}")
|
424 |
-
if strict_mode:
|
425 |
-
raise
|
426 |
|
427 |
# Parse course history
|
428 |
course_history_start = None
|
429 |
for i, line in enumerate(lines):
|
430 |
-
logging.debug(f"Processing line: {line}") # Added debug logging
|
431 |
if "Requirement" in line and "School Year" in line and "GradeLv1" in line:
|
432 |
course_history_start = i + 1
|
433 |
break
|
@@ -435,33 +420,28 @@ class TranscriptParser:
|
|
435 |
if course_history_start:
|
436 |
current_requirement = None
|
437 |
for line in lines[course_history_start:]:
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
data['course_history'].append(course)
|
461 |
-
except Exception as e:
|
462 |
-
logging.warning(f"Error parsing course line: {line} - {str(e)}")
|
463 |
-
if strict_mode:
|
464 |
-
raise
|
465 |
|
466 |
# Calculate graduation status
|
467 |
try:
|
@@ -475,9 +455,8 @@ class TranscriptParser:
|
|
475 |
}
|
476 |
data['graduation_status'] = graduation_status
|
477 |
except Exception as e:
|
478 |
-
logging.warning(f"Error calculating graduation status: {str(e)}")
|
479 |
if strict_mode:
|
480 |
-
raise
|
481 |
|
482 |
return data
|
483 |
|
|
|
332 |
'format': 'miami_dade' # Add format identifier
|
333 |
}
|
334 |
|
335 |
+
# Parse student information
|
336 |
+
student_info_found = False
|
337 |
for i, line in enumerate(lines):
|
|
|
338 |
if "DORAL ACADEMY HIGH SCHOOL" in line:
|
339 |
+
# School info line
|
340 |
+
school_info = line.split('|')
|
341 |
+
if len(school_info) > 1:
|
342 |
+
data['student_info']['school'] = school_info[1].strip()
|
343 |
+
data['student_info']['district'] = school_info[2].strip() if len(school_info) > 2 else ''
|
|
|
|
|
|
|
|
|
|
|
|
|
344 |
|
345 |
+
# Student ID and name line
|
346 |
+
if i+1 < len(lines):
|
347 |
+
student_line = lines[i+1].split('-')
|
348 |
+
if len(student_line) > 1:
|
349 |
+
name_parts = student_line[1].split(',')
|
350 |
if len(name_parts) > 1:
|
351 |
+
data['student_info']['student_id'] = student_line[0].strip()
|
352 |
data['student_info']['student_name'] = name_parts[1].strip() + " " + name_parts[0].strip()
|
353 |
|
354 |
+
# Academic info line
|
355 |
+
if i+2 < len(lines):
|
356 |
+
academic_info = lines[i+2].split('|')
|
357 |
+
if len(academic_info) > 1:
|
358 |
+
data['student_info']['current_grade'] = academic_info[1].split(':')[1].strip() if ':' in academic_info[1] else academic_info[1].strip()
|
359 |
+
if len(academic_info) > 2:
|
360 |
+
data['student_info']['graduation_year'] = academic_info[2].strip()
|
361 |
+
if len(academic_info) > 3:
|
362 |
+
gpa_part = academic_info[3].strip()
|
363 |
+
if 'Weighted GPA' in gpa_part:
|
364 |
+
data['student_info']['weighted_gpa'] = gpa_part.split(':')[1].strip() if ':' in gpa_part else ''
|
365 |
+
elif 'Un-weighted GPA' in gpa_part:
|
366 |
+
data['student_info']['unweighted_gpa'] = gpa_part.split(':')[1].strip() if ':' in gpa_part else ''
|
367 |
+
if len(academic_info) > 4:
|
368 |
+
data['student_info']['community_service_date'] = academic_info[4].split(':')[1].strip() if ':' in academic_info[4] else ''
|
369 |
+
if len(academic_info) > 5:
|
370 |
+
data['student_info']['total_credits_earned'] = academic_info[5].split(':')[1].strip() if ':' in academic_info[5] else ''
|
371 |
+
|
372 |
+
student_info_found = True
|
373 |
+
break
|
374 |
+
|
375 |
+
if not student_info_found and strict_mode:
|
376 |
+
raise ValueError("Could not find student information section")
|
377 |
|
378 |
# Parse graduation requirements
|
379 |
requirements_start = None
|
380 |
requirements_end = None
|
381 |
for i, line in enumerate(lines):
|
|
|
382 |
if "Code" in line and "Description" in line and "Required" in line:
|
383 |
requirements_start = i + 1
|
384 |
if requirements_start and "Total" in line:
|
|
|
387 |
|
388 |
if requirements_start and requirements_end:
|
389 |
for line in lines[requirements_start:requirements_end]:
|
390 |
+
if '|' in line:
|
391 |
+
parts = [p.strip() for p in line.split('|') if p.strip()]
|
392 |
+
if len(parts) >= 6:
|
393 |
+
req = {
|
394 |
+
'code': parts[0],
|
395 |
+
'description': parts[1],
|
396 |
+
'required': parts[2],
|
397 |
+
'waived': parts[3],
|
398 |
+
'completed': parts[4],
|
399 |
+
'status': parts[5]
|
400 |
+
}
|
401 |
+
data['graduation_requirements'].append(req)
|
|
|
|
|
|
|
|
|
|
|
402 |
|
403 |
# Parse total line
|
404 |
+
if requirements_end < len(lines):
|
405 |
total_line = lines[requirements_end]
|
406 |
total_parts = [p.strip() for p in total_line.split('|') if p.strip()]
|
407 |
if len(total_parts) >= 5:
|
|
|
409 |
data['summary']['total_waived'] = total_parts[2]
|
410 |
data['summary']['total_completed'] = total_parts[3]
|
411 |
data['summary']['completion_percentage'] = total_parts[4]
|
|
|
|
|
|
|
|
|
412 |
|
413 |
# Parse course history
|
414 |
course_history_start = None
|
415 |
for i, line in enumerate(lines):
|
|
|
416 |
if "Requirement" in line and "School Year" in line and "GradeLv1" in line:
|
417 |
course_history_start = i + 1
|
418 |
break
|
|
|
420 |
if course_history_start:
|
421 |
current_requirement = None
|
422 |
for line in lines[course_history_start:]:
|
423 |
+
if '|' in line:
|
424 |
+
parts = [p.strip() for p in line.split('|') if p.strip()]
|
425 |
+
|
426 |
+
# Check if this is a new requirement line
|
427 |
+
if len(parts) >= 2 and parts[0] and parts[0] in [req['code'] for req in data['graduation_requirements']]:
|
428 |
+
current_requirement = parts[0]
|
429 |
+
parts = parts[1:] # Remove the requirement code
|
430 |
+
|
431 |
+
if len(parts) >= 9:
|
432 |
+
course = {
|
433 |
+
'requirement': current_requirement,
|
434 |
+
'school_year': parts[0],
|
435 |
+
'grade_level': parts[1],
|
436 |
+
'course_number': parts[2],
|
437 |
+
'description': parts[3],
|
438 |
+
'term': parts[4],
|
439 |
+
'district_number': parts[5],
|
440 |
+
'fg': parts[6],
|
441 |
+
'included': parts[7],
|
442 |
+
'credits': parts[8]
|
443 |
+
}
|
444 |
+
data['course_history'].append(course)
|
|
|
|
|
|
|
|
|
|
|
445 |
|
446 |
# Calculate graduation status
|
447 |
try:
|
|
|
455 |
}
|
456 |
data['graduation_status'] = graduation_status
|
457 |
except Exception as e:
|
|
|
458 |
if strict_mode:
|
459 |
+
raise ValueError(f"Error calculating graduation status: {str(e)}")
|
460 |
|
461 |
return data
|
462 |
|