/// <summary> /// Đánh giá rank dựa trên bài test /// </summary> /// <param name="db"></param> /// <param name="answers"></param> /// <returns></returns> public static RankPoint EvaluateRank(DeverateContext db, TestAnswerDTO answers) { double?totalPoint = CalculateResultPoint(db, answers); List <ConfigurationRankDTO> configurationRanks = GetRankPoint(db, answers); configurationRanks = configurationRanks.OrderBy(o => o.point).ToList(); ConfigurationRankDTO tmp = new ConfigurationRankDTO(); tmp.rankId = configurationRanks[0].rankId.Value; tmp.point = configurationRanks[0].point; foreach (ConfigurationRankDTO cr in configurationRanks) { if (tmp.point > cr.point) { tmp = cr; } } string rank = db.Rank.SingleOrDefault(r => r.RankId == tmp.rankId).Name; if (rank == null) { return(null); } return(new RankPoint(rank, tmp.point)); }
public ActionResult <IEnumerable <string> > PostEvaluateRank([FromBody] TestAnswerDTO answer) { RankPoint rp = SystemDAO.EvaluateRank(context, answer); if (rp == null) { return(new JsonResult(rm.Error("Evaluate Failed"))); } return(new JsonResult(rm.Success("Evaluate successful", rp))); }
/// <summary> /// Lấy danh sách điểm của từng rank được cấu hình /// </summary> /// <param name="db"></param> /// <param name="answer"></param> /// <returns></returns> public static List <ConfigurationRankDTO> GetRankPoint(DeverateContext db, TestAnswerDTO answer) { if (answer.testId == null) { return(null); } var result = from con in db.Configuration join te in db.Test on con.ConfigId equals te.ConfigId join cr in db.ConfigurationRank on con.ConfigId equals cr.ConfigId where te.TestId == answer.testId select new ConfigurationRankDTO(cr); return(result.ToList()); }
/// <summary> /// Tính điểm trên từng catalogue /// </summary> /// <param name="db"></param> /// <param name="answers"></param> /// <returns></returns> public static double?CalculateResultPoint(DeverateContext db, TestAnswerDTO answers) { double?totalPoint = 0; List <CataloguePointDTO> cataloguePoints = CalculateCataloguePoints(db, answers); if (answers.testId == null) { return(-1); } List <CatalogueWeightPointDTO> catalogueWeightPoints = GetWeightPoints(db, answers.testId); for (int i = 0; i < cataloguePoints.Count; i++) { totalPoint += (cataloguePoints[i].cataloguePoint / catalogueWeightPoints[i].weightPoint); } return(totalPoint); }
/// <summary> /// Tính điểm trên từng catalogue /// </summary> /// <param name="db"></param> /// <param name="answers"></param> /// <returns></returns> public static List <CataloguePointDTO> CalculateCataloguePoints(DeverateContext db, TestAnswerDTO answers) { if (answers.testId == null) { return(null); } var catas = from t in db.Test join cf in db.Configuration on t.ConfigId equals cf.ConfigId join cif in db.CatalogueInConfiguration on cf.ConfigId equals cif.ConfigId join c in db.Catalogue on cif.CatalogueId equals c.CatalogueId where t.TestId == answers.testId select new CatalogueDTO(c); List <CatalogueDTO> catalogues = catas.ToList(); List <CataloguePointDTO> cataloguePoints = new List <CataloguePointDTO>(); foreach (CatalogueDTO cata in catalogues) { float?point = 0; float?maxPoint = 0; foreach (AnswerDTO answer in answers.answers) { Answer ans = db.Answer.SingleOrDefault(an => an.AnswerId == answer.AnswerId); if (ans == null) { continue; } if (ans.Question.CatalogueId == cata.catalogueId) { maxPoint += ans.Question.MaxPoint; point += ans.Point; } } float?cataloguePoint = (point / maxPoint); cataloguePoints.Add(new CataloguePointDTO(cata.catalogueId, cataloguePoint)); } return(cataloguePoints); }