Example #1
0
        private async Task ProcessTaxonomicUnits(ITISPlantInfoTransformer transformer, PlantInfoProcessor processor, List <TaxonomicUnit> taxonomicUnits)
        {
            var plantInfos = new List <PlantInfo>();

            foreach (var taxonomicUnit in taxonomicUnits.GroupBy(t => t.Tsn))
            {
                var species = taxonomicUnit.First();
                if (species != null)
                {
                    try
                    {
                        var plantInfoResults = transformer.Transform(taxonomicUnit);
                        plantInfos.AddRange(plantInfoResults);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"Unable to process {taxonomicUnit.Key} {species} {ex.Message}", ex);
                    }
                }
            }

            var plantInfosResult = await processor.Process(plantInfos);

            foreach (var plantInfoResult in plantInfosResult)
            {
                _logger.LogInformation("CommonName" + ": " + plantInfoResult.CommonName + " ScientificName" + ": " + plantInfoResult.ScientificName +
                                       " PlantInfoId" + ": " + plantInfoResult.PlantInfoId);
            }
        }
Example #2
0
        public async Task TestITISPlantInfoProcessor()
        {
            var transformer = new ITISPlantInfoTransformer();
            var itisData    = ITISPlantInfoData();
            var plantInfos  = new List <PlantInfo>();

            itisData.ForEach(i => plantInfos.AddRange(transformer.Transform(new List <TaxonomicUnit> {
                i
            })));

            var originRepository        = RepositoryMocks.GetStandardMockOriginRepository(new List <Stores.Origin>());
            var locationRepository      = RepositoryMocks.GetStandardMockLocationRepository(new List <Stores.Location>());
            var lifeformRepository      = RepositoryMocks.GetStandardMockLifeformRepository(new List <Stores.Lifeform>());
            var plantInfoRepository     = RepositoryMocks.GetStandardMockPlantInfoRepository(new List <Stores.PlantInfo>());
            var plantLocationRepository = RepositoryMocks.GetStandardMockPlantLocationRepository(new List <Stores.PlantLocation>());
            var synonymRepository       = RepositoryMocks.GetStandardMockSynonymRepository();
            var taxonRepository         = RepositoryMocks.GetStandardMockTaxonRepository(new List <Stores.Taxon>());
            var plantSynonymRepository  = new Mock <IRepository <Stores.PlantSynonym> >();
            var plantInfoIndex          = SearchMocks.GetStandardMockPlantInfoIndex();
            var lifeformIndex           = SearchMocks.GetStandardMockLifeformIndex();

            var locationService  = new LocationService(locationRepository.Object);
            var originService    = new OriginService(originRepository.Object, locationService);
            var lifeformService  = new LifeformService(lifeformRepository.Object, lifeformIndex.Object);
            var plantInfoService = new PlantInfoService(plantInfoRepository.Object, plantLocationRepository.Object, plantInfoIndex.Object);
            var synonymService   = new SynonymService(synonymRepository.Object);
            var taxonService     = new TaxonService(taxonRepository.Object, synonymService);

            var processor = new PlantInfoProcessor(lifeformService, originService, plantInfoService, taxonService, locationService);

            await processor.InitializeOrigin(transformer.Origin);

            await processor.InitializeLifeforms();

            await processor.InitializeTaxons();

            var result = await processor.Process(plantInfos);

            result.Count(p => p.ScientificName == "Glandularia quadrangulata").Should().Be(1);
            result.Count(p => p.Taxon.Subfamily == null).Should().Be(5);
            result.Count(p => p.Taxon.Species == "cremersii").Should().Be(1);
            result.Count(p => p.Taxon.Form == "viridifolia").Should().Be(1);
            result.Count(p => p.Taxon.Subspecies == "purpurea").Should().Be(1);
            result.Count(p => p.Taxon.Variety == "graminea").Should().Be(1);
            result.Where(p => p.Locations != null).SelectMany(p => p.Locations).Count().Should().Be(3);
            result.Where(p => p.Locations != null).SelectMany(p => p.Locations).Count(l => l.Status == LocationStatus.Native).Should().Be(3);
            result.Select(p => p.Origin).DistinctBy(o => o.OriginId).Count().Should().Be(5);
        }
Example #3
0
        public void TestITISPlantInfoTransformer()
        {
            var transformer = new ITISPlantInfoTransformer();

            var itisData = ITISPlantInfoData();
            var result   = new List <PlantInfo>();

            itisData.ForEach(i => result.AddRange(transformer.Transform(new List <TaxonomicUnit> {
                i
            })));

            result.Count(p => p.ScientificName == "Glandularia quadrangulata").Should().Be(1);
            result.Count(p => p.Taxon.Subfamily == null).Should().Be(6);
            result.Count(p => p.Taxon.Species == "cremersii").Should().Be(2);
            result.Count(p => p.Taxon.Form == "viridifolia").Should().Be(2);
            result.Count(p => p.Taxon.Subspecies == "purpurea").Should().Be(1);
            result.Count(p => p.Taxon.Variety == "graminea").Should().Be(1);
            result.Where(p => p.Locations != null).SelectMany(p => p.Locations).Count().Should().Be(3);
            result.SelectMany(p => p.Locations).DistinctBy(l => l.Location.Region).Count().Should().Be(1);
            result.Select(p => p.Origin).Count().Should().Be(6);
        }