예제 #1
0
 private void InitFieldCriteria(QueryField field, ComparisonOp comparisonOp, object value)
 {
     Field = field;
     ComparisonOperator = comparisonOp;
     FieldValue         = value;
     if (FieldValue is IEnumerable && !(FieldValue is string))
     {
         FieldValue = new CriteriaValues((IEnumerable)FieldValue);
     }
 }
예제 #2
0
        private CriteriaValues GetCriteriaValuesFromDimension(string colDimName, Func <CriteriaValues, bool> predicat, Dictionary <long, DataSetDimension> dimIds, Dictionary <long, IEnumerable <CriteriaValues> > dico)
        {
            long idDim = dimIds.Where(kv => kv.Value.ColumnName == colDimName).Select(kv => kv.Value.Dimension.Id).FirstOrDefault();

            if ((idDim != 0) && dico.ContainsKey(idDim))
            {
                // Important, créer un nouvel objet pour chaque CriteriaValues, vu que chaque SelectorInstance doit avoir ses propres cv
                CriteriaValues cvLight = dico[idDim].Where(predicat).FirstOrDefault();
                if (cvLight != null)
                {
                    return new CriteriaValues()
                           {
                               Criteria = cvLight.Criteria, Value = cvLight.Value
                           }
                }
                ;
            }
            return(null);
        }
        private void FinishButton(object sender, RoutedEventArgs e)
        {
            if (alternativesSomplete && criteriasComplete)
            {
                weightsCriteria = new Weights(CriteriaQuestions.CriteriasNames.Count);

                for (int i = 0; i < QuestionsCriteria.Count; i++)
                {
                    double weight = QuestionsCriteria[i].getValue();
                    int    x      = combinationsCriteria.CombinationList[i].itemOne;
                    int    y      = combinationsCriteria.CombinationList[i].itemTwo;

                    weightsCriteria.InsertToTable(x, y, weight);
                }

                weightsAlternatives = new List <Weights>();
                int idc = 0;
                for (int i = 0; i < CriteriaQuestions.CriteriasNames.Count; i++)
                {
                    weightsAlternatives.Add(new Weights(AlternativeQuestions.Count));
                }
                for (int i = 0; i < combinationAlternatives.CombinationList.Count; i++)
                {
                    for (int j = 0; j < CriteriaQuestions.CriteriasNames.Count; j++)
                    {
                        int    x      = combinationAlternatives.CombinationList[i].itemOne;
                        int    y      = combinationAlternatives.CombinationList[i].itemTwo;
                        double weight = QuestionsAlternative[idc].getValue();
                        int    id     = QuestionsAlternative[idc].compare;
                        weightsAlternatives[id].InsertToTable(x, y, weight);
                        idc++;
                    }
                }

                cValues = new CriteriaValues(CriteriaQuestions.CriteriasNames.Count);
                cValues.Count(weightsCriteria.weights);

                aValues = new List <CriteriaValues>();
                for (int i = 0; i < CriteriaQuestions.CriteriasNames.Count; i++)
                {
                    aValues.Add(new CriteriaValues(AlternativeQuestions.Count));
                    aValues[i].Count(weightsAlternatives[i].weights);
                }


                Validate        validateCriterias    = new Validate(CriteriaQuestions.CriteriasNames.Count, cValues.Values, weightsCriteria.weights, errorLevel);
                List <Validate> validateAlternatives = new List <Validate>();
                for (int i = 0; i < CriteriaQuestions.CriteriasNames.Count; i++)
                {
                    validateAlternatives.Add(new Validate(AlternativeQuestions.Count, aValues[i].Values, weightsAlternatives[i].weights, errorLevel));
                }
                bool correctly = true;
                correctly = validateCriterias.Cohesion();
                foreach (Validate item in validateAlternatives)
                {
                    correctly = item.Cohesion();
                }
                if (!correctly)
                {
                    ValidationResult vr = new ValidationResult();
                    if (vr.ShowDialog() == true)
                    {
                        correctly = vr.confirm();
                    }
                }
                if (correctly)
                {
                    RatingAlternatives ratingAlternatives = new RatingAlternatives(AlternativeQuestions.Count, CriteriaQuestions.CriteriasNames.Count);
                    ratingAlternatives.Count(cValues.Values, aValues);
                    data = new List <KeyValuePair <string, double> >();
                    data.Clear();

                    for (int i = 0; i < AlternativeQuestions.Count; i++)
                    {
                        data.Add(new KeyValuePair <string, double>(AlternativeQuestions[i].Name, ratingAlternatives.Values[i]));
                    }
                    chartWindow = new ChartWindow(data);
                    chartWindow.Show();
                }
            }
        }
        /// <summary>
        /// Envoi la liste des CriteriaValues existants pour ce Criteria.
        /// </summary>
        /// <param name="criteria">Criteria</param>
        /// <param name="wfInstance">Instance du WorkflowInstance</param>
        /// <returns>Liste des CriteriaValues</returns>
        public async Task <IEnumerable <CriteriaValues> > ExtractCriteriaValues(Criteria criteria, WorkflowInstance wfInstance)
        {
            if ((criteria == null) || (wfInstance == null))
            {
                throw new WrongParameterException("ExtractCriteriaValues: criteria or wfInstance are null.");
            }

            List <CriteriaValues> lst = new List <CriteriaValues>();

            if (_regexCharAllValues.IsMatch(criteria.Value))
            {
                List <string> distinctValue = await UnitOfWork.GetDbContext().DistinctValue
                                              .Where(dv => dv.DataSetId == wfInstance.DataSetId && dv.DimensionId == criteria.Dimension.Id)
                                              .Select(dv => dv.Value)
                                              .AsNoTracking()
                                              .ToAsyncEnumerable()
                                              .ToList();

                foreach (string valeur in distinctValue)
                {
                    CriteriaValues cv = new CriteriaValues()
                    {
                        Criteria = criteria, Value = valeur
                    };
                    lst.Add(cv);
                }
                return(lst);
            }
            if (_regexBracketsChar.IsMatch(criteria.Value))
            {
                if (criteria.Dimension.TypeDimension == DimensionTypeEnum.Tree)
                {
                    Match  mb     = _regexBracketsChar.Match(criteria.Value);
                    string niveau = mb.Groups["level"].Value;

                    List <string> nodes = await UnitOfWork.GetDbContext().DimensionTreeData //Dimension
                                          .Include(dt => dt.Dimensions)
                                          .Where(dt => dt.Dimensions.Any(ds => ds.Id == criteria.Dimension.Id))
                                          .Where(dt => dt.LevelName == niveau)
                                          .Select(dt => dt.ValueKey)
                                          .AsNoTracking()
                                          .ToAsyncEnumerable()
                                          .ToList();

                    foreach (string valeur in nodes)
                    {
                        CriteriaValues cv = new CriteriaValues()
                        {
                            Criteria = criteria, Value = valeur
                        };
                        lst.Add(cv);
                    }
                    return(lst);
                }
            }

            // Par défaut, on considére qu'il s'agit d'une valeur...
            List <string> existingValue = await UnitOfWork.GetDbContext().DistinctValue
                                          .Where(dv => dv.DataSetId == wfInstance.DataSetId && dv.DimensionId == criteria.Dimension.Id && dv.Value == criteria.Value)
                                          .Select(dv => dv.Value)
                                          .AsNoTracking()
                                          .ToAsyncEnumerable()
                                          .ToList();

            // Controle de la valeur
            if ((existingValue == null) || (existingValue.Count == 0))
            {
                throw new SequenceException($"Criteria value {criteria.Value} don't exist!");
            }

            CriteriaValues cvSingle = new CriteriaValues()
            {
                Criteria = criteria, Value = criteria.Value
            };

            lst.Add(cvSingle);

            return(lst);
        }
        private async Task <HttpResponseMessageResult> ExecuteAggregatePrimeum(long referenceSequence, int OrderSequence, SelectorInstance selectorInstance, WorkflowInstance wfInstance)
        {
            HttpResponseMessageResult res = new HttpResponseMessageResult()
            {
                IsSuccess = true
            };
            await ConfigVariableDomain.LoadVariables();

            string nomDimension = await GetActionParameter(referenceSequence, OrderSequence, Constant.PARAMETER_ACTION_AGGREGATE_PRIMEUM_ALIGNMENTNAME);

            long idDimension = await GetIdDimensionTree(nomDimension, Constant.PARAMETER_ACTION_AGGREGATE_PRIMEUM_ALIGNMENTNAME, wfInstance);

            // niveau utiisateur
            CriteriaValues cvTree = await UnitOfWork.GetDbContext().CriteriaValues
                                    .Include(cv => cv.Criteria)
                                    .ThenInclude(c => c.Dimension)
                                    .Where(cv => cv.SelectorInstanceModifier != null && cv.SelectorInstanceModifier.Id == selectorInstance.Id && cv.Criteria.Dimension.Id == idDimension)
                                    .AsNoTracking()
                                    .FirstOrDefaultAsync();

            string valueTopUser = cvTree?.Value;
            int    levelTopUser = 0;

            if (!string.IsNullOrWhiteSpace(valueTopUser))
            {
                levelTopUser = valueTopUser.Split(ConfigVariableDomain.AlignmentChar).Length;
            }

            Dictionary <long, Tuple <ValueObject, int, string, bool> > dicVo = await ValueObjectDomain.CreateDictionaryVO(nomDimension, selectorInstance);

            // Construction des arbres
            int topLvl    = dicVo.Values.Select(t => t.Item2).Min();
            int bottomLvl = dicVo.Values.Select(t => t.Item2).Max();
            IEnumerable <TreeValueObject> lstTree = ValueObjectDomain.BuildTreeVO(dicVo, nomDimension, topLvl, bottomLvl);

            // On part du dernier niveau editable pour remonter jusqu'au niveau user.
            int bottom = dicVo.Values.Where(t => t.Item4).Select(t => t.Item2).Max();

            HashSet <long> idsAlreadyComputed = new HashSet <long>();
            HashSet <KeyValuePair <long, double> > modifiedValues = new HashSet <KeyValuePair <long, double> >();

            foreach (TreeValueObject tvo in lstTree)
            {
                for (int currentLvl = bottom; currentLvl > levelTopUser; currentLvl--)
                {
                    IEnumerable <TreeValueObject> nodes = TreeValueObject.GetNodesFromLevel(tvo, currentLvl);
                    foreach (TreeValueObject child in nodes)
                    {
                        if ((child.Parent == null) || idsAlreadyComputed.Contains(child.Parent.Node.Id) || (child.Parent.Level <= levelTopUser))
                        {
                            continue;
                        }

                        double sum = child.Parent.Children.Select(subnode => ValueObjectDomain.GetMostCurrentValue(subnode.Node)).Sum();
                        child.Parent.Node.FutureValue = sum;
                        modifiedValues.Add(new KeyValuePair <long, double>(child.Parent.Node.Id, sum));
                        idsAlreadyComputed.Add(child.Parent.Node.Id);
                    }
                }
            }

            // On sauve les modifications
            int nbr = await UnitOfWork.GetDbContext().SaveChangesAsync();

            // Mise à jour de la table temporaire
            res.Append(await GridConfigurationDomain.SaveDataInTemporyTable(selectorInstance, wfInstance, modifiedValues));

            return(res);
        }
예제 #6
0
        /// <summary>
        /// Recherche du modificateur pour le SelectorInstance donné en paramétre.
        /// </summary>
        /// <param name="selectorInstance">SelectorInstance</param>
        /// <param name="wfInstance">WorkflowInstance</param>
        /// <returns>Message de retour</returns>
        public async Task <HttpResponseMessageResult> FindModificator(SelectorInstance selectorInstance, WorkflowInstance wfInstance)
        {
            if (selectorInstance == null)
            {
                throw new WrongParameterException($"SelectorInstanceDomain.FindModificator: SelectorInstance is null.");
            }
            if (selectorInstance.SelectorConfig == null)
            {
                throw new WrongParameterException($"SelectorInstanceDomain.FindModificator: SelectorConfig is null (Id SelectorInstance : {selectorInstance.Id}).");
            }
            if (selectorInstance.SelectorConfig.Modifiers == null)
            {
                throw new SequenceException($"SelectorInstance.FindModificator : no modificator found, error in SelectorConfig (no Modifiers list). Id SelectorConfig : {selectorInstance.SelectorConfig.Id}");
            }

            HttpResponseMessageResult res = new HttpResponseMessageResult()
            {
                IsSuccess = true
            };
            IEnumerable <IGrouping <int, Criteria> > lstGrp = selectorInstance.SelectorConfig.Modifiers.GroupBy(c => c.ChainNumber);

            int currentChain = -1;

            if ((lstGrp != null) && (lstGrp.Count() > 0))
            {
                currentChain = lstGrp.Min(g => g.Key);
            }
            User modificator = null;
            IEnumerable <UserSetUser> lstUsu = null;
            IGrouping <int, Criteria> grp    = null;

            // On parcourt les chaines de criteria une à une afin de trouver le modificateur.
            while ((currentChain > -1) && (modificator == null))
            {
                grp = lstGrp.Where(g => g.Key == currentChain).FirstOrDefault();
                if (grp == null)
                {
                    throw new SequenceException($"SelectorInstance.FindModificator : no modificator found, error in SelectorConfig (no group). Id SelectorConfig : {selectorInstance.SelectorConfig.Id}");
                }

                IEnumerable <IEnumerable <CriteriaValues> > lstCv = await CriteriaDomain.ExtractAllCriteriaValues(grp, wfInstance);

                lstUsu = await UserSetDomain.GetUsersByRight(lstCv, wfInstance.DataSetId, RightEnum.Modification);

                IEnumerable <User> modificators = lstUsu.Select(usu => usu.User).Distinct(new UserComparer((x, y) => x.Id == y.Id));

                // Gestion des cas des modificateurs
                if ((modificators == null) || (modificators.Count() == 0))
                {
                    IEnumerable <int> lstNumber = lstGrp.Select(g => g.Key).Where(i => i > currentChain);
                    if (lstNumber.Count() > 0)
                    {
                        currentChain = lstNumber.OrderBy(i => i).First();
                    }
                    else
                    {
                        throw new ConfigurationException("SelectorInstanceDomain.FindModificator : no modificator was found.");
                    }
                }
                if (modificators.Count() > 1)
                {
                    throw new ConfigurationException("SelectorInstanceDomain.FindModificator : more than one modificator was found.");
                }
                if (modificators.Count() == 1)
                {
                    modificator = modificators.ElementAt(0);
                }
            }

            if (modificator == null)
            {
                throw new DataLoadingException($"SelectorInstanceDomain.FindModificator : No modificator found for SelectorInstance (Id : {selectorInstance.Id}).");
            }

            // Régler le SelectorInstance avec l'id de l'utilisateur trouvé.
            selectorInstance.ChainNumberModifyer = currentChain;
            selectorInstance.ModifyerId          = modificator.Id;
            UserSetUser usuDistinct = lstUsu.FirstOrDefault();

            if (usuDistinct == null)
            {
                throw new DataLoadingException("SelectorInstanceDomain.FindModificator : a problem with loading UserSetUser must stop this finding.");
            }

            Dictionary <long, DataSetDimension> dimIds = await DataSetDimensionDomain.GetDimensionColumns(wfInstance.DataSetId);

            foreach (Criteria crit in grp)
            {
                string         dimName = dimIds.Values.Where(v => v.Dimension.Id == crit.Dimension.Id).Select(v => v.ColumnName).FirstOrDefault();
                string         value   = GetValueFromDimension(usuDistinct, dimName);
                CriteriaValues cv      = new CriteriaValues()
                {
                    Criteria = crit, SelectorInstanceModifier = selectorInstance, Value = value
                };
                selectorInstance.ModifyCriteriasValues.Add(cv);
            }

            return(res);
        }