public IActionResult GetChartData(string group, string subject, short year, short semester, string teacher) { var sheet = ExamSheetManager.Get(group, teacher, subject, year, semester, true); var model = new GroupChartJsonModel(); if (sheet == null) { return(Json(model)); } var semesterMarks = new Dictionary <string, short>(); var rangeMarks = new Dictionary <string, short>(); var ratings = RatingManager.FindAll(sheet.Id); model.StudentsRating = new List <StudentRating>(); foreach (var rating in ratings) { var stringRepresentation = RatingMapper.MapRatingToString(rating.Mark); var rangeRepresentation = RatingMapper.MapRatingToRange(rating.Mark); if (semesterMarks.ContainsKey(stringRepresentation)) { semesterMarks[stringRepresentation] = (short)(semesterMarks[stringRepresentation] + 1); } else { semesterMarks[stringRepresentation] = 1; } if (rangeMarks.ContainsKey(rangeRepresentation)) { rangeMarks[rangeRepresentation] = (short)(rangeMarks[rangeRepresentation] + 1); } else { rangeMarks[rangeRepresentation] = 1; } var student = StudentManager.GetById(rating.StudentId); model.StudentsRating.Add(new StudentRating() { Surname = student.Surname, Name = student.Name, Rating = rating.Mark, StringRepresentation = stringRepresentation }); } var sorted = semesterMarks.OrderBy(key => key.Key); model.SemesterMarks = sorted.ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value); sorted = rangeMarks.OrderBy(key => key.Key); model.RangeMarks = sorted.ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value); model.StudentsRating = model.StudentsRating.OrderByDescending(x => x.Rating).ToList(); return(Json(model)); }
public IActionResult Edit(ExamSheetViewModel model) { if (!ModelState.IsValid) { InitSelectItems(model.Faculty.Id); return(View(model)); } var examSheet = ExamSheetManager.Get(model.GroupId, model.TeacherId, model.SubjectId, model.Year, model.Semester); if (examSheet != null && examSheet.Id != model.Id) { ModelState.AddModelError(string.Empty, "Така відомість вже існує!"); InitSelectItems(model.Faculty.Id); return(View(model)); } SaveOrUpdate(model); return(RedirectToAction("Index", "Home")); }
public IActionResult GetSubjectData(string subject, string faculty) { var sheets = ExamSheetManager.Get(faculty, subject, true); var model = new SubjectChartJsonModel(); if (!sheets?.Any() ?? true) { return(Json(model)); } var ids = sheets.Select(x => x.Id); var groupedByYears = sheets.GroupBy(x => x.Year).OrderBy(x => x.Key); model.AverageRatings = new Dictionary <string, float>(); model.RatingFrequency = new Dictionary <short, short>(); var ratings = new List <RatingModel>(); foreach (var year in groupedByYears) { var groupedBySemesters = year.GroupBy(x => x.Semester).OrderByDescending(x => x.Key); foreach (var semester in groupedBySemesters) { var sum = 0; var count = 0; foreach (var item in semester) { ratings.AddRange(item.Ratings); sum += item.Ratings.Sum(x => x.Mark); count += item.Ratings.Count; } var average = sum / (float)count; var title = string.Format("{0} {1}", year.Key, semester.Key); model.AverageRatings.Add(title, average); } } foreach (var rating in ratings) { if (model.RatingFrequency.ContainsKey(rating.Mark)) { model.RatingFrequency[rating.Mark]++; } else { model.RatingFrequency.Add(rating.Mark, 1); } } var M = ratings.Sum(x => x.Mark) / ratings.Count; var D = ratings.Sum(x => Math.Pow(x.Mark - M, 2)) / (ratings.Count - 1); var sigma = Math.Sqrt(D); var size = 4; model.NormalDistributions = new Dictionary <short, double> [size]; for (int i = 0; i < size; ++i) { model.NormalDistributions[i] = new Dictionary <short, double>(); } var eScore = calcZScore(60, M, sigma); var cScore = calcZScore(74, M, sigma); var aScore = calcZScore(90, M, sigma); var eProbability = ZTable.GetProbability(eScore); var cProbability = ZTable.GetProbability(cScore); var aProbability = ZTable.GetProbability(aScore); var probFail = eProbability * 100; var probSatisfactorily = (cProbability - eProbability) * 100; var probGood = (aProbability - cProbability) * 100; var probExcellent = (1 - aProbability) * 100; model.NormalDistributionLabels = new List <string>() { string.Format("Ймовірність не здати предмет: {0}%", probFail.ToString("0.0")), string.Format("Ймовірність здати на 60-74: {0}%", probSatisfactorily.ToString("0.0")), string.Format("Ймовірність здати на 74-90: {0}%", probGood.ToString("0.0")), string.Format("Ймовірність здати на 90+: {0}%", probExcellent.ToString("0.0")) }; for (short i = 0; i < 100; ++i) { double func = (1 / (sigma * Math.Sqrt(2 * Math.PI))) * Math.Exp(-(Math.Pow((i - M), 2)) / (2 * sigma * sigma)); if (i < 60) { model.NormalDistributions[0].Add(i, func * 1000); } else if (i < 74) { model.NormalDistributions[1].Add(i, func * 1000); } else if (i < 90) { model.NormalDistributions[2].Add(i, func * 1000); } else { model.NormalDistributions[3].Add(i, func * 1000); } } return(Json(model)); }