public PersonalityTestElementStandardResult[] GetPersonalityTestElementStandardResults(PersonalityTestPaperResult[] paperResults)
        {
            var questionsSetCodes = paperResults.Select(item => item.QuestionsSetCode).Distinct().ToList();
            var ages = paperResults.Select(item => item.Age).Distinct().ToList();

            List <PersonalityTestQuestionsSet> questionsSets;
            List <PersonalityTestElementStandardParametersSet> elementStandardParametersSets;

            using (var context = new ComputingServicesContext())
            {
                questionsSets = context.PersonalityTestQuestionsSets.Include(item => item.Questions.Select(question => question.ChoiceScores)).Where(item => questionsSetCodes.Contains(item.Code)).ToList();
                elementStandardParametersSets = context.PersonalityTestElementStandardParametersSets.Include(item => item.Parameters.Select(parameter => parameter.Segments)).Where(item => ages.Any(age => age >= item.AgeMin && age <= item.AgeMax)).ToList();
            }

            List <PersonalityTestElementStandardResult> elementStandardResultList = new List <PersonalityTestElementStandardResult>();

            foreach (PersonalityTestPaperResult paperResult in paperResults)
            {
                var questionsSet = questionsSets.Single(item => item.Code == paperResult.QuestionsSetCode);

                Core.Domain.Models.Shared.Gender gender = ConvertToDomain(paperResult.Gender);

                var elementStandardParametersSet = elementStandardParametersSets.Single(item => item.Gender == gender && paperResult.Age >= item.AgeMin && paperResult.Age <= item.AgeMax);

                var elementStandardResult = GetPersonalityTestElementStandardResult(paperResult, questionsSet, elementStandardParametersSet);

                elementStandardResultList.Add(elementStandardResult);
            }

            return(elementStandardResultList.ToArray());
        }
        private Gender ConvertToApp(Core.Domain.Models.Shared.Gender domainGender)
        {
            switch (domainGender)
            {
            case Core.Domain.Models.Shared.Gender.Male: return(Gender.MALE);

            case Core.Domain.Models.Shared.Gender.Female: return(Gender.FEMALE);

            default: throw new ArgumentException("Can not mapping to app gender.");
            }
        }
        private CertainSportAbilityTestStandardResult GetCertainSportAbilityTestStandardResult(CertainSportAbilityTestOriginalResult originalResult, CertainSportAbilityTestEvaluationCriteriaSportBundle sportBundle)
        {
            CertainSportAbilityTestStandardResult standardResult = new CertainSportAbilityTestStandardResult();

            int age = GetCertainSportAbilityTestAge(originalResult.Birthdate, originalResult.TestDate);

            Core.Domain.Models.Shared.Gender gender = ConvertToDomain(originalResult.Gender);

            var sport = sportBundle.Sport;

            List <CertainSportAbilityTestStandardSubScore> standardSubScoreList = new List <CertainSportAbilityTestStandardSubScore>();

            foreach (var originalSubScore in originalResult.SubScores)
            {
                //确定子项目
                var subSport = sportBundle.SubSports.Single(item => item.Sport == sport && item.Code == originalSubScore.SubType);

                //确定评分标准集,符合年龄、性别条件
                var subSportParametersSet = sportBundle.SubSportParametersSets.Single(item => item.SubSport == subSport && item.AgeMin <= age && item.AgeMax >= age && (item.Gender == null || item.Gender == gender));

                CertainSportAbilityTestStandardSubScore standardSubScore = GetCertainSportAbilityTestStandardSubScore(originalSubScore.Value, subSportParametersSet);

                standardSubScoreList.Add(standardSubScore);
            }
            standardResult.SubScores = standardSubScoreList.ToArray();

            int overallScore = standardSubScoreList.Sum(item => item.Value);

            var sportParameter = sport.Parameters.Where(item => overallScore >= item.Score && (item.Gender == null || item.Gender == gender) && (item.AgeMin == null || item.AgeMin <= age) && (item.AgeMax == null || item.AgeMax <= age)).OrderByDescending(item => item.Score).FirstOrDefault();

            standardResult.OverallScore = overallScore.ToString();
            if (sportParameter != null)
            {
                standardResult.Level = sportParameter.Level;
            }
            standardResult.RefId = originalResult.RefId;

            return(standardResult);
        }
Example #4
0
        protected void btnImportPersonalityTestElementStandardParametersSet_Click(object sender, EventArgs e)
        {
            List <PersonalityTestElementStandardParametersSet> parametersSetList = new List <PersonalityTestElementStandardParametersSet>();

            string dataDirectoryPath = MapPath("~/App_Data/PersonalityTest");

            string[] dataFilePaths = Directory.GetFiles(dataDirectoryPath, "ElementStandardParametersSet*.xml");

            foreach (string dataFilePath in dataFilePaths)
            {
                XmlDocument xd = new XmlDocument();
                xd.Load(dataFilePath);

                XmlElement xeElementStandardParametersSet = (XmlElement)xd.SelectSingleNode("ElementStandardParametersSet");
                string     name   = xeElementStandardParametersSet.GetAttribute("Name");
                int        ageMin = int.Parse(xeElementStandardParametersSet.GetAttribute("AgeMin"));
                int        ageMax = int.Parse(xeElementStandardParametersSet.GetAttribute("AgeMax"));
                Core.Domain.Models.Shared.Gender gender = (Core.Domain.Models.Shared.Gender)Enum.Parse(typeof(Core.Domain.Models.Shared.Gender), xeElementStandardParametersSet.GetAttribute("Gender"));

                PersonalityTestElementStandardParametersSet parametersSet = new PersonalityTestElementStandardParametersSet(name, ageMin, ageMax, gender);

                foreach (XmlNode xnParameter in xeElementStandardParametersSet.SelectNodes("Parameter"))
                {
                    XmlElement xeParameter = (XmlElement)xnParameter;

                    string             parameterElement = xeParameter.GetAttribute("Element");
                    PersonalityElement element          = (PersonalityElement)Enum.Parse(typeof(PersonalityElement), parameterElement);
                    decimal            parameterX       = decimal.Parse(xeParameter.GetAttribute("X"));
                    decimal            parameterS       = decimal.Parse(xeParameter.GetAttribute("S"));

                    PersonalityTestElementStandardParameter elementStandardParameter = new PersonalityTestElementStandardParameter(element, parameterX, parameterS);

                    foreach (XmlNode xnSegment in xeParameter.SelectNodes("Segment"))
                    {
                        XmlElement xeSegment = (XmlElement)xnSegment;

                        int originalScoreMin = int.Parse(xeSegment.GetAttribute("OriginalScoreMin"));
                        int originalScoreMax = int.Parse(xeSegment.GetAttribute("OriginalScoreMax"));
                        int standardScore    = int.Parse(xeSegment.GetAttribute("StandardScore"));

                        PersonalityTestElementStandardParameterSegment parameterSegment = new PersonalityTestElementStandardParameterSegment(originalScoreMin, originalScoreMax, standardScore);

                        elementStandardParameter.Segments.Add(parameterSegment);
                    }

                    parametersSet.Parameters.Add(elementStandardParameter);
                }

                parametersSetList.Add(parametersSet);
            }

            if (parametersSetList.Count > 0)
            {
                using (var context = new ComputingServicesContext())
                {
                    foreach (var parametersSet in parametersSetList)
                    {
                        var oldPersonalityTestElementStandardParametersSet = context.PersonalityTestElementStandardParametersSets.Where(item => item.AgeMin == parametersSet.AgeMin && item.AgeMax == parametersSet.AgeMax).ToList().SingleOrDefault(item => item.Gender == parametersSet.Gender);
                        if (oldPersonalityTestElementStandardParametersSet != null)
                        {
                            context.PersonalityTestElementStandardParametersSets.Remove(oldPersonalityTestElementStandardParametersSet);
                        }
                        context.PersonalityTestElementStandardParametersSets.Add(parametersSet);
                    }
                    context.SaveChanges();
                }

                ltlLog.Text = "成功完成。";
            }
            else
            {
                ltlLog.Text = "没有数据。";
            }
        }