Ejemplo n.º 1
0
        private Plankton IdentifyPlankton(string searchText)
        {
            Plankton      plankton = new Plankton();
            TaxonNameList result   = this.DyntaxaSession.searchTaxa(searchText);

            if (result.IsNotEmpty())
            {
                if (result.Count == 1)
                {
                    List <Plankton> resultList = this.DyntaxaSession.MakePlanktonList(result);

                    try
                    {
                        plankton = resultList[0];
                    }
                    catch (IndexOutOfRangeException e)
                    {
                        Console.WriteLine(e);
                    }
                }
                else
                {
                    plankton = this.GetUserSelectedPlankton(searchText, result);
                }
            }
            else
            {
                plankton = this.GetUserSelectedPlankton(searchText, result);
            }
            return(plankton);
        }
Ejemplo n.º 2
0
        private Plankton GetUserSelectedPlankton(string taxonSearch, TaxonNameList matchingResult)
        {
            var      viewModel = new DyntaxaMatchingDialogViewModel($"Found {matchingResult.Count} matches when searching for species: {taxonSearch}", taxonSearch, matchingResult);
            Plankton plankton  = null;
            bool?    result    = dialogService.ShowDialog(viewModel);

            if (result.HasValue)
            {
                if (result.Value)
                {
                    plankton = viewModel.SelectedPlankton;
                }
                else
                {
                    plankton = new Plankton(taxonSearch);
                    // Cancelled
                }
            }
            return(plankton);
        }
Ejemplo n.º 3
0
        public List <Plankton> MakePlanktonList(TaxonNameList search)
        {
            List <Plankton> planktonList = new List <Plankton>();

            foreach (TaxonName match in search)
            {
                Plankton       plankton      = new Plankton();
                ITaxonTreeNode taxonTreeNode = match.Taxon.GetParentTaxonTree(this.getUserContext(), true);
                while (taxonTreeNode != null)
                {
                    string categoryName = taxonTreeNode.Taxon.Category.Name;
                    if (!(plankton.TaxonDyntaxaIDIsInitialized))
                    {
                        plankton.TaxonDyntaxaID = taxonTreeNode.Taxon.Id;
                    }
                    switch (categoryName)
                    {
                    case "Variety":
                        plankton.TaxonVariety = taxonTreeNode.Taxon.ScientificName;
                        break;

                    case "Species":
                        plankton.TaxonSpecies = taxonTreeNode.Taxon.ScientificName;
                        break;

                    case "Genus":
                        plankton.TaxonGenus = taxonTreeNode.Taxon.ScientificName;
                        break;

                    case "Class":
                        plankton.TaxonClass = taxonTreeNode.Taxon.ScientificName;
                        break;

                    case "Family":
                        plankton.TaxonFamily = taxonTreeNode.Taxon.ScientificName;
                        break;

                    case "Order":
                        plankton.TaxonOrder = taxonTreeNode.Taxon.ScientificName;
                        break;

                    case "Phylum":
                        plankton.TaxonPhylum = taxonTreeNode.Taxon.ScientificName;
                        break;

                    case "Superphylum":
                        plankton.TaxonSuperPhylum = taxonTreeNode.Taxon.ScientificName;
                        break;

                    case "Organism group":
                        plankton.TaxonOrganismGroup = taxonTreeNode.Taxon.ScientificName;
                        break;

                    default: break;
                    }
                    if (taxonTreeNode.Parents == null)
                    {
                        break;
                    }
                    taxonTreeNode = taxonTreeNode.Parents[0];
                }
                planktonList.Add(plankton);
            }

            return(planktonList);
        }
Ejemplo n.º 4
0
        public void ExportSamples()
        {
            List <string> flags = new List <string> {
                "cf", "sp", "spp"
            };
            List <string> comments = new List <string> {
                "avl", "rund", "enstaka", "oval", "runda", "koloni",
                "i", "gele", "ovala", "filament", "gelé", "med", "flagell",
                "stjärnformad", "bandkoloni", "klyftform", "långsmal",
                "gissel", "copepodit", "adult", "naupliuslarv", "hanne",
                "bentisk"
            };
            List <string> ignores = new List <string> {
                "um"
            };

            List <Sample> exportedSamples = new List <Sample>();

            foreach (var inputSample in this.Samples)
            {
                using (var stream = File.Open(inputSample.FilePath, FileMode.Open, FileAccess.Read))
                {
                    // Auto-detect format, supports:
                    //  - Binary Excel files (2.0-2003 format; *.xls)
                    //  - OpenXml Excel files (2007 format; *.xlsx)
                    using (var reader = ExcelReaderFactory.CreateReader(stream))
                    {
                        do
                        {
                            int rowNum = 0;
                            while (reader.Read())
                            {
                                // Start of species declarations
                                if (rowNum >= 13)
                                {
                                    // End of species declarations
                                    if (reader.GetString(0) == null)
                                    {
                                        break;
                                    }
                                    // Species was counted
                                    if (reader.GetDouble(9) > 0)
                                    {
                                        string   taxonSpecies  = reader.GetString(0);
                                        Double   concentration = reader.GetDouble(12);
                                        Double   biovolume     = reader.GetDouble(13);
                                        Double   freshweight   = reader.GetDouble(14);
                                        Plankton plankton      = new Plankton(taxonSpecies, concentration, biovolume, freshweight);
                                        plankton.CleanTaxonSpecies(flags, comments, ignores);
                                        Plankton newPlankton = this.IdentifyPlankton(plankton.TaxonSpecies);
                                        newPlankton.TaxonConcentration = plankton.TaxonConcentration;
                                        newPlankton.TaxonBiovolume     = plankton.TaxonBiovolume;
                                        newPlankton.ConvertBiovolume(1e-9);
                                        newPlankton.TaxonFreshweight      = plankton.TaxonFreshweight;
                                        newPlankton.TaxonMinSize          = plankton.TaxonMinSize;
                                        newPlankton.TaxonMaxSize          = plankton.TaxonMaxSize;
                                        newPlankton.TaxonSpeciesFlags     = plankton.TaxonSpeciesFlags;
                                        newPlankton.TaxonSpeciesComments  = plankton.TaxonSpeciesComments;
                                        newPlankton.TaxonSpeciesIgnores   = plankton.TaxonSpeciesIgnores;
                                        newPlankton.TaxonSpeciesMinAndMax = plankton.TaxonSpeciesMinAndMax;
                                        inputSample.AddPlankton(newPlankton);
                                    }
                                }

                                rowNum++;
                            }
                        } while (reader.NextResult());
                    }

                    exportedSamples.Add(inputSample);
                }
            }
            foreach (Sample sample in exportedSamples)
            {
                string FileDir              = Path.GetDirectoryName(sample.FilePath);
                string FileName             = Path.GetFileNameWithoutExtension(sample.FileName);
                string FileExt              = Path.GetExtension(sample.FileName);
                string ExportedFullFileName = $"{FileName}_Exported{FileExt}";
                string ExportedFilePath     = Path.Combine(FileDir, ExportedFullFileName);

                var newFile = new FileInfo(ExportedFilePath);
                if (newFile.Exists)
                {
                    newFile.Delete();  // ensures we create a new workbook
                    newFile = new FileInfo(ExportedFilePath);
                }
                using (var package = new ExcelPackage(newFile))
                {
                    // Add a new worksheet to the empty workbook
                    ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Compilation");
                    //Add the headers

                    worksheet.Cells[1, 1].Value = "Origin";
                    worksheet.Cells[1, 2].Value = "Date";
                    worksheet.Cells[1, 3].Value = "Sample Number";
                    worksheet.Cells[1, 4].Value = "Phylum";
                    worksheet.Cells[1, 5].Value = "Class";
                    worksheet.Cells[1, 6].Value = "Order";
                    worksheet.Cells[1, 7].Value = "Species";
                    worksheet.Cells[1, 8].Value = "Flags";
                    if (this.phytoSampleIsChecked)
                    {
                        worksheet.Cells[1, 9].Value  = "Min Size";
                        worksheet.Cells[1, 10].Value = "Max Size";
                        worksheet.Cells[1, 11].Value = "Comments";
                        worksheet.Cells[1, 12].Value = "Dyntaxa ID";
                        worksheet.Cells[1, 13].Value = "Concentration";
                        worksheet.Cells[1, 14].Value = "Biovolume";
                        worksheet.Cells[1, 15].Value = "Analysis Method";
                        worksheet.Cells[1, 16].Value = "Analysis Laboratory";
                    }
                    else if (this.zooSampleIsChecked)
                    {
                        worksheet.Cells[1, 9].Value  = "Comments";
                        worksheet.Cells[1, 10].Value = "Dyntaxa ID";
                        worksheet.Cells[1, 11].Value = "Concentration";
                        worksheet.Cells[1, 12].Value = "Biovolume";
                        worksheet.Cells[1, 13].Value = "Analysis Method";
                        worksheet.Cells[1, 14].Value = "Analysis Laboratory";
                    }

                    for (int i = 0; i < sample.exportedSamples.Count; i++)
                    {
                        Plankton plankton = sample.exportedSamples[i];

                        if (string.IsNullOrEmpty(plankton.TaxonPhylum))
                        {
                            if (string.IsNullOrEmpty(plankton.TaxonSuperPhylum))
                            {
                                if (string.IsNullOrEmpty(plankton.TaxonOrganismGroup) == false)
                                {
                                    plankton.TaxonPhylum = plankton.TaxonOrganismGroup;
                                }
                            }
                            else
                            {
                                plankton.TaxonPhylum = plankton.TaxonSuperPhylum;
                            }
                        }

                        if (string.IsNullOrEmpty(plankton.TaxonSpecies))
                        {
                            if (string.IsNullOrEmpty(plankton.TaxonGenus))
                            {
                                if (string.IsNullOrEmpty(plankton.TaxonFamily))
                                {
                                    if (string.IsNullOrEmpty(plankton.TaxonOrder))
                                    {
                                        if (string.IsNullOrEmpty(plankton.TaxonClass))
                                        {
                                            if (string.IsNullOrEmpty(plankton.TaxonPhylum) == false)
                                            {
                                                plankton.TaxonSpecies = plankton.TaxonPhylum;
                                            }
                                        }
                                        else
                                        {
                                            plankton.TaxonSpecies = plankton.TaxonClass;
                                        }
                                    }
                                    else
                                    {
                                        plankton.TaxonSpecies = plankton.TaxonOrder;
                                    }
                                }
                                else
                                {
                                    plankton.TaxonSpecies = plankton.TaxonFamily;
                                }
                            }
                            else
                            {
                                plankton.TaxonSpecies = plankton.TaxonGenus;
                            }
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(plankton.TaxonVariety) == false)
                            {
                                plankton.TaxonSpecies = plankton.TaxonVariety;
                            }
                        }

                        int row = i + 2;

                        worksheet.Cells[row, 1].Value = sample.Origin;
                        worksheet.Cells[row, 2].Style.Numberformat.Format = "yyyy-mm-dd";
                        worksheet.Cells[row, 2].Formula = $"=DATE({sample.Date.Year},{sample.Date.Month},{sample.Date.Day})";
                        worksheet.Cells[row, 3].Value   = sample.SampleNumber;
                        worksheet.Cells[row, 4].Value   = plankton.TaxonPhylum;
                        worksheet.Cells[row, 5].Value   = plankton.TaxonClass;
                        worksheet.Cells[row, 6].Value   = plankton.TaxonOrder;
                        worksheet.Cells[row, 7].Value   = plankton.TaxonSpecies;
                        worksheet.Cells[row, 8].Value   = plankton.GetTaxonSpeciesFlagsAsString();
                        if (this.phytoSampleIsChecked)
                        {
                            if (plankton.TaxonMinSize == 0)
                            {
                                worksheet.Cells[row, 9].Value = "";
                            }
                            else
                            {
                                worksheet.Cells[row, 9].Value = plankton.TaxonMinSize;
                            }
                            if (plankton.TaxonMaxSize == 0)
                            {
                                worksheet.Cells[row, 10].Value = "";
                            }
                            else
                            {
                                worksheet.Cells[row, 10].Value = plankton.TaxonMaxSize;
                            }
                            worksheet.Cells[row, 11].Value = plankton.GetTaxonSpeciesCommentsAsString();
                            worksheet.Cells[row, 12].Value = plankton.TaxonDyntaxaID;
                            worksheet.Cells[row, 13].Value = plankton.TaxonConcentration;
                            worksheet.Cells[row, 14].Value = plankton.TaxonBiovolume;
                            worksheet.Cells[row, 15].Value = "SS-EN 15204:2006";
                            worksheet.Cells[row, 16].Value = "Erkenlaboratoriet";
                        }
                        else if (this.zooSampleIsChecked)
                        {
                            worksheet.Cells[row, 9].Value  = plankton.GetTaxonSpeciesCommentsAsString();
                            worksheet.Cells[row, 10].Value = plankton.TaxonDyntaxaID;
                            worksheet.Cells[row, 11].Value = plankton.TaxonConcentration;
                            worksheet.Cells[row, 12].Value = plankton.TaxonBiovolume;
                            worksheet.Cells[row, 13].Value = "Naturvårdsverkets Djurplankton i sjöar 2003-05-27";
                            worksheet.Cells[row, 14].Value = "Erkenlaboratoriet";
                        }
                    }
                    sample.exportedSamples.Clear();
                    package.Save();
                }
            }
        }
Ejemplo n.º 5
0
 public void AddPlankton(Plankton plankton)
 {
     this.exportedSamples.Add(plankton);
 }