예제 #1
0
        public JsonResult GetJobProfileByCategoriesChartData()
        {
            var curJob = this.jobsRepo.FindOne(new ByIdSpecify<Job>(this.CurrentJobId));

            var skillCatNames = curJob.JobSkills.Select(x => x.SkillCategory).Distinct().Select(x => x.Name);

            var skillCatGroupedData = curJob.JobSkills.GroupBy(g => g.SkillCategoryId);

            var skillsData = new List<ChartSeriesModel>();

            foreach (var skillCat in skillCatGroupedData)
            {
                if (skillCat.Any())
                {
                    var skillData = new ChartSeriesModel
                        {
                            Name = skillCat.First().SkillCategory.Name,
                            CategoryAvgEstimate = Math.Round((double)skillCat.Sum(x => x.Estimate) / skillCat.Count(), 2)
                        };

                    foreach (var jobSkill in skillCat)
                    {
                        skillData.Categories.Add(jobSkill.Skill.Name);
                        skillData.Data.Add(jobSkill.Estimate);
                    }

                    skillsData.Add(skillData);
                }
            }

            return this.Json(
                    new { SkillCatNames = skillCatNames, SkillsData = skillsData },
                    JsonRequestBehavior.AllowGet);
        }
        public JsonResult GetJobProfileSkillsChartData(long? jobId, long? candidateId)
        {
            var skillsData = new List<ChartSeriesModel>();
            var skillNames = new List<string>();
            Job curJob = null;

            if (jobId.HasValue)
            {
                curJob = this.jobsRepo.FindOne(new ByIdSpecify<Job>(jobId.Value));

                skillNames.AddRange(curJob.JobSkills.Where(x=>x.Estimate > 0).Select(x => x.Skill).Select(x => x.Name));

                skillsData.Add(new ChartSeriesModel
                    {
                        Name = "Job Profile",
                        Data = curJob.JobSkills.Where(x=>x.Estimate > 0).Select(x => double.Parse(x.Estimate.ToString())).ToList(),
                        YAxis = 0
                    });
            }

            if (candidateId.HasValue)
            {
                var candidate = this.usersRepo.FindOne(new ByIdSpecify<User>(candidateId.Value));

                var seriesName = string.Format("{0} {1} Profile", candidate.LastName, candidate.FirstName);

                var userSkills = new List<UserSkill>();
                if (curJob != null)
                {
                    userSkills = candidate.UsersSkills.Where(x => curJob.JobSkills.Any(a => a.SkillId == x.SkillId && a.Estimate > 0)).ToList();
                }
                else
                {
                    skillNames.AddRange(candidate.UsersSkills.Select(x => x.Skill).Select(x => x.Name));
                    userSkills = candidate.UsersSkills.ToList();
                }

                skillsData.Add(new ChartSeriesModel
                {
                    Name = seriesName,
                    Data = userSkills.Select(x => double.Parse(x.Estimate.ToString())).ToList(),
                    YAxis = 0
                });

                // Select TestResults for candidate skills
                var testResults = candidate.TestResults.Where(x => userSkills.Any(s => s.SkillId == x.Test.SkillId)).ToList();

                var skillTestRes = new ChartSeriesModel
                    {
                        Name = "Test Results",
                        YAxis = 1
                    };
                foreach (var skill in userSkills)
                {
                    var testRes = testResults.FirstOrDefault(x => x.Test.SkillId == skill.SkillId);
                    if (testRes != null)
                    {
                        // Percent correct answers
                        var totalQuestions = testRes.Test.Questions.Count;
                        var correctAnswers = testRes.ResultQuestions.Count(x => x.ResultAnswers.Any(a => a.IsCorrect && a.IsChoisen));
                        skillTestRes.Data.Add(Math.Round((double)correctAnswers/totalQuestions*100, 2));
                    }
                    else
                    {
                        skillTestRes.Data.Add(0);
                    }
                }

                skillsData.Add(skillTestRes);
            }

            return this.Json(new { SkillNames = skillNames, SkillsData = skillsData }, JsonRequestBehavior.AllowGet);
        }