Пример #1
0
        public double Compare(XmlBase answer, double Value)
        {
            var order = answer as XmlMultyAnswer;

            if (order == null)
            {
                throw new Exception("Wrong answer type");
            }

            if (order.Answer.Length != Options.Count())
            {
                throw new Exception("Answer is initialized wrong");
            }

            var correctAnswer = Options.Select(x => x.Id).ToList();

            double eCount = 0;

            for (int i = 0; i < order.Answer.Length; ++i)
            {
                if (order.Answer[i] != correctAnswer[i])
                {
                    eCount++;
                }
            }

            return(Value * (1 - (eCount / order.Answer.Length)));
        }
Пример #2
0
        public double Compare(XmlBase answer, double Value)
        {
            var _answer = answer as XmlTextInputAnswer;

            if (_answer == null)
            {
                throw new Exception("Wrong answer type");
            }

            if (Input == _answer.Answer)
            {
                return(Value);
            }

            return(0);
        }
Пример #3
0
        public static XElement SerializeAbstract(XmlBase obj)
        {
            //var type = property.PropertyType.GetGenericArguments()[0];

            //var methodInfo = typeof(DiagramWorker).GetRuntimeMethods()
            //    .Where(x => x.Name == "CompareList").Single();

            //var genericMethod = methodInfo.MakeGenericMethod(type);

            //genericMethod.Invoke(this, new object[]
            //    { property.GetValue(_correct), property.GetValue(_received), result });

            var methodInfo = typeof(XmlBase).GetRuntimeMethods().
                             Where(x => x.Name == "_instanceSerializer").Single();

            var genericMethod = methodInfo.MakeGenericMethod(obj.GetType());

            return((XElement)genericMethod.Invoke(obj, new object[] { obj }));
        }
Пример #4
0
        public double Compare(XmlBase answer, double Value)
        {
            if (ListType == null)
            {
                throw new Exception("list isn't initialized");
            }

            if (this.ListType == XmlQuestionType.Checkbox)
            {
                var converted = answer as XmlMultyAnswer;

                var trueAnswers = Options.Where(x => x.IsTrue).Select(y => y.Id).ToList();

                double trueCount = 0;

                foreach (var item in converted.Answer)
                {
                    if (trueAnswers.Contains(item))
                    {
                        trueCount++;
                    }
                }

                return((Value / trueAnswers.Count) * trueCount);
            }
            else
            {
                var converted = answer as XmlSingleAnswer;

                if (converted.Answer == Options.Single(x => x.IsTrue).Id)
                {
                    return(Value);
                }

                return(0);
            }
        }
Пример #5
0
        public double Compare(XmlBase answer, double Value)
        {
            if (MatchingType == XmlMatchingType.Multy)
            {
                var _answer = answer as XmlMatchingMultyAnswer;

                double eCount = 0;

                foreach (var item in Answers)
                {
                    if (!_answer.Answer.Contains(item))
                    {
                        ++eCount;
                    }
                }

                foreach (var item in _answer.Answer)
                {
                    if (!Answers.Contains(item))
                    {
                        ++eCount;
                    }
                }

                if (eCount >= Answers.Count)
                {
                    eCount = Answers.Count;
                }

                return(Value * (1 - (eCount / Answers.Count)));
            }
            else if (MatchingType == XmlMatchingType.Single)
            {
                var _answer = answer as XmlMatchingSingleAnswer;

                var correctAnswers = Answers.OrderBy(x => x.Key).
                                     Select(y => y.Value).ToList();

                var input = _answer.Answer.ToList().Take(Rows.Count).ToList();

                double eCount = 0;

                if (correctAnswers.Count != input.Count())
                {
                    throw new Exception("Matching - wrong option count");
                }

                for (int i = 0; i < correctAnswers.Count; ++i)
                {
                    if (correctAnswers[i] != input[i])
                    {
                        eCount++;
                    }
                }

                return(Value * (1 - (eCount / correctAnswers.Count)));
            }
            else
            {
                throw new Exception("Matching isn't initialized");
            }
        }