public ActionResult Create()
        {
            var model = new RuleSetModel();

            PrepareTemplateViewBag(0);

            return(View(model));
        }
Esempio n. 2
0
        public ActionResult Create(RuleScope?scope)
        {
            var model = new RuleSetModel();

            PrepareModel(model, null, scope);
            PrepareTemplateViewBag(0);

            return(View(model));
        }
Esempio n. 3
0
 public static void Patch(this RuleSetModel ruleSetModel, RuleSet ruleSet, UserModel user)
 {
     if (ruleSetModel == null)
     {
         return;
     }
     ruleSetModel.Name = ruleSet.Name;
     ruleSetModel.Patch(user);
 }
Esempio n. 4
0
        public ActionResult Edit(RuleSetModel model, bool continueEditing)
        {
            var ruleSet = _ruleStorage.GetRuleSetById(model.Id, true, true);

            MiniMapper.Map(model, ruleSet);

            _ruleStorage.UpdateRuleSet(ruleSet);

            return(continueEditing ? RedirectToAction("Edit", new { id = ruleSet.Id }) : RedirectToAction("List"));
        }
Esempio n. 5
0
        public async Task <RuleSetModel> SaveRuleSetAsync(RuleSetModel model)
        {
            using (var scope = _container.BeginLifetimeScope())
            {
                var repository = scope.Resolve <IRuleSetRepository>();

                RuleSet ruleSet;

                if (model.RuleSetId > 0)
                {
                    ruleSet = await repository.GetAsync(model.RuleSetId);
                }
                else
                {
                    ruleSet = repository.Add(new RuleSet());
                }

                if (ruleSet != null)
                {
                    ruleSet.Name        = model.Name;
                    ruleSet.Description = model.Description;
                    ruleSet.Deleted     = model.Deleted;
                    ruleSet.Period      = model.Period;

                    await repository.CommitAsync();

                    var detailsRepository = scope.Resolve <IRuleSetDetailsRepository>();
                    await detailsRepository.DeleteAsync(ruleSet.RuleSetId);

                    await detailsRepository.CommitAsync();

                    if (model.Rules.Any(r => !r.Deleted))
                    {
                        var orderId = 1;
                        foreach (var rule in model.Rules.Where(r => !r.Deleted))
                        {
                            var details = detailsRepository.Add(new RuleSetDetails());
                            details.RuleId    = rule.RuleId;
                            details.OrderId   = orderId;
                            details.RuleSetId = ruleSet.RuleSetId;

                            orderId += 1;
                        }
                        await detailsRepository.CommitAsync();
                    }


                    model.RuleSetId = ruleSet.RuleSetId;
                }


                return(model);
            }
        }
Esempio n. 6
0
 public static RuleSet FromDal(this RuleSetModel ruleSetModel)
 {
     if (ruleSetModel == null) return null;
     var result = new RuleSet
     {
         Id = ruleSetModel.RuleSetId,
         Name = ruleSetModel.Name,
         Status = ruleSetModel.Status.FromDal()
     };
     return result.SyncBase(ruleSetModel);
 }
Esempio n. 7
0
        public void ScoreExample1Test()
        {
            string  pFilePath  = "test-ruleset1.xml";
            string  modelname  = "NestedDrug";
            string  paramList  = "BP='HIGH', K=0.0621, Age = 36, Na = 0.5023";
            string  res        = "may play";
            decimal confidence = 0.47M;

            Pmml pmml = Pmml.loadModels(pFilePath);

            Assert.NotNull(pmml);

            ModelElement model = pmml.getByName(modelname);

            Assert.NotNull(model);

            Assert.IsInstanceOf <RuleSetModel>(model);

            RuleSetModel rs = (RuleSetModel)model;

            // Check exemple 1 as 3 RuleSelectionMethod for first node
            Assert.IsNotNull(rs.RuleSet);
            Assert.IsNotNull(rs.RuleSet.RuleSelectionMethods);
            Assert.AreEqual(3, rs.RuleSet.RuleSelectionMethods.Count);

            // Check 3 Rule
            Assert.AreEqual(3, rs.RuleSet.Rules.Count);

            // Modification for aggregateNode
            //tree.MissingValueStrategy = MissingValueStrategy.AggregateNodes;

            Dictionary <string, object> lDict = parseParams(paramList);

            ScoreResult result = rs.Score(lDict);

            Assert.NotNull(result);


            /*foreach(Node item in result.Nodes)
             * {
             *      Console.WriteLine("Node {0} = score {1}", item.Id, item.Score);
             *
             *      foreach(ScoreDistribution it2 in item.ScoreDistributions)
             *              Console.WriteLine("\tScore Dist. {0} ({1}) = {2}", it2.Value, it2.RecordCount, it2.Confidence);
             * }*/

            Assert.AreEqual(res, result.Value);
            Assert.AreEqual(confidence, result.Confidence);
        }
        public ActionResult Create(RuleSetModel model, bool continueEditing)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var ruleSet = MiniMapper.Map <RuleSetModel, RuleSetEntity>(model);

            _ruleStorage.InsertRuleSet(ruleSet);

            NotifySuccess(T("Admin.Rules.RuleSet.Added"));

            return(continueEditing ? RedirectToAction("Edit", new { id = ruleSet.Id }) : RedirectToAction("List"));
        }
Esempio n. 9
0
        public void ScoreCarfTest(string paramList, string res, decimal confidence)
        {
            string pFilePath = "models\\RuleSetCarrefour.xml";
            string modelname = "CARF-20140124";

            Pmml pmml = Pmml.loadModels(pFilePath);

            Assert.NotNull(pmml);

            ModelElement model = pmml.getByName(modelname);

            Assert.NotNull(model);

            Assert.IsInstanceOf <RuleSetModel>(model);

            RuleSetModel rs = (RuleSetModel)model;

            // Check CARF as 1 RuleSelectionMethod for first node
            Assert.IsNotNull(rs.RuleSet);
            Assert.IsNotNull(rs.RuleSet.RuleSelectionMethods);
            Assert.AreEqual(1, rs.RuleSet.RuleSelectionMethods.Count);
            Assert.AreEqual("firstHit", rs.RuleSet.RuleSelectionMethods[0].Criterion);

            // Check 11 Rule
            Assert.AreEqual(11, rs.RuleSet.Rules.Count);

            // Modification for aggregateNode
            //tree.MissingValueStrategy = MissingValueStrategy.AggregateNodes;

            Dictionary <string, object> lDict = parseParams(paramList);
            //for

            ScoreResult result = rs.Score(lDict);

            Assert.NotNull(result);


            /*foreach(Node item in result.Nodes)
             * {
             *      Console.WriteLine("Node {0} = score {1}", item.Id, item.Score);
             *
             *      foreach(ScoreDistribution it2 in item.ScoreDistributions)
             *              Console.WriteLine("\tScore Dist. {0} ({1}) = {2}", it2.Value, it2.RecordCount, it2.Confidence);
             * }*/

            Assert.AreEqual(res, result.Value);
            Assert.AreEqual(confidence, result.Confidence);
        }
Esempio n. 10
0
        public RuleSetModel CreateRuleSet(string name, Guid guid)
        {
            var ruleSet = Context.RuleSets.FindByGuid(guid);

            if (ruleSet == null)
            {
                var status = Context.Statuses.FindByGuid(PredefinedGuids.Draft);
                var utcNow = DateTime.UtcNow;
                ruleSet = new RuleSetModel
                {
                    Name             = name,
                    Guid             = guid,
                    LastModifiedTime = utcNow,
                    CreateTime       = utcNow,
                    Creator          = ServiceUser,
                    LastModifiedBy   = ServiceUser,
                    Status           = status,
                };
                Context.RuleSets.Add(ruleSet);
                Context.SaveChanges();
            }
            return(ruleSet);
        }
        public ActionResult Edit(RuleSetModel model, bool continueEditing)
        {
            var ruleSet = _ruleStorage.GetRuleSetById(model.Id, true, true);

            MiniMapper.Map(model, ruleSet);

            _ruleStorage.UpdateRuleSet(ruleSet);

            if (model.RawRuleData.HasValue())
            {
                try
                {
                    var ruleData = JsonConvert.DeserializeObject <RuleEditItem[]>(model.RawRuleData);

                    SaveRuleData(ruleData, model.Scope);
                }
                catch (Exception ex)
                {
                    NotifyError(ex);
                }
            }

            return(continueEditing ? RedirectToAction("Edit", new { id = ruleSet.Id }) : RedirectToAction("List"));
        }
Esempio n. 12
0
        public static void Patch(this CardModel cardModel, Card card,
                                 SerieModel serieModel, FactionModel factionModel, CardTypeModel cardTypeModel, StatusModel statusModel, RuleSetModel ruleSetModel, UserModel user)
        {
            if (cardModel == null)
            {
                return;
            }
            if (card == null)
            {
                return;
            }
            cardModel.Name         = card.Name;
            cardModel.FirstName    = card.FirstName;
            cardModel.LastName     = card.LastName;
            cardModel.Artist       = card.Artist;
            cardModel.RuleText     = card.RuleText;
            cardModel.FlavorText   = card.FlavorText;
            cardModel.SubType      = card.SubType;
            cardModel.Cost         = card.Cost;
            cardModel.Loyalty      = card.Loyalty;
            cardModel.Attack       = card.Attack;
            cardModel.Defense      = card.Defense;
            cardModel.Info         = card.Info;
            cardModel.MarkdownText = card.MarkdownText;
            cardModel.LanguageCode = card.Language?.LanguageCode ?? "en";


            if (serieModel != null)
            {
                cardModel.Serie = serieModel;
            }
            if (factionModel != null)
            {
                cardModel.Faction = factionModel;
            }
            if (cardTypeModel != null)
            {
                cardModel.Type = cardTypeModel;
            }
            if (statusModel != null)
            {
                cardModel.Status = statusModel;
            }
            if (ruleSetModel != null)
            {
                cardModel.RuleSet = ruleSetModel;
            }
            cardModel.Patch(user);
        }
Esempio n. 13
0
        public async Task <IHttpActionResult> SaveRuleSet([FromBody] RuleSetModel model)
        {
            var rule = await _service.SaveRuleSetAsync(model);

            return(Ok(rule));
        }
Esempio n. 14
0
        private void PrepareModel(RuleSetModel model, RuleSetEntity entity, RuleScope?scope = null)
        {
            var scopes = (entity?.Scope ?? scope ?? RuleScope.Cart).ToSelectList();

            model.Scopes = scopes
                           .Select(x =>
            {
                var item = new ExtendedSelectListItem
                {
                    Value    = x.Value,
                    Text     = x.Text,
                    Selected = x.Selected
                };

                var ruleScope = (RuleScope)x.Value.ToInt();
                item.CustomProperties["Description"] = ruleScope.GetLocalizedEnum(Services.Localization, Services.WorkContext, true);

                return(item);
            })
                           .ToList();

            if ((entity?.Id ?? 0) != 0)
            {
                var provider = _ruleProvider(entity.Scope);

                model.ScopeName       = entity.Scope.GetLocalizedEnum(Services.Localization, Services.WorkContext);
                model.ExpressionGroup = _ruleFactory.CreateExpressionGroup(entity, provider, true);

                model.AssignedToDiscounts = entity.Discounts
                                            .Select(x => new RuleSetModel.AssignedToEntityModel {
                    Id = x.Id, Name = x.Name.NullEmpty() ?? x.Id.ToString()
                })
                                            .ToList();

                model.AssignedToShippingMethods = entity.ShippingMethods
                                                  .Select(x => new RuleSetModel.AssignedToEntityModel {
                    Id = x.Id, Name = x.GetLocalized(y => y.Name)
                })
                                                  .ToList();

                var paymentMethods = entity.PaymentMethods;
                if (paymentMethods.Any())
                {
                    var paymentProviders = _paymentService.Value.LoadAllPaymentMethods().ToDictionarySafe(x => x.Metadata.SystemName);

                    model.AssignedToPaymentMethods = paymentMethods
                                                     .Select(x =>
                    {
                        string friendlyName = null;
                        if (paymentProviders.TryGetValue(x.PaymentMethodSystemName, out var paymentProvider))
                        {
                            friendlyName = _pluginMediator.Value.GetLocalizedFriendlyName(paymentProvider.Metadata);
                        }

                        return(new RuleSetModel.AssignedToEntityModel
                        {
                            Id = x.Id,
                            Name = friendlyName.NullEmpty() ?? x.PaymentMethodSystemName,
                            SystemName = x.PaymentMethodSystemName
                        });
                    })
                                                     .ToList();
                }

                model.AssignedToCustomerRoles = entity.CustomerRoles
                                                .Select(x => new RuleSetModel.AssignedToEntityModel {
                    Id = x.Id, Name = x.Name
                })
                                                .ToList();

                model.AssignedToCategories = entity.Categories
                                             .Select(x => new RuleSetModel.AssignedToEntityModel {
                    Id = x.Id, Name = x.GetLocalized(y => y.Name)
                })
                                             .ToList();
            }
        }