Example #1
0
        /// <summary>
        /// Get TractIDs.
        /// </summary>
        public void FindTractIDs()
        {
            Model.TractIDCollection.Clear();
            Model.TractIDCollection = new ObservableCollection <TractAggregationDataModel>();
            string tractRootPath = Path.Combine(settingsService.RootPath, "TractDelineation", "Tracts");

            if (Directory.Exists(tractRootPath))
            {
                DirectoryInfo di = new DirectoryInfo(tractRootPath);
                foreach (DirectoryInfo dir in di.GetDirectories())
                {
                    if (!dir.Name.StartsWith("AGG"))
                    {
                        string tractCsvPath = Path.Combine(settingsService.RootPath, "UndiscDep", dir.Name, "SelectedResult", "TractPmf.csv");
                        if (!dir.GetFiles().Any(f => f.Name == "TractsAggregated.csv") && File.Exists(tractCsvPath))
                        {
                            TractAggregationDataModel item = new TractAggregationDataModel
                            {
                                TractName   = dir.Name,
                                ChooseTract = false
                            };
                            Model.TractIDCollection.Add(item);  // Get TractID by getting the name of the directory.
                        }
                    }
                }
            }
            else
            {
                Directory.CreateDirectory(Path.Combine(settingsService.RootPath, "TractDelineation", "Tracts"));
            }
        }
Example #2
0
 /// <summary>
 /// Combine tracts to dictionary.
 /// </summary>
 private void CombineTracts()
 {
     logger.Info("-->{0}", this.GetType().Name);
     Model.TractPairRow.Clear();
     // Collection of rows that contain columns of tracts.
     Model.TractPairRow = new ObservableCollection <TractAggregationDataModel>();
     try
     {
         if (Model.TractIDCollection.Count > 1)
         {
             TractAggregationDataModel row;
             TractAggregationDataModel column;
             foreach (var item in Model.TractIDCollection)
             {
                 // Enumerator makes sure that tract pair will not be added twice.
                 using (IEnumerator <TractAggregationDataModel> tractIDEnumerator = Model.TractIDCollection.GetEnumerator())
                 {
                     while (tractIDEnumerator.Current != item)
                     {
                         tractIDEnumerator.MoveNext();
                     }
                     if (item.ChooseTract == true)
                     {
                         row = new TractAggregationDataModel();  // New row where columns will be added
                         row.TractPairColumn = new ObservableCollection <TractAggregationDataModel>();
                         string tractName = tractIDEnumerator.Current.TractName;
                         // Adds the first index.
                         if (tractIDEnumerator.Current.ChooseTract == true)
                         {
                             column = new TractAggregationDataModel();  // New column where tract pair information will be added.
                             column.TractPairColumn.Clear();
                             //column.TractName = item.TractName + " - " + tractIDEnumerator.Current.TractName;
                             column.TractName = "";
                             column.IsVisible = true;
                             if (item.TractName == tractIDEnumerator.Current.TractName)
                             {
                                 column.TractText = "1";
                             }
                             else
                             {
                                 column.IsCorrelated = true;
                             }
                             row.TractPairColumn.Add(column);
                         }
                         // Adds other indexes.
                         while (tractIDEnumerator.MoveNext() != false)
                         {
                             if (tractIDEnumerator.Current.ChooseTract == true)
                             {
                                 TractAggregationDataModel newColumn = new TractAggregationDataModel();  // New column where tract pair information will be added.
                                 //newColumn.TractName = item.TractName + " - " + tractIDEnumerator.Current.TractName;
                                 newColumn.TractName = "";
                                 newColumn.IsVisible = true;
                                 if (item.TractName == tractIDEnumerator.Current.TractName)
                                 {
                                     newColumn.TractText = "1";
                                 }
                                 else
                                 {
                                     newColumn.IsCorrelated = true;
                                 }
                                 row.TractPairColumn.Add(newColumn);
                             }
                         }
                         column           = new TractAggregationDataModel(); // New column where tract pair information will be added.
                         column.TractName = tractName;
                         column.IsTitle   = true;                            // This column is used as a title for the row where it is located.
                         column.IsVisible = true;
                         row.TractPairColumn.Add(column);
                         // Reverses the order so the matrix can turned upside down.
                         for (int i = 0; i < row.TractPairColumn.Count; i++)
                         {
                             row.TractPairColumn.Move(row.TractPairColumn.Count - 1, i);
                         }
                         Model.TractPairRow.Add(row);
                     }
                 }
             }
             row = new TractAggregationDataModel();
             Model.TractPairRow.Add(row);
             for (int i = 0; i < Model.TractPairRow.Count; i++)
             {
                 Model.TractPairRow.Move(Model.TractPairRow.Count - 1, i);
             }
             column = new TractAggregationDataModel();
             //column.TractName = "test";
             column.IsVisible = false;  // Makes the first column from first row hidden.
             Model.TractPairRow[0].TractPairColumn.Add(column);
             var reversedTractCollection = new ObservableCollection <TractAggregationDataModel>(Model.TractIDCollection.Reverse());
             // Sets the column title by putting column names for the first row.
             foreach (var item in reversedTractCollection)
             {
                 if (item.ChooseTract == true)
                 {
                     column           = new TractAggregationDataModel();
                     column.TractName = item.TractName;
                     column.IsTitle   = true;
                     column.IsVisible = true; // Makes the other columns visible.
                     Model.TractPairRow[0].TractPairColumn.Add(column);
                 }
             }
         }
         else
         {
             dialogService.ShowNotification("Choose more than one tract.", "Error");
         }
     }
     catch (Exception ex)
     {
         logger.Error(ex, "Failed to create matrice of tract pairs.");
         dialogService.ShowNotification("Failed to create matrice of tract pairs.", "Error");
         viewModelLocator.SettingsViewModel.WriteLogText("Failed to create matrice of tract pairs.", "Error");
     }
 }