sathwikabhavaraju2005 commited on
Commit
38df9d0
Β·
verified Β·
1 Parent(s): 7eea29a

Create weakness_analyzer.py

Browse files
Files changed (1) hide show
  1. utils/weakness_analyzer.py +43 -0
utils/weakness_analyzer.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+
3
+ def analyze_weakness(csv_file):
4
+ """
5
+ Analyzes a CSV file with student scores to identify weak topics.
6
+
7
+ Parameters:
8
+ csv_file (file): Uploaded CSV file (must contain 'Topic' and 'Score' columns).
9
+
10
+ Returns:
11
+ str: Analysis report of weak and strong topics.
12
+ """
13
+ try:
14
+ df = pd.read_csv(csv_file)
15
+
16
+ if 'Topic' not in df.columns or 'Score' not in df.columns:
17
+ return "❌ CSV must contain 'Topic' and 'Score' columns."
18
+
19
+ avg_score = df['Score'].mean()
20
+ weak_topics = df[df['Score'] < avg_score]
21
+ strong_topics = df[df['Score'] >= avg_score]
22
+
23
+ report = f"πŸ“Š Average Score: {round(avg_score, 2)}\n\n"
24
+ report += "❌ Weak Topics:\n"
25
+ if not weak_topics.empty:
26
+ report += "\n".join(
27
+ [f"- {row['Topic']} ({row['Score']})" for index, row in weak_topics.iterrows()]
28
+ )
29
+ else:
30
+ report += "None πŸŽ‰"
31
+
32
+ report += "\n\nβœ… Strong Topics:\n"
33
+ if not strong_topics.empty:
34
+ report += "\n".join(
35
+ [f"- {row['Topic']} ({row['Score']})" for index, row in strong_topics.iterrows()]
36
+ )
37
+ else:
38
+ report += "None"
39
+
40
+ return report
41
+
42
+ except Exception as e:
43
+ return f"Error analyzing file: {str(e)}"