예제 #1
0
        public void AddItem(CartItemViewModel item)
        {
            CartItemViewModel unit = ItemsSet.FirstOrDefault(i => i.ProductID == item.ProductID);

            if (unit == null)
            {
                ItemsSet.Add(item);
            }
            else
            {
                foreach (var element in ItemsSet.Where(i => i.ProductID == item.ProductID))
                {
                    element.Quantity = item.Quantity;
                }
            }
        }
        public HashSet <ItemsSet <String> > FPGrow(int epsilon, List <String> previos = null)
        {
            //si previos es default
            if (previos == null)
            {
                //instancia a previos
                previos = new List <string>();
            }

            //crea el conjuto de respuesta
            HashSet <ItemsSet <String> > respuesta = new HashSet <ItemsSet <string> >();

            //para cada item en el arbol
            foreach (KeyValuePair <string, FPNode> entry in headersTable)
            {
                //obtiene su nodo inicial
                FPNode node = entry.Value;
                //crea un nuevo set de items
                ItemsSet <String> items = new ItemsSet <string>();
                //agrega los los items previos que se han hecho y an llevado a esta instancia de arbol
                items.UnionWith(previos);
                //agrega el nodo que se esta evaluando
                items.Add(node.Contenido);
                //agrega a la respueta el set de items
                respuesta.Add(items);
                //crea una copia de los previos
                List <String> nueva = Extenciones.Clone <String>(previos);
                //agrega el actual
                nueva.Add(node.Contenido);
                //genera el arbol condicional para el item actual
                FPTree conditional = GetConditional(node, epsilon);
                //llama recursivamente sobre el arbol condicional y une las respuestas
                respuesta.UnionWith(conditional.FPGrow(epsilon, nueva));
            }
            return(respuesta);
        }
예제 #3
0
        public HashSet <Dependencia> FunctionalDependeciesWithFPGrow(double confianza = 0.2)
        {
            if (confianza < 0 || confianza > 1)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (tree == null)
            {
                throw new Exception("tree is null");
            }
            HashSet <ItemsSet <String> > result = tree.FPGrow(epsilon);
            HashSet <Dependencia>        posiblesDependencias = new HashSet <Dependencia>();

            foreach (ItemsSet <String> i in result)
            {
                if (i.Count > 1)
                {
                    posiblesDependencias.UnionWith(generarDependencias(i));
                }
            }

            HashSet <Dependencia> dependencias       = tree.TestDependenciasV2(posiblesDependencias, confianza);
            HashSet <Dependencia> dependenciasNombre = new HashSet <Dependencia>();

            Dictionary <string, string> dic = new Dictionary <string, string>();
            StreamReader lector             = new StreamReader("productos.txt");
            string       linea = lector.ReadLine();

            while (linea != null)
            {
                string[] array = linea.Split('|');
                dic.Add(array[0], array[1].Substring(1, array[1].Length - 1));
                linea = lector.ReadLine();
            }

            foreach (Dependencia d in dependencias)
            {
                ItemsSet <string> implicantes       = d.Implicante;
                ItemsSet <String> implicantesNombre = new ItemsSet <string>();
                foreach (string i in implicantes)
                {
                    string value = "";
                    dic.TryGetValue(i, out value);
                    implicantesNombre.Add(value);
                }

                ItemsSet <string> implicadosNombre = new ItemsSet <string>();
                ItemsSet <string> implicados       = d.Implicados;
                foreach (string idos in implicados)
                {
                    string value = "";
                    dic.TryGetValue(idos, out value);
                    implicadosNombre.Add(value);
                }
                Dependencia depen = new Dependencia(implicantesNombre, implicadosNombre);
                dependenciasNombre.Add(depen);
            }



            //return dependencias;

            //StringBuilder sb = new StringBuilder();
            //using (StreamWriter writer = new StreamWriter(ruta))
            //{
            //    foreach (Dependencia d in dependencias)
            //    {
            //        foreach (String s in d.Implicante)
            //        {
            //            sb.Append(s);
            //            sb.Append(itemSeparator);
            //        }
            //        sb.Remove(sb.Length - 1, 1);
            //        sb.Append(dependencySeparator);
            //        foreach (String s in d.Implicados)
            //        {
            //            sb.Append(s);
            //            sb.Append(itemSeparator);
            //        }
            //        sb.Remove(sb.Length - 1, 1);
            //        writer.WriteLine(sb.ToString());
            //        sb.Clear();
            //    }
            //}
            return(dependenciasNombre);
        }
예제 #4
0
파일: ItemsGameParser.cs 프로젝트: NPsim/P3
        private void BuildItems()
        {
            List <VDFNode> tfItems = this.ItemsGame.Head.GetValueFromKey("items");

            foreach (VDFNode entry in tfItems)
            {
                string itemName = entry.GetValueFromKey("name");
                int    itemID   = itemName == "default" ? -1 : int.Parse(entry.Key);            // The only item without a valid int ID is "default"
                Item   item     = new Item(itemID, itemName);

                // Import Prefabs
                if (entry.KeyExists("prefab"))
                {
                    string   prefabValue = entry.GetValueFromKey("prefab");
                    string[] inheritList = prefabValue.Split(' ');
                    foreach (string prefabName in inheritList)
                    {
                        item.ImportPrefab(this.PrefabsTable, prefabName);
                    }
                }

                // Localization
                if (entry.KeyExists("item_name"))
                {
                    item.LocalizedName = entry.GetValueFromKey("item_name");
                }
                if (entry.KeyExists("item_description"))
                {
                    item.LocalizedDescription = entry.GetValueFromKey("item_description");
                }

                // Attributes
                if (entry.KeyExists("attributes"))                   // Standard attributes
                {
                    List <VDFNode> attributesList = entry.GetValueFromKey("attributes");
                    foreach (VDFNode attributeNode in attributesList)
                    {
                        item.AddAttribute(attributeNode.Key, attributeNode.GetValueFromKey("value"));
                    }
                }
                if (entry.KeyExists("static_attrs"))                   // Static attributes
                {
                    List <VDFNode> staticAttributesList = entry.GetValueFromKey("static_attrs");
                    foreach (VDFNode attributeNode in staticAttributesList)
                    {
                        item.AddAttribute(attributeNode.Key, attributeNode.Value);
                    }
                }

                // Slots
                if (entry.KeyExists("item_slot") && ((string)entry.GetValueFromKey("item_slot")).Length > 0)                   // Default slot definition
                {
                    InventorySlot inventorySlot = InventorySlotHelper.Cast(entry.GetValueFromKey("item_slot"));

                    item.DefaultSlot = inventorySlot;
                }
                if (entry.KeyExists("used_by_classes"))                   // Direct slot definition
                {
                    List <VDFNode> classesList = entry.GetValueFromKey("used_by_classes");
                    foreach (VDFNode classNode in classesList)
                    {
                        PlayerClass   classType = PlayerClassHelper.Cast(classNode.Key);
                        InventorySlot inventorySlot;
                        if (classNode.Value == "1")
                        {
                            inventorySlot = InventorySlot.DEFAULT;
                        }
                        else
                        {
                            inventorySlot = InventorySlotHelper.Cast(classNode.Value);
                        }
                        item.AddSlot(classType, inventorySlot);
                    }
                }

                // Equip region
                if (entry.KeyExists("equip_region"))
                {
                    if (entry.GetNode("equip_region").Value is string)                       // Single region
                    {
                        item.AddEquipRegion(entry.GetValueFromKey("equip_region"));
                    }
                    else if (entry.GetNode("equip_region").Value is List <VDFNode> )                     // Ambiguous multiple region (Valve error?)
                    {
                        List <VDFNode> regions = entry.GetValueFromKey("equip_region");
                        foreach (VDFNode equipRegion in regions)
                        {
                            if (equipRegion.Value == "1")
                            {
                                item.AddEquipRegion(equipRegion.Key);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("item equip_region type not found");
                    }
                }
                if (entry.KeyExists("equip_regions"))                   // Multiple region
                {
                    List <VDFNode> regions = entry.GetValueFromKey("equip_regions");
                    foreach (VDFNode equipRegion in regions)
                    {
                        if (equipRegion.Value == "1")
                        {
                            item.AddEquipRegion(equipRegion.Key);
                        }
                    }
                }

                // Add to table
                ItemsSet.Add(item);
            }
        }