private void GenerateRecsForNodeArray() { List <Node> nodes = new List <Node>(); MemoryTree.ToList(nodes); nodes = nodes.Except(CurrentUser.NotShow).Except(CurrentUser.Favourite).ToList(); foreach (Node node in nodes) { node.Distance = 0.0; foreach (Node n in CurrentUser.Favourite) { DistanceCalculator calculator = new DistanceCalculator(node, n); node.Distance += calculator.CalculateDistance((MeasureType)MeasureTypeIndex); } node.Distance /= (double)CurrentUser.Favourite.Count(); } nodes.Sort(delegate(Node node1, Node node2) { if (node1 == null && node2 == null) { return(0); } if (node1 == null) { return(-1); } if (node2 == null) { return(1); } if (node1.Distance == node2.Distance) { return(0); } if (node1.Distance > node2.Distance) { return(1); } return(-1); }); Recommendations = new ObservableCollection <Node>(nodes.Take(UsersCount)); AddRecommendationsToItems(); }
private IEnumerable <Node> GenerateRecsForNodeArray() { var nodes = new List <Node>(); MemoryTree.ToList(nodes); nodes = nodes.Except(CurrentUser.NotShow).Except(CurrentUser.Favourite).ToList(); foreach (var node in nodes) { node.Distance = 0.0; foreach (var n in CurrentUser.Favourite) { var calculator = new DistanceCalculator(node, n); node.Distance += calculator.CalculateDistance((MeasureType)MeasureTypeIndex); } node.Distance /= (double)CurrentUser.Favourite.Count(); } nodes.Sort(delegate(Node node1, Node node2) { if (node1 == null && node2 == null) { return(0); } if (node1 == null) { return(-1); } if (node2 == null) { return(1); } if (node1.Distance == node2.Distance) { return(0); } if (node1.Distance > node2.Distance) { return(1); } return(-1); }); return(nodes); }
private void GenerateRecsForSingleNode(Node node) { List <Node> nodes = new List <Node>(); MemoryTree.ToList(nodes); nodes = nodes.Except(CurrentUser.NotShow).Except(new[] { node }).ToList(); foreach (Node n in nodes) { DistanceCalculator calculator = new DistanceCalculator(node, n); n.Distance = calculator.CalculateDistance((MeasureType)MeasureTypeIndex); } nodes.Sort(delegate(Node node1, Node node2) { if (node1 == null && node2 == null) { return(0); } if (node1 == null) { return(-1); } if (node2 == null) { return(1); } if (node1.Distance == node2.Distance) { return(0); } if (node1.Distance > node2.Distance) { return(1); } return(-1); }); Recommendations = new ObservableCollection <Node>(nodes.Take(RecsLength)); AddRecommendationsToItems(); }
private IEnumerable <Node> GenerateRecsForSingleNode(Node node) { var nodes = new List <Node>(); MemoryTree.ToList(nodes); nodes = nodes.Except(CurrentUser.NotShow).Except(new[] { node }).ToList(); foreach (var n in nodes) { var calculator = new DistanceCalculator(node, n); n.Distance = calculator.CalculateDistance((MeasureType)MeasureTypeIndex); } nodes.Sort(delegate(Node node1, Node node2) { if (node1 == null && node2 == null) { return(0); } if (node1 == null) { return(-1); } if (node2 == null) { return(1); } if (node1.Distance == node2.Distance) { return(0); } if (node1.Distance > node2.Distance) { return(1); } return(-1); }); return(nodes); }
/// <summary> Загрузка дерева из JSON-файла. </summary> private void LoadTreeFromFile() { try { var fileContent = string.IsNullOrWhiteSpace(Filename) ? Properties.Resources.tree : File.ReadAllText(Filename); MemoryTree = JsonSerializer.Deserialize <Tree>(fileContent); MemoryTree.SetParents(); var root = new TreeViewItem(); root.Header = "Дерево"; MemoryTree.AddToTreeView(root, new ICommand[] { AddToFavouriteCommand, AddToNotShowCommand }); var items = new ObservableCollection <TreeViewItem>(); items.Add(root); MemoryTreeViewItems = items; } catch (ArgumentException) { MessageBox.Show($"Ошибка при загрузке дерева: неверный путь к файлу.\n{Filename}", "Ошибка"); } catch (DirectoryNotFoundException) { MessageBox.Show($"Ошибка при загрузке дерева: указанный путь не существует.\n{Filename}", "Ошибка"); } catch (JsonException) { MessageBox.Show("Ошибка при загрузке дерева: неверный формат данных.", "Ошибка"); } catch (Exception e) { while (e.InnerException != null) { e = e.InnerException; } MessageBox.Show($"Ошибка при загрузке дерева: {e.Message}", "Ошибка"); } }