Exemplo n.º 1
0
        // Fill in missing coordinates in Table 1 using district information from Table 2
        public void AddDistrictCoords(CsvTable csv1, CsvTable csv2)
        {
            if (csv1 == null || csv2 == null)
            {
                return;
            }

            for (int row1 = 0; row1 < csv1.Rows; row1++)
            {
                if (csv1.StringAt("Match", row1) == "x")
                {
                    for (int row2 = 0; row2 < csv2.Rows; row2++)
                    {
                        if (csv1.StringAt("Admin 1", row1) == csv2.StringAt("Admin 1", row2) &&
                            csv1.StringAt("Admin 2", row1) == csv2.StringAt("Admin 2", row2))
                        {
                            string lat2  = csv2.StringAt("Latitude", row2);
                            string long2 = csv2.StringAt("Longitude", row2);
                            csv1.Assign("Latitude", row1, lat2);
                            csv1.Assign("Longitude", row1, long2);
                            csv1.Assign("Match", row1, "District");
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private CsvTable LoadCsvTable()
        {
            string   filePath = string.Empty;
            CsvTable csvTable = new CsvTable(country);

            using (OpenFileDialog openFileDialog = new OpenFileDialog()) {
                openFileDialog.Filter           = "csv files (*.csv)|*.csv|All files (*.*)|*.*";
                openFileDialog.FilterIndex      = 1;
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    filePath = openFileDialog.FileName;

                    var fileStream = openFileDialog.OpenFile();
                    try {
                        csvTable.Load(filePath);
                        csvTable.FilePath = filePath;
                    }
                    catch (Exception exception) {
                        MessageBox.Show(exception.Message);
                    };
                }

                return(csvTable);
            }
        }
Exemplo n.º 3
0
        public AdminTree(CsvTable table, string level0)
        {
            root = new AdminTreeNode(level0);

            for (int row = 0; row < table.Rows; row++)
            {
                List <string> adminPath = table.GetAdminPath(row);
                root.AddAdminPath(adminPath, 1);
            }
        }
Exemplo n.º 4
0
        private void InitializeApplication()
        {
            this.csvTable1 = new CsvTable(country);
            this.csvTable2 = new CsvTable(country);
            this.nameSet1  = new NameSet();
            this.nameSet2  = new NameSet();

            this.appOptions     = new ApplicationOptions();
            this.displayManager = new DisplayManager(this.textBox1, this.textBox2, this.textBox3, this.listBox1, this.treeView1, this.treeView2);

            this.dataCleaner     = new DataCleaner(this.displayManager);
            this.facilityManager = new FacilityManager(this.displayManager, this.appOptions);
        }
Exemplo n.º 5
0
        public void AddFacilityNodes(CsvTable table)
        {
            int col = table.LookupColumn("Facility");

            if (col == -1)
            {
                return;
            }
            for (int row = 0; row < table.Rows; row++)
            {
                List <string> adminPath = table.GetAdminPath(row);
                root.AddFacility(adminPath, 1, table.dataColumns[col].StringAt(row));
            }
        }
Exemplo n.º 6
0
 // Update columns: Add Lat/Long in table1 from table2 if they are not already present
 // An obvious flaw is we get into trouble with a facility named "x"
 private void UpdateColumns(int row1, CsvTable csv1, int row2, CsvTable csv2)
 {
     if (csv1.StringAt("Match", row1) == "x")
     {
         string uid2  = csv2.StringAt("UID", row2);
         string lat2  = csv2.StringAt("Latitude", row2);
         string long2 = csv2.StringAt("Longitude", row2);
         string fac2  = csv2.StringAt("Facility", row2);
         csv1.Assign("Link", row1, uid2);
         csv1.Assign("Match", row1, fac2);
         csv1.Assign("Latitude", row1, lat2);
         csv1.Assign("Longitude", row1, long2);
     }
 }
Exemplo n.º 7
0
        private void SaveCsv(CsvTable csvTable)
        {
            using (SaveFileDialog saveFileDialog = new SaveFileDialog()) {
                saveFileDialog.Filter           = "CSV files (*.csv)|*.csv|All files (*.*)|*.*";
                saveFileDialog.FilterIndex      = 1;
                saveFileDialog.RestoreDirectory = true;

                if (saveFileDialog.ShowDialog() == DialogResult.OK && this.csvTable2 != null)
                {
                    string   filePath    = saveFileDialog.FileName;
                    string[] outputTable = csvTable.CsvFile();
                    System.IO.File.WriteAllLines(filePath, outputTable);
                }
            }
        }
Exemplo n.º 8
0
        public void ApplyNameSubstitutions(NameSet ns, CsvTable csv, ListBox lb)
        {
            List <string> path       = ns.ExtractPath;
            string        columnName = "Admin " + path.Count;

            foreach (int i in lb.SelectedIndices)
            {
                string   str       = lb.Items[i].ToString();
                char[]   separator = new char[] { '\\' };
                string[] values    = str.Split(separator);
                string   oldValue  = values[0];
                string   newValue  = values[1];
                csv.Substitute(path, columnName, oldValue, newValue);
            }
        }
Exemplo n.º 9
0
        // *** File Management ***
        private void OnCsvOneLoad(object sender, EventArgs e)
        {
            this.csvTable1 = LoadCsvTable();
            if (this.csvTable1 != null)
            {
                this.csvTable1.MaxAdminLevels = 2;
                this.toolStripFileLabel1.Text = "CSV One: " + Utilities.TruncateString(this.csvTable1.FilePath, 70);

                this.admin1 = new AdminTree(this.csvTable1, country);
                if (this.appOptions.IncludeFacilities)
                {
                    this.admin1.AddFacilityNodes(this.csvTable1);
                }
                this.admin1.BuildTreeView(this.treeView1);
            }
        }
Exemplo n.º 10
0
        public void CapitalizeColumn(CsvTable csv, string columnName)
        {
            if (csv == null)
            {
                return;
            }
            int column = csv.LookupColumn(columnName);

            if (column == -1)
            {
                return;
            }

            csv.dataColumns[column].Capitalize();
            displayManager.DisplayTextFile(csv.dataColumns[column].UniqueElements(), 1000);
        }
Exemplo n.º 11
0
        private void OnLoadCsvTwo(object sender, EventArgs e)
        {
            this.csvTable2 = LoadCsvTable();
            if (this.csvTable2 != null)
            {
                this.csvTable2.MaxAdminLevels = 2;
                this.displayManager.DisplayTextFile(this.csvTable2.CsvFile());
                LoadHeaderComboBox(csvTable2.Headers);

                this.admin2 = new AdminTree(this.csvTable2, country);
                if (this.appOptions.IncludeFacilities)
                {
                    this.admin2.AddFacilityNodes(this.csvTable2);
                }

                this.admin2.BuildTreeView(this.treeView2);

                this.toolStripFileLabel2.Text = "CSV Two: " + Utilities.TruncateString(this.csvTable2.FilePath, 70);
            }
        }
Exemplo n.º 12
0
        public MatchResultSet MatchAllFacilities(CsvTable csv1, CsvTable csv2)
        {
            List <string> results = new List <string>();

            if (csv1 == null || csv2 == null)
            {
                return(null);
            }

            AdminTree admin1 = new AdminTree(csv1, applicationOptions.Country);

            admin1.AddFacilityNodes(csv1);
            AdminTree admin2 = new AdminTree(csv2, applicationOptions.Country);

            admin2.AddFacilityNodes(csv2);
            AdminIterator  adminNodes      = new AdminIterator(admin1);
            MatchResultSet resultsToReturn = new MatchResultSet();

            foreach (AdminTreeNode node in adminNodes)
            {
                Console.WriteLine(node.Name);
                if (node.IsFacility)
                {
                    string      path = node.Path;
                    NameSet     facilitiesToMatch = admin2.GetFacilities(path);
                    MatchResult result            = facilitiesToMatch.FindBestMatch(node.Name);

                    if (GoodMatch(node.Name, result))
                    {
                        string resultString = path + "\\" + result.ToString();
                        results.Add(resultString);
                        result.FullPath = path;
                        resultsToReturn.Add(result);
                    }
                }
            }

            displayManager.DisplayTextFile(results, 10000);
            return(resultsToReturn);
        }
Exemplo n.º 13
0
        // Compute the join of facilities based on the list of results.  This is coded to allow for duplicate facility names which are possible
        public void FacilityJoin(MatchResultSet matches, CsvTable csv1, CsvTable csv2)
        {
            if (matches == null || csv1 == null || csv2 == null)
            {
                return;
            }

            foreach (MatchResult match in matches.Results)
            {
                string     path     = match.FullPath;
                string     fac1     = match.Source;
                string     fac2     = match.Best;
                List <int> indices1 = csv1.LookupFacilities(path, fac1);
                List <int> indices2 = csv2.LookupFacilities(path, fac2);
                foreach (int row1 in indices1)
                {
                    foreach (int row2 in indices2)
                    {
                        UpdateColumns(row1, csv1, row2, csv2);
                    }
                }
            }
        }