Update main.py
Browse files
main.py
CHANGED
@@ -452,7 +452,7 @@ def select_files(coaching_code):
|
|
452 |
|
453 |
# Main route to get sorted scores
|
454 |
@app.post("/get_sorted_scores")
|
455 |
-
async def
|
456 |
journal_file, panic_button_file, test_file = select_files(data.coachingCode)
|
457 |
|
458 |
# Load data into DataFrames
|
@@ -523,47 +523,33 @@ async def get_sorted_scores(data: CoachingCodeRequest):
|
|
523 |
'test_scores': test_scores_dict
|
524 |
})
|
525 |
|
526 |
-
|
527 |
-
academic_weights = {'BACKLOGS': -5, 'MISSED CLASSES': -4, 'NOT UNDERSTANDING': -3, 'BAD MARKS': -3, 'LACK OF MOTIVATION': -3}
|
528 |
-
non_academic_weights = {'EMOTIONAL FACTORS': -3, 'PROCRASTINATE': -2, 'LOST INTEREST': -4, 'LACK OF FOCUS': -2, 'GOALS NOT ACHIEVED': -2, 'LACK OF DISCIPLINE': -2}
|
529 |
-
max_weighted_panic_score = sum([max(academic_weights.values()) * 3, max(non_academic_weights.values()) * 3])
|
530 |
-
|
531 |
-
def calculate_potential_score(row):
|
532 |
-
if row['test_scores']:
|
533 |
-
avg_test_score = sum(row['test_scores'].values()) / len(row['test_scores'])
|
534 |
-
test_score_normalized = (avg_test_score / 40) * 70
|
535 |
-
else:
|
536 |
-
test_score_normalized = 0
|
537 |
-
student_panic_score = 0
|
538 |
-
if row['panic_button']:
|
539 |
-
for factor, count in row['panic_button'].items():
|
540 |
-
if factor in academic_weights:
|
541 |
-
student_panic_score += academic_weights[factor] * count
|
542 |
-
elif factor in non_academic_weights:
|
543 |
-
student_panic_score += non_academic_weights[factor] * count
|
544 |
-
else:
|
545 |
-
student_panic_score = 0
|
546 |
-
panic_score = 20 * (1 - (student_panic_score / max_weighted_panic_score) if max_weighted_panic_score != 0 else 1)
|
547 |
-
if pd.notna(row['productivity_yes_no']) and row['productivity_yes_no'] == 'Yes':
|
548 |
-
if pd.notna(row['productivity_rate']):
|
549 |
-
journal_score = (float(row['productivity_rate']) / 10) * 10
|
550 |
-
else:
|
551 |
-
journal_score = 0
|
552 |
-
elif pd.notna(row['productivity_yes_no']) and row['productivity_yes_no'] == 'No':
|
553 |
-
if pd.notna(row['productivity_rate']):
|
554 |
-
journal_score = (float(row['productivity_rate']) / 10) * 5
|
555 |
-
else:
|
556 |
-
journal_score = 0
|
557 |
-
else:
|
558 |
-
journal_score = 0
|
559 |
-
total_potential_score = test_score_normalized + panic_score + journal_score
|
560 |
-
return total_potential_score
|
561 |
|
562 |
merged_df = merged_data_cleaned.groupby('user_id').apply(process_group).reset_index()
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
567 |
|
568 |
-
|
|
|
569 |
|
|
|
452 |
|
453 |
# Main route to get sorted scores
|
454 |
@app.post("/get_sorted_scores")
|
455 |
+
async def get_revison_chapters(data: CoachingCodeRequest):
|
456 |
journal_file, panic_button_file, test_file = select_files(data.coachingCode)
|
457 |
|
458 |
# Load data into DataFrames
|
|
|
523 |
'test_scores': test_scores_dict
|
524 |
})
|
525 |
|
526 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
527 |
|
528 |
merged_df = merged_data_cleaned.groupby('user_id').apply(process_group).reset_index()
|
529 |
+
revision_dict = {}
|
530 |
+
|
531 |
+
# Define the score threshold for requiring revision
|
532 |
+
threshold = 16
|
533 |
+
|
534 |
+
# Iterate through each student's test_scores
|
535 |
+
for index, row in merged_df.iterrows():
|
536 |
+
user_id = row['user_id']
|
537 |
+
test_scores = row['test_scores']
|
538 |
+
|
539 |
+
# Check each chapter's score for this student
|
540 |
+
for chapter, score in test_scores.items():
|
541 |
+
if score < threshold:
|
542 |
+
if chapter not in revision_dict:
|
543 |
+
revision_dict[chapter] = []
|
544 |
+
revision_dict[chapter].append(user_id)
|
545 |
+
|
546 |
+
# Convert the dictionary to the desired DataFrame format
|
547 |
+
revision_df = pd.DataFrame({
|
548 |
+
'chapter_name': list(revision_dict.keys()),
|
549 |
+
'user_ids_needing_revision': [', '.join(users) for users in revision_dict.values()]
|
550 |
+
})
|
551 |
+
|
552 |
|
553 |
+
revision_json = revision_df.to_dict(orient="records")
|
554 |
+
return {"data": revision_json}
|
555 |
|