コード例 #1
0
        internal void Handler()
        {
            wrToFile = ifWrToFile();
            if (!wrToFile)
            {
                return;             // if model not changed -> no handing is necessary
            }
            getGroups();
            foreach (var gr in elmGroups)
            {
                bool b = false;
                foreach (var rule in Rules)
                {
                    Mtch _match = new Mtch(gr, rule);
                    if (_match.ok == Mtch.OK.Match)
                    {
                        matches.Add(_match); b = true; break;
                    }
//27/3                    else log.Info("No Match Group. mat= " + gr.mat + "\tprf=" + gr.prf);
                }
                if (!b)
                {
                    log.Info("No Match Group. mat= " + gr.mat + "\tprf=" + gr.prf);
                }
            }
            getSuppliers();
            getPricing();
        }
コード例 #2
0
ファイル: Handler.cs プロジェクト: PavelKhrapkin/TSmatch
        /// <summary>
        /// Hndl(model) - find matching Components for model and total_price
        /// </summary>
        /// <param name="mod">model to be handled</param>
        public void Hndl(ref Mod mod)
        {
            Log.set("MH.Hndl");
            mod.elmGroups = getGrps(mod.elements);
            if (mod.elmGroups.Count < 1 || mod.Rules.Count < 1) Msg.F("No Rules or element Groups");
            if(testMode) { Log.exit(); return; }

            foreach (var rules in mod.Rules)
                if (rules.CompSet == null) rules.Init();
            // find matching Components with Rules by module Mtch 
            foreach (var gr in mod.elmGroups)
            {
                bool b = false;
                foreach (var rule in mod.Rules)
                {
                    Mtch _match = new Mtch(gr, rule);
                    if (_match.ok == Mtch.OK.Match)
                    {
                        mod.matches.Add(_match);
                        gr.CompSetName = _match.rule.sCS;
                        gr.SupplierName = _match.rule.sSupl;
                        gr.compDescription = _match.component.Str(Section.Section.SType.Description);
                        b = true; break;
                    }
                }
                if (!b) log.Info("No Match Group. mat= " + gr.mat + "\tprf=" + gr.prf);
            }
            // calculate prices for matches      
            mod.total_price = mod.elmGroups.Sum(x => x.totalPrice);
            mod.pricingDate = DateTime.Now;
            mod.pricingMD5 = mod.get_pricingMD5(mod.elmGroups);
            Log.Trace("price date=\t" + mod.pricingDate + "\tMD5=" + mod.pricingMD5);
            log.Info("Model.Hndl set " + mod.matches.Count + " groups. Total price=" + mod.total_price + " rub");
            Log.exit();
        }
コード例 #3
0
ファイル: Handler.cs プロジェクト: PavelKhrapkin/TSmatch
        public void Pricing(ref Mod m, bool unit_test_mode = false)
        {
            Log.set("mh.Pricing");
#if DEBUG
            testMode = unit_test_mode;
            var x = new Mtch(m);
#endif
            if (m.Rules == null || m.Rules.Count == 0)
            {
                m = sr._GetSavedRules(m);
            }
            log.Info(">m.MD5=" + m.MD5 + " =?= " + m.getMD5(m.elements));
            Hndl(ref m);
            log.Info(">m.MD5=" + m.MD5 + " =?= " + m.getMD5(m.elements));
            Log.Trace("      date=\t" + m.date + "\tMD5=" + m.MD5 + "\telements.Count=" + m.elements.Count);
            Log.Trace("price date=\t" + m.pricingDate + "\tMD5=" + m.pricingMD5 + "\ttotal price" + m.total_price);
            Log.exit();
        }
コード例 #4
0
ファイル: UT_Component.cs プロジェクト: PavelKhrapkin/TSmatch
 public void UT_comp_InSh_Native()
 {
     boot.Init();
     // test 1 Native: Балка 35 Ш2 СТО АСЧМ 20-93 ст3сп/пс5
     model = model.sr.SetModel(boot);
     foreach(var gr in model.elmGroups)
     {
         if(!gr.prf.Contains("i") || !gr.prf.Contains("ш") )continue;
         string rText = string.Empty;
         foreach(var r in model.Rules)
         {
             if (r.sSupl != "ЛенСпецСталь" || r.sCS != "Двутавр") continue;
             rText = r.Text;
             r.Init();
             Assert.IsTrue(r.CompSet.Components.Count > 5);
             var m = new Mtch(gr, r);
             Assert.AreEqual("Match", m.ok.ToString());
         }
     }
     exit: FileOp.AppQuit();
 }
コード例 #5
0
ファイル: ModHandler.cs プロジェクト: PavelKhrapkin/TSmatch
        public void Handler(Mod mod)
        {
            Log.set("MH.Handler(\"" + mod.name + "\")");
            getGroups(mod.elements);
            log.Info("- total elements = " + mod.elements.Count + " in " + mod.elmGroups.Count + "groups");
            foreach (var gr in mod.elmGroups)
            {
                bool b = false;
                foreach (var rule in mod.Rules)
                {
                    Mtch _match = new Mtch(gr, rule);
                    if (_match.ok == Mtch.OK.Match) { mod.matches.Add(_match); b = true; break; }
                }
                if (!b) log.Info("No Match Group. mat= " + gr.mat + "\tprf=" + gr.prf);
            }
            int cnt = 0;
            var elms = new Dictionary<string, Elm>();
            elms = mod.elements.ToDictionary(elm => elm.guid);
            foreach (var match in mod.matches)
            {
                match.group.SupplierName = match.rule.Supplier.name;
                double price_per_t = match.group.totalPrice / match.group.totalVolume;
                foreach (var guid in match.group.guids)
                {
                    elms[guid].price = price_per_t * elms[guid].volume;
                    cnt++;
                }
            }

            log.Info("- found " + mod.matches.Count + " price matches for " + cnt + " elements");
            elements = elms.Values.ToList();

            Log.Trace("<MH>Rules.Count=", mod.Rules.Count);
            Log.Trace("<MH>Price match for ", mod.matches.Count, " / ", mod.elmGroups.Count);
            Log.exit();
        }
コード例 #6
0
ファイル: ModHandler.cs プロジェクト: PavelKhrapkin/TSmatch
 /// <summary>
 /// Hndl(model) - find matching Components for model and total_price
 /// </summary>
 /// <param name="mod">model to be handled</param>
 /// <returns>List of found matches</returns>
 public List<Mtch> Hndl(Mod mod)
 {
     mod.elmGroups = getGrps(mod.elements);
     // find matching Components with Rules by Match 
     foreach (var gr in mod.elmGroups)
     {
         bool b = false;
         foreach (var rule in mod.Rules)
         {
             Mtch _match = new Mtch(gr, rule);
             if (_match.ok == Mtch.OK.Match)
             {
                 mod.matches.Add(_match);
                 gr.SupplierName = _match.rule.Supplier.name;
                 b = true; break;
             }
         }
         if (!b) log.Info("No Match Group. mat= " + gr.mat + "\tprf=" + gr.prf);
     }
     // calculate prices for matches      
     mod.total_price = mod.elmGroups.Sum(x => x.totalPrice);
     log.Info("Model.Hndl set " + mod.matches.Count + " groups. Total price=" + mod.total_price + " rub");
     return mod.matches;
 }
コード例 #7
0
ファイル: Handler.cs プロジェクト: PavelKhrapkin/TSmatch
 public Mtch PriceGr(Mod mod, ElmGr gr)
 {
     Log.set("Handler.PriceGr");
     Mtch match = null;
     bool found=false;
     if (mod.Rules == null || mod.Rules.Count == 0) Msg.F("Handler__PriceGr Rules not Initialized");
     foreach(var rule in mod.Rules)
     {
         if (gr.SupplierName != string.Empty && gr.SupplierName != rule.sSupl) continue;
         match = new Mtch(gr, rule);
         if (match.ok == Mtch.OK.Match)
         {
             mod.matches.Add(match);
             gr.CompSetName = match.rule.sCS;
             gr.SupplierName = match.rule.sSupl;
             gr.compDescription = match.component.Str(Section.Section.SType.Description);
             found = true;
             break;
         }
     }
     if (!found) log.Info("No Match Group. mat= " + gr.mat + "\tprf=" + gr.prf);
     Log.exit();
     return match;
 }
コード例 #8
0
ファイル: UT_Handler.cs プロジェクト: PavelKhrapkin/TSmatch
        public void UT_Hndl()
        {
            //-- Assign: подготавливаем все необходимое для Hndl-
            //.. mod.elements и mod.elmGroups, инициируем Rules с загрузкой прайс-листов
            boot.Init();
            var sr = new _SR();

            mod          = sr.SetModel(boot);
            mod.elements = sr.Raw(mod);
            List <Elm> elmCopy = new List <Elm>();

            foreach (Elm elm in mod.elements)
            {
                elmCopy.Add(elm);
            }
            for (int i = 0; i < elmCopy.Count; i++)
            {
                Assert.AreEqual(elmCopy[i], mod.elements[i]);
            }
            int    cnt = mod.elements.Count;
            string MD5 = mod.getMD5(mod.elements);

            Assert.IsTrue(cnt > 0);
            string cMD5 = mod.getMD5(elmCopy);

            Assert.AreEqual(cMD5, MD5);
            if (mod.Rules == null || mod.Rules.Count == 0)
            {
                sr._GetSavedRules(mod);
            }
            var  mh   = new MH();
            Mtch mtsh = new Mtch(mod);

            mh.Hndl(ref mod);

            // проверка, что elements не испортились
            foreach (var gr in mod.elmGroups)
            {
                cnt -= gr.guids.Count();
            }
            Assert.AreEqual(0, cnt);
            Assert.AreEqual(mod.elements.Count, elmCopy.Count);
            for (int i = 0; i < elmCopy.Count; i++)
            {
                Assert.AreEqual(elmCopy[i], mod.elements[i]);
            }
            string newMD5  = mod.getMD5(mod.elements);
            string copyMD5 = mod.getMD5(elmCopy);

            Assert.AreEqual(mod.getMD5(mod.elements), MD5);

            // проверка наличия compDescription, sCS, sSupl и totalPrice в группах
            foreach (var gr in mod.elmGroups)
            {
                if (gr.totalPrice == 0)
                {
                    continue;
                }
                Assert.IsTrue(gr.compDescription.Length > 0);
                Assert.IsTrue(gr.SupplierName.Length > 0);
                Assert.IsTrue(gr.CompSetName.Length > 0);
            }

            //Hndl performance test -- 180 sec for 100 cycles ОНХП модель 1124 элемента
            //                      -- 20,4 sec 1 cycle модель "Навес над трибунами" 7128 э-тов
            int      nLoops = 1;
            DateTime t0     = DateTime.Now;

            for (int i = 0; i < nLoops; i++)
            {
                mh.Hndl(ref mod);
            }
            TimeSpan ts      = DateTime.Now - t0;
            var      secHndl = ts.TotalSeconds / nLoops;

            Assert.IsTrue(secHndl > 0.0);

            FileOp.AppQuit();
        }
コード例 #9
0
ファイル: UT_Component.cs プロジェクト: PavelKhrapkin/TSmatch
        public void UT_comp_PL_Native()
        {
            boot.Init();
            // test 1 Native: берем группу, правила и компонент - пластину PL8 из модели
            model = model.sr.SetModel(boot);
            if (model.name != "Chasovnya+lepestok") goto exit;
            gr = model.elmGroups[23];
            Assert.AreEqual("—8", gr.prf);
            rule = new Rule.Rule(6);
            Assert.AreEqual(58, rule.text.Length);
            rule.Init();
            Assert.AreEqual(93, rule.CompSet.Components.Count);
            comp = rule.CompSet.Components[60];
            Assert.AreEqual("С245", comp.Str(SType.Material));
            Assert.AreEqual("PL8x100", comp.Str(SType.Profile));

            bool b = comp.isMatch(gr, rule);
            Assert.IsTrue(b);

            //test 2 Native: обрабатываем все группы, но проверяем только нужную - PL8
            Mtch _mtch = null;
            foreach (var g in model.elmGroups)
            {
                _mtch = new Mtch(g, rule);
                if (g.prf != "—8") continue;
                Assert.AreEqual(Mtch.OK.Match, _mtch.ok);
            }

            //test 3 Native: загружаем несколько Правил
            model.Rules.Clear();
            rule = new Rule.Rule(5);
            rule.Init();
            model.Rules.Add(rule);
            rule = new Rule.Rule(6);
            rule.Init();
            model.Rules.Add(rule);
            _mtch = null;
            Mtch found_mtch = null;
            foreach (var g in model.elmGroups)
            {
                foreach (var r in model.Rules)
                {
                    _mtch = new Mtch(g, r);
                    if (g.prf != "—8" || !r.text.Contains("—")) continue;
                    Assert.AreEqual(Mtch.OK.Match, _mtch.ok);
                    found_mtch = _mtch;
                    break;
                }
            }
            Assert.AreEqual("Полоса", found_mtch.rule.sCS);

            //test 4 Native with Handle, init all rules
            model.Rules.Clear(); model.matches.Clear();
            Docs rRule = Docs.getDoc("Rules", fatal: false, create_if_notexist: false);
            for (int i = 4; i < rRule.il; i++)
            {
                rule = new Rule.Rule(i);
                rule.Init();
                model.Rules.Add(rule);
            }
            model.mh.Hndl(ref model);
            foreach (var m in model.matches)
            {
                if (m.group.prf != "—8") continue;
                Assert.AreEqual(Mtch.OK.Match, m.ok);
                Assert.AreEqual("Полоса", m.rule.sCS);
                Assert.AreEqual("СтальХолдинг", m.rule.sSupl);
            }

            //test 5 Native with Pricing
            model.Rules.Clear(); model.matches.Clear();
            model.mh.Pricing(ref model);
            if (model.name != "Chasovnya+lepestok") goto exit;
            bool c235found = false;
            //проверим, что это в самом деле правила из TSmatchINFO/Rules - есть С235
            foreach (var r in model.Rules)
            {
                if (!r.text.Contains("235")) continue;
                c235found = true;
                break;
            }
            Assert.IsTrue(c235found);
            //полоса PL8 находится в matches[23]
            Mtch found_match = model.matches[23];
            Assert.AreEqual(Mtch.OK.Match, found_match.ok);
            Assert.AreEqual("Полоса", found_match.rule.sCS);
            Assert.AreEqual("СтальХолдинг", found_match.rule.sSupl);

            exit: FileOp.AppQuit();
        }