Untitled

mail@pastecode.io avatar
unknown
plain_text
16 days ago
1.4 kB
0
Indexable
Never
public IActionResult PredictGrade() {
    var sessions = Database.StudySessions;
    var subjects = Database.Subjects; // Fetch the subjects from the database

    var results = sessions.GroupBy(s => s.SubjectID).Select(group => new {
        SubjectID = group.Key,
        SubjectName = subjects.FirstOrDefault(sub => sub.SubjectID == group.Key)?.Name, // Get the subject name
        PredictedGrade = CalculateGrade(group.ToList()),
        ExistingKnowledgeLevel = int.Parse(group.First().KnowledgeLevel),
        PredictedKnowledge = CalculatePredictedKnowledge(group.ToList())
    }).ToList();

    return View(results); // Pass the list of predicted grades to the view
}

private string CalculateGrade(List<StudySession> sessions) {
    // Calculate total study time and number of sessions for the subject
    int totalSessions = sessions.Count;
    int totalStudyTime = sessions.Sum(session =>
        (session.DurationMinutes - Database.Breaks
            .Where(b => b.StudySessionID == session.StudySessionID)
            .Sum(b => b.DurationMinutes)));

    double score = (totalStudyTime * int.Parse(sessions.First().KnowledgeLevel)) / 100.0;

    if (score >= 7) return "A";
    else if (score >= 6 && score < 7) return "B";
    else if (score >= 5 && score < 6) return "C";
    else if (score >= 4 && score < 5) return "D";
    else return "F";
}
Leave a Comment