public Window1(DwgDocument dwgDocument) { InitializeComponent(); itemsSet = new ItemsSet(dwgDocument, pgrid); itemsSet.FillItemsTree(treeView); }
void OnEnable() { if (items == null) { items = (ItemsSet)target; } }
private void butCalcular_Click(object sender, RoutedEventArgs e) { string mostrarDependencias = ""; HashSet <Dependencia> dependencias = controladora.FunctionalDependeciesWithFPGrow(Double.Parse(txtConfianza.Text)); foreach (Dependencia d in dependencias) { string aux = ""; ItemsSet <string> implicantes = d.Implicante; foreach (string i in implicantes) { aux += i + ","; } aux = aux.Substring(0, aux.Length - 1); aux += " ---> "; ItemsSet <string> implicados = d.Implicados; foreach (string idos in implicados) { aux += idos + ","; } aux = aux.Substring(0, aux.Length - 1); mostrarDependencias += aux + "\n"; } txtDependencias.Text = mostrarDependencias; }
public Dependencia(IEnumerable <string> i, IEnumerable <string> j) { implicante = new ItemsSet <string>(); implicados = new ItemsSet <string>(); implicante.UnionWith(i); implicados.UnionWith(j); }
private void AgregarSoporte(List <String> lista, ItemsSet <String> set, Dictionary <ItemsSet <String>, int> soportes) { String start = ""; foreach (String s in lista) { if (set.Contains(s)) { start = s; break; } } FPNode nodo = headersTable[start]; int soporteSet = 0; while (nodo != null) { FPNode temp = nodo; ItemsSet <String> copy = new ItemsSet <string>(); copy.Union(set); while (temp.Contenido != null) { copy.Remove(temp.Contenido); temp = temp.Padre; } if (!copy.Any()) { soporteSet += nodo.Conteo; } nodo = nodo.Siguiente; } soportes.Add(set, soporteSet); }
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; } } }
private IEnumerable <Dependencia> generarDependencias(ItemsSet <string> items) { List <Dependencia> respuesta = new List <Dependencia>(); IEnumerable <IEnumerable <String> > partes = GetPowerSet <String>(items.ToList()); foreach (IEnumerable <String> i in partes) { foreach (IEnumerable <String> j in partes) { if (i.Any() && j.Any() && !i.Intersect(j).Any()) { respuesta.Add(new Dependencia(i, j)); } } } return(respuesta); }
public HashSet <Dependencia> TestDependencias(HashSet <Dependencia> posiblesDependencias, double confianza = 0.2) { HashSet <Dependencia> respuesta = new HashSet <Dependencia>(); Dictionary <String, Int32> conteo = new Dictionary <string, int>(); foreach (FPNode node in headersTable.Values) { FPNode n = node; int i = 0; while (n != null) { i += node.Conteo; n = n.Siguiente; } conteo.Add(node.Contenido, i); } List <String> lista = conteo.ToList().OrderBy(c => c.Value).Select(c => c.Key).ToList(); int total = conteo.Sum(c => c.Value); conteo = null; Dictionary <ItemsSet <String>, int> soportes = new Dictionary <ItemsSet <string>, int>(); foreach (Dependencia dependencia in posiblesDependencias) { ItemsSet <String> dividendo = new ItemsSet <string>(); dividendo.UnionWith(dependencia.Implicante.Union(dependencia.Implicados)); if (!soportes.ContainsKey(dividendo)) { AgregarSoporte(lista, dividendo, soportes); } ItemsSet <String> divisor = new ItemsSet <string>(); divisor.UnionWith(dependencia.Implicante); if (!soportes.ContainsKey(divisor)) { AgregarSoporte(lista, divisor, soportes); } if ((soportes[dividendo] + 0.0) / (soportes[divisor] + 0.0) >= confianza) { respuesta.Add(dependencia); } } return(respuesta); }
public HashSet <Dependencia> TestDependenciasV2(HashSet <Dependencia> posiblesDependencias, double confianza = 0.2) { Dictionary <ItemsSet <String>, double> memorization = new Dictionary <ItemsSet <String>, double>(); HashSet <Dependencia> respuesta = new HashSet <Dependencia>(); foreach (Dependencia posible in posiblesDependencias) { double denonimador = 0; if (memorization.ContainsKey(posible.Implicante)) { denonimador = memorization[posible.Implicante]; } else { foreach (FPNode node in root.Hijos.Values) { denonimador += GetConteo(posible.Implicante, node); } memorization.Add(posible.Implicante, denonimador); } ItemsSet <String> numeradorSet = new ItemsSet <string>(posible.Implicados.Union(posible.Implicante)); double numerador = 0; if (memorization.ContainsKey(numeradorSet)) { numerador = memorization[numeradorSet]; } else { foreach (FPNode node in root.Hijos.Values) { numerador += GetConteo(numeradorSet, node); } memorization.Add(numeradorSet, numerador); } if ((numerador / denonimador) >= confianza) { respuesta.Add(posible); } } return(respuesta); }
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); }
public ActionResult ItemSet(long?matchId = null, int?teamId = null, int?championId = null) { if (!matchId.HasValue || !teamId.HasValue || !championId.HasValue) { return(RedirectToAction("Index")); } var region = getRegionFromCookie(); RestClient client = new RestClient("https://" + region + ".api.pvp.net"); // get match var request = new RestRequest("/api/lol/" + region + "/v2.2/match/" + matchId.Value, Method.GET); request.AddParameter("api_key", apiKey); request.AddParameter("includeTimeline", "true"); IRestResponse <Match> response = client.Execute <Match>(request); if (response.Data == null || response.StatusCode != HttpStatusCode.OK) { return(RedirectToAction("Index", new { error = "Could not load match details." })); } // get participientId (the player which events from timeline should be considered later) var match = response.Data; var participientId = match.GetParticipientId(championId.Value, teamId.Value); // get all events from timeline about buying / selling items if (!participientId.HasValue) { return(RedirectToAction("Index", new { error = "Could not find player in match." })); } var items = match.timeline.GetItemsEvents(participientId.Value); var itemsSet = new ItemsSet(items); string fileName = "itemsSet.json"; // get name of champion (for better file name) RestClient globalClient = new RestClient("https://global.api.pvp.net"); var championsRequest = new RestRequest("/api/lol/static-data/" + region + "/v1.2/champion/" + championId.Value, Method.GET); championsRequest.AddParameter("api_key", apiKey); IRestResponse <Champion> championResponse = globalClient.Execute <Champion>(championsRequest); if (championResponse.Data != null && championResponse.StatusCode == HttpStatusCode.OK) { itemsSet.title = championResponse.Data.name + " - Vel'Koz Archive"; fileName = championResponse.Data.name + "ItemsSet.json"; } var contentType = "application/json"; var content = JsonConvert.SerializeObject(itemsSet); var bytes = Encoding.UTF8.GetBytes(content); var result = new FileContentResult(bytes, contentType); result.FileDownloadName = fileName; return(result); }
public void ClearCart() { ItemsSet.Clear(); }
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); }
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); } }