public void GridStatisticsTableOnSpeciesRichnessGetTest() { // Arrange ResultController resultController = new ResultController(); var taxaIds = new ObservableCollection <int> { 100573 }; SessionHandler.MySettings = new MySettings(); SessionHandler.MySettings.Filter.Taxa.TaxonIds = taxaIds; SessionHandler.MySettings.Filter.Taxa.IsActive = true; SessionHandler.MySettings.Presentation.Table.IsActive = true; SessionHandler.MySettings.Calculation.GridStatistics.CalculateNumberOfObservations = false; SessionHandler.MySettings.Calculation.GridStatistics.CalculateNumberOfTaxa = true; SessionHandler.MySettings.Calculation.GridStatistics.GridSize = 50000; SessionHandler.MySettings.Calculation.GridStatistics.CoordinateSystemId = (int)GridCoordinateSystem.Rt90_25_gon_v; SessionHandler.MySettings.Calculation.GridStatistics.IsActive = true; // Act // Get Views and model var viewResult = resultController.Tables(); Assert.IsNotNull(viewResult); var result = resultController.GridStatisticsTableOnSpeciesRichness() as ViewResult; Assert.IsNotNull(result); var model = (ResultTaxonGridTableViewModel)result.ViewData.Model; // Get json result from server JsonNetResult taxonResult = resultController.GetTaxonGridCountAsJSON(); JsonModel jsonResult = (JsonModel)taxonResult.Data; TaxonGridResult taxonListResult = (TaxonGridResult)jsonResult.Data; // Assert Assert.IsNotNull(result); Assert.IsTrue(model.OriginalCoordinateSystemName.Equals("RT 90")); // Todo: should be fixed when naming convention of RT 90 and SWEREF99 is resolved. // Assert.IsTrue(model.OriginalCoordinateSystemName.Equals(GridCoordinateSystem.Rt90_25_gon_v.ToString())); Assert.IsTrue(model.CoordinateSystemName.Equals("Google Mercator")); Assert.IsNotNull(taxonResult); Assert.IsNotNull(jsonResult); Assert.IsTrue(jsonResult.Success); Assert.IsTrue(taxonListResult.Cells.Count > 0); Assert.IsTrue(taxonListResult.Cells[0].SpeciesCount > 0); Assert.IsTrue(taxonListResult.Cells[0].ObservationCount > 0); // Not used Assert.IsNotNull(taxonListResult.Cells[0].CentreCoordinate); Assert.IsNotNull(taxonListResult.Cells[0].CentreCoordinateX); Assert.IsNotNull(taxonListResult.Cells[0].CentreCoordinateY); Assert.IsNotNull(taxonListResult.Cells[0].BoundingBox); Assert.IsNotNull(taxonListResult.Cells[0].OriginalCentreCoordinateX); Assert.IsNotNull(taxonListResult.Cells[0].OriginalCentreCoordinateY); }
public void SpeciesRichnessGridMapSuccessTest() { // Arrange ResultController resultController = new ResultController(); var taxaIds = new ObservableCollection <int> { 100573 }; SessionHandler.MySettings = new MySettings(); SessionHandler.MySettings.Filter.Taxa.TaxonIds = taxaIds; SessionHandler.MySettings.Filter.Taxa.IsActive = true; SessionHandler.MySettings.Presentation.Table.IsActive = true; SessionHandler.MySettings.Calculation.GridStatistics.CalculateNumberOfObservations = false; SessionHandler.MySettings.Calculation.GridStatistics.CalculateNumberOfTaxa = true; SessionHandler.MySettings.Calculation.GridStatistics.GridSize = 50000; SessionHandler.MySettings.Calculation.GridStatistics.CoordinateSystemId = (int)GridCoordinateSystem.Rt90_25_gon_v; SessionHandler.MySettings.Calculation.GridStatistics.IsActive = true; // Act // Get Views and model var viewResult = resultController.Maps(); Assert.IsNotNull(viewResult); var result = resultController.SpeciesRichnessGridMap() as ViewResult; Assert.IsNotNull(result); var viewName = result.ViewName; // Get json result from server JsonNetResult taxonResult = resultController.GetTaxonGridCountAsJSON(); JsonModel jsonResult = (JsonModel)taxonResult.Data; TaxonGridResult taxonMapResult = (TaxonGridResult)jsonResult.Data; // Assert Assert.IsNotNull(result); // Assert.IsTrue(viewName.Equals("SpeciesRichnessGridMap")); Assert.IsNotNull(taxonResult); Assert.IsNotNull(jsonResult); Assert.IsTrue(jsonResult.Success); Assert.IsNotNull(taxonMapResult); Assert.IsTrue(taxonMapResult.Cells.Count > 0); Assert.IsTrue(taxonMapResult.Cells[0].SpeciesCount > 0); Assert.IsTrue(taxonMapResult.Cells[0].ObservationCount > 0); // Not used Assert.IsNotNull(taxonListResult.Cells[0].CentreCoordinate); Assert.IsNotNull(taxonMapResult.Cells[0].CentreCoordinateX); Assert.IsNotNull(taxonMapResult.Cells[0].CentreCoordinateY); Assert.IsNotNull(taxonMapResult.Cells[0].BoundingBox); Assert.IsNotNull(taxonMapResult.Cells[0].OriginalCentreCoordinateX); Assert.IsNotNull(taxonMapResult.Cells[0].OriginalCentreCoordinateY); Assert.IsTrue(taxonMapResult.GridCellCoordinateSystem.Equals(GridCoordinateSystem.Rt90_25_gon_v.ToString())); }
/// <summary> /// Adds the headers. /// </summary> /// <param name="worksheet">The worksheet.</param> private void AddHeaders(ExcelWorksheet worksheet, TaxonGridResult data) { worksheet.Cells[1, 1].Value = "Id"; worksheet.Cells[1, 2].Value = Resource.GridStatisticsTaxaCount; worksheet.Cells[1, 3].Value = Resource.GridStatisticsObservationCount; worksheet.Cells[1, 4].Value = String.Format("Centre coordinate X ({0})", data.GridCellCoordinateSystem); worksheet.Cells[1, 5].Value = String.Format("Centre coordinate Y ({0})", data.GridCellCoordinateSystem); worksheet.Cells[1, 6].Value = String.Format("Centre coordinate X ({0})", CoordinateSystem); worksheet.Cells[1, 7].Value = String.Format("Centre coordinate Y ({0})", CoordinateSystem); worksheet.Cells[1, 8].Value = "Grid cell width (metres)"; }
public void GridStatisticsTableOnSpeciesRichnessGetNoTaxaSetTest() { // Arrange ResultController resultController = new ResultController(); var taxaIds = new ObservableCollection <int>(); SessionHandler.MySettings = new MySettings(); SessionHandler.MySettings.Filter.Taxa.TaxonIds = taxaIds; SessionHandler.MySettings.Filter.Taxa.IsActive = true; SessionHandler.MySettings.Presentation.Table.IsActive = false; SessionHandler.MySettings.DataProvider.DataProviders.IsActive = false; SessionHandler.MySettings.Calculation.GridStatistics.IsActive = false; SessionHandler.MySettings.Calculation.SummaryStatistics.IsActive = false; SessionHandler.MySettings.Filter.Occurrence.IsActive = false; SessionHandler.MySettings.Filter.Quality.IsActive = false; SessionHandler.MySettings.Filter.Spatial.IsActive = false; SessionHandler.MySettings.Filter.Temporal.IsActive = false; SessionHandler.MySettings.Presentation.Map.IsActive = false; SessionHandler.MySettings.Presentation.Report.IsActive = false; SessionHandler.MySettings.DataProvider.MapLayers.IsActive = false; // Act var result = resultController.GridStatisticsTableOnSpeciesRichness(); Assert.IsNotNull(result); var taxonResult = resultController.GetTaxonGridCountAsJSON(); Assert.IsNotNull(taxonResult); JsonModel jsonResult = (JsonModel)taxonResult.Data; TaxonGridResult taxonListResult = (TaxonGridResult)jsonResult.Data; // Add one taxa taxaIds.Add(100573); SessionHandler.MySettings.Filter.Taxa.TaxonIds = taxaIds; var taxonResult2 = resultController.GetTaxonGridCountAsJSON(); Assert.IsNotNull(taxonResult2); JsonModel jsonResult2 = (JsonModel)taxonResult2.Data; TaxonGridResult taxonListResult2 = (TaxonGridResult)jsonResult2.Data; // Assert Assert.IsNotNull(jsonResult); Assert.IsTrue(jsonResult.Success); Assert.IsNotNull(jsonResult.Data); // If no taxa is set then all taxa will be returned Assert.IsTrue(taxonListResult.Cells.Count > 0); Assert.IsTrue(taxonListResult2.Cells.Count > 0); Assert.IsTrue(taxonListResult.Cells.Count > taxonListResult2.Cells.Count); }
public override void Execute() { System.Diagnostics.Debug.WriteLine("CalculateDefaultTaxonGridTask started"); IUserContext userContext = CoreData.UserManager.GetCurrentUser(); MySettings.MySettings mySettings = new MySettings.MySettings(); TaxonGridCalculator resultCalculator = new TaxonGridCalculator(userContext, mySettings); TaxonGridResult result = resultCalculator.CalculateTaxonGrid(mySettings); DefaultResultsManager.AddGridCellTaxa(result); System.Diagnostics.Debug.WriteLine("CalculateDefaultTaxonGridTask finished"); }
public TaxonGridResult CalculateTaxonGrid() { List <int> taxonIds = null; if (MySettings.Filter.Taxa.IsActive) { taxonIds = MySettings.Filter.Taxa.TaxonIds.ToList(); } IList <IGridCellSpeciesCount> result = CalculateTaxonGrid(taxonIds, null); return(TaxonGridResult.Create(result)); }
private void AddContentData(ExcelWorksheet worksheet, TaxonGridResult data) { var rowIndex = 2; foreach (var row in data.Cells) { worksheet.Cells[rowIndex, 1].Value = row.Identifier; worksheet.Cells[rowIndex, 2].Value = row.SpeciesCount; worksheet.Cells[rowIndex, 3].Value = row.ObservationCount; worksheet.Cells[rowIndex, 4].Value = row.OriginalCentreCoordinateX; worksheet.Cells[rowIndex, 5].Value = row.OriginalCentreCoordinateY; worksheet.Cells[rowIndex, 6].Value = row.CentreCoordinateX; worksheet.Cells[rowIndex, 7].Value = row.CentreCoordinateY; worksheet.Cells[rowIndex, 8].Value = data.GridCellSize; rowIndex++; } }
/// <summary> /// Calculates a species richness grid and creates a feature collection. /// </summary> /// <returns>A feature collection containing all grid cells.</returns> public FeatureCollection GetTaxonGridAsFeatureCollection() { TaxonGridResult taxonGridResult = GetTaxonGridResultFromCacheIfAvailableOrElseCalculate(); List <Feature> features = new List <Feature>(); foreach (TaxonGridCellResult gridCell in taxonGridResult.Cells) { Dictionary <string, object> properties = new Dictionary <string, object>(); properties.Add("Id", gridCell.Identifier); properties.Add("SpeciesCount", gridCell.SpeciesCount); properties.Add("ObservationCount", gridCell.ObservationCount); properties.Add("CentreCoordinateX", gridCell.CentreCoordinateX); properties.Add("CentreCoordinateY", gridCell.CentreCoordinateY); properties.Add("OriginalCentreCoordinateX", gridCell.OriginalCentreCoordinateX); properties.Add("OriginalCentreCoordinateY", gridCell.OriginalCentreCoordinateY); List <GeographicPosition> coordinates = new List <GeographicPosition>(); coordinates.Add(new GeographicPosition(gridCell.BoundingBox[0][0], gridCell.BoundingBox[0][1])); coordinates.Add(new GeographicPosition(gridCell.BoundingBox[1][0], gridCell.BoundingBox[1][1])); coordinates.Add(new GeographicPosition(gridCell.BoundingBox[2][0], gridCell.BoundingBox[2][1])); coordinates.Add(new GeographicPosition(gridCell.BoundingBox[3][0], gridCell.BoundingBox[3][1])); coordinates.Add(new GeographicPosition(gridCell.BoundingBox[0][0], gridCell.BoundingBox[0][1])); LineString lineString = new LineString(coordinates); List <LineString> linearRings = new List <LineString>(); linearRings.Add(lineString); ArtDatabanken.GIS.GeoJSON.Net.Geometry.Polygon polygon = new ArtDatabanken.GIS.GeoJSON.Net.Geometry.Polygon(linearRings); Feature feature = new Feature(polygon, properties); features.Add(feature); } FeatureCollection featureCollection = new FeatureCollection(features); featureCollection.CRS = new NamedCRS(MySettings.Presentation.Map.PresentationCoordinateSystemId.EpsgCode()); return(featureCollection); }
public static CalculatedDataItem <TaxonGridResult> AddGridCellTaxa(TaxonGridResult data) { return(CalculatedDataItemCollection.AddCalculatedDataItem(CalculatedDataItemType.GridCellTaxa, data)); }
public TaxonGridResult CalculateTaxonGrid(MySettings.MySettings mySettings) { IList <IGridCellSpeciesCount> result = CalculateTaxonGrid(mySettings.Filter.Taxa.TaxonIds.ToList(), null); return(TaxonGridResult.Create(result)); }