smart-lms-suite / utils /weakness_analyzer.py
sathwikabhavaraju2005's picture
Create weakness_analyzer.py
38df9d0 verified
import pandas as pd
def analyze_weakness(csv_file):
"""
Analyzes a CSV file with student scores to identify weak topics.
Parameters:
csv_file (file): Uploaded CSV file (must contain 'Topic' and 'Score' columns).
Returns:
str: Analysis report of weak and strong topics.
"""
try:
df = pd.read_csv(csv_file)
if 'Topic' not in df.columns or 'Score' not in df.columns:
return "❌ CSV must contain 'Topic' and 'Score' columns."
avg_score = df['Score'].mean()
weak_topics = df[df['Score'] < avg_score]
strong_topics = df[df['Score'] >= avg_score]
report = f"πŸ“Š Average Score: {round(avg_score, 2)}\n\n"
report += "❌ Weak Topics:\n"
if not weak_topics.empty:
report += "\n".join(
[f"- {row['Topic']} ({row['Score']})" for index, row in weak_topics.iterrows()]
)
else:
report += "None πŸŽ‰"
report += "\n\nβœ… Strong Topics:\n"
if not strong_topics.empty:
report += "\n".join(
[f"- {row['Topic']} ({row['Score']})" for index, row in strong_topics.iterrows()]
)
else:
report += "None"
return report
except Exception as e:
return f"Error analyzing file: {str(e)}"