public async Task <ActionResult <TeacherStatistics> > GetTeacherStatistics(Guid teacherId, int timeStamps) { double averageMark; try { averageMark = await m_analyzer.GetTeacherAverageMark(teacherId); } catch (InvalidDataException) { averageMark = 0; } List <DateMark> averageMarks; try { averageMarks = await m_analyzer.GetTeacherAverageMarks(teacherId, timeStamps); } catch (InvalidDataException) { averageMarks = new List <DateMark>(); } double levelOfDifficulty; try { levelOfDifficulty = await m_analyzer.GetTeacherAverageLevelOfDifficulty(teacherId); } catch (InvalidDataException) { levelOfDifficulty = 0; } double wouldTakeAgainRatio; try { wouldTakeAgainRatio = await m_analyzer.GetTeacherWouldTakeTeacherAgainRatio(teacherId); } catch (InvalidDataException) { wouldTakeAgainRatio = 0; } var teacherStatistic = new TeacherStatistics { Id = Guid.NewGuid(), TeacherId = teacherId, AverageMark = averageMark, AverageMarks = averageMarks, AverageLevelOfDifficulty = levelOfDifficulty, WouldTakeAgainRatio = wouldTakeAgainRatio }; return(teacherStatistic); }
private async Task <TeacherLeaderboardEntry> GetTeacherEntryAsync(Guid teacherId) { var globalRatingCount = await m_teacherAnalyzer.GetTeacherRatingCount(teacherId); if (globalRatingCount < m_minimumRatings) { return(null); } var entry = await m_context.TeacherLeaderboard.FindAsync(teacherId) ?? new TeacherLeaderboardEntry { TeacherId = teacherId, }; entry.AllTimeRatingCount = globalRatingCount; try { entry.AllTimeAverage = await m_teacherAnalyzer.GetTeacherAverageMark(teacherId); } catch (InvalidDataException e) { if (e.Message.Equals("Teacher has no ratings.")) { entry.AllTimeAverage = 0; } } entry.ThisYearRatingCount = await m_teacherAnalyzer.GetTeacherRatingCount(teacherId, new DateTime(m_currentYear, 9, 1)); try { entry.ThisYearAverage = await m_teacherAnalyzer.GetTeacherAverageMarkInYear(teacherId, m_currentYear); } catch (InvalidDataException e) { if (e.Message.Equals("Teacher has no ratings.")) { entry.ThisYearAverage = 0; } } var globalPositiveReviews = await m_teacherAnalyzer.GetTeacherPositiveRatingCount(teacherId); var yearlyPositiveReviews = await m_teacherAnalyzer.GetTeacherPositiveRatingCountInYear(teacherId, m_currentYear); entry.AllTimeScore = GetScore(entry.AllTimeAverage, entry.AllTimeRatingCount, globalPositiveReviews); entry.ThisYearScore = GetScore(entry.ThisYearAverage, entry.ThisYearRatingCount, yearlyPositiveReviews); return(entry); }