public PermanentCongruenceResults ComputeOutcome(string permaTokenA, string permaTokenB)
        {
            var retval = new PermanentCongruenceResults();

            try
            {
                var refer  = _respondentsRepository.GetPermanentResults(permaTokenA);
                var victim = _respondentsRepository.GetPermanentResults(permaTokenB);

                if (refer?.ScopeId != victim?.ScopeId)
                {
                    return(retval);
                }

                if (refer.ScopeId != 224053984)
                {
                    _log.Warning("Only 224053984 test is supported now.");
                    return(retval);
                }
                retval.ScopeId = refer.ScopeId;
                var quest = _questionnaireRepository.FindQuestionnaireById(refer.ScopeId);

                var mapR    = MapResultsForQuestFifth(refer, quest);
                var mapV    = MapResultsForQuestFifth(victim, quest);
                var matches = new List <(int indexR, int indexV, string nameR, string nameV, double val, bool match)>();

                for (int i = 0; i < mapR.Length; i++)
                {
                    for (int j = 0; j < mapV.Length; j++)
                    {
                        matches.Add((i, j, mapR[i].Name, mapV[j].Name, _adjuscentMatrix[i, j], _adjuscentMatrix[i, j] == 0.8 && mapR[i].Value == 1 && mapV[j].Value == 1));
Пример #2
0
        public QuestionnaireScope GetQuestionnaire(string token, long scopeId, int questionnumber = -1)
        {
            if (!_userValidation.ValidateToken(token))
            {
                throw new AddressAccessDeniedException();
            }
            try
            {
                var cacheKey = $"Scope_{scopeId}";
                QuestionnaireScope scope;
                if (_questionnaireScopes.TryGetValue(cacheKey, out QuestionnaireScope tmpScope))
                {
                    scope = CloneQuestionnaireScope(tmpScope);
                }
                else
                {
                    _log.Information($"{GetCurrentMethod()} #{scopeId} cached.");
                    var questionaire = _questionnaireRepository.FindQuestionnaireById(scopeId);

                    if (_questionnaireScopes.TryAdd(cacheKey, questionaire))
                    {
                        scope = CloneQuestionnaireScope(questionaire);
                    }
                    else
                    {
                        scope = questionaire;
                    }
                }

                if (scope.Entries.Any(z => z.Number == questionnumber))
                {
                    scope.Entries = scope.Entries.Where(z => z.Number == questionnumber).ToList();
                    scope.Outcomes.Clear();
                }
                return(scope);
            }
            catch (Exception ex)
            {
                _log.Error(ex, ex.Message);
                return(null);
            }
        }