public void RegionsTest() { IDataPointsRegionsSource source = new PowerOfTwoRegionsSource(); var x = source.GetRegionIndexes(longitude: 28.597728655515253600863950727m, latitude: 44.304150309297175136564201538m, zoomLevel: 20); var y = source.GetRegionIndexes(-90, -180, 1); Assert.Equals(x, new Tuple <int, int>(266197, 607584)); Assert.Equals(y, new Tuple <int, int>(1, 0)); }
public void CheckDataSetCreation() { IDataPointsSource pointsSource = new TxtDataPointsSource(); IDataPointsRegionsSource regionSource = new PowerOfTwoRegionsSource(); (pointsSource as TxtDataPointsSource).HeaderFile = @"E:\temp\header.txt"; (pointsSource as TxtDataPointsSource).DisplacementsFile = @"E:\temp\displacements.txt"; (pointsSource as TxtDataPointsSource).LatitudeZone = 'T'; (pointsSource as TxtDataPointsSource).Zone = 35; PointsDataSet dataset = pointsSource.CreateDataSet("Test", CoordinateSystem.UTM).First(); bool regionsGenerationResult = regionSource.GenerateRegions(dataset); IEnumerable <PointType> points = PointType.GetPoints(dataset); IDataPointsZoomLevelsSource zoomGenerator = new SquareMeanPZGenerator(); PointsDataSet[] set = zoomGenerator.CreateDataSetsZoomSets(dataset, 3, 19); Assert.IsNotNull(dataset); Assert.IsNotNull(points); Assert.IsTrue(regionsGenerationResult); }
private void processFile(string fileName, string username, string datasetName) { IDataPointsSource pointsSource = new TxtDataPointsSource(); int datasetId = this.userRepository.GetDatasetID(username, datasetName); if (datasetId == -1) { throw new Exception($"Failed to find / create dataset with the name {datasetName} for user {username} "); } (pointsSource as TxtDataPointsSource).HeaderFile = ConfigurationManager.AppSettings["DataSetsHeaderFile"]; (pointsSource as TxtDataPointsSource).DisplacementsFile = fileName; (pointsSource as TxtDataPointsSource).LatitudeZone = 'T'; //TODO: modify here. This can be read from database (pointsSource as TxtDataPointsSource).Zone = 35; //TODO: modify here. This can be read from database decimal minimumLatitude = 90, minimumLongitude = 180, maximumLatitude = -90, maximumLongitude = -180, minimumHeight = decimal.MaxValue, maximumHeight = decimal.MinValue, minimumStdDev = decimal.MaxValue, maximumStdDev = decimal.MinValue, minimumDefRate = decimal.MaxValue, maximumDefRate = decimal.MinValue; int sectionIndex = 1; ///The source file must be looped, because a full read in memory of the file could throw a OutOfMemoryException. ///This means that the file will be read and parsed in chunks and multiple datasets with the same ID will be created ///and stored in repository. foreach (var dataset in pointsSource.CreateDataSet(datasetName, CoordinateSystem.Default)) { if (dataset == null) { logData("Failed to read the dataset", EventLogEntryType.Error); this.userRepository.UpdateDatasetStatus(datasetName, DatasetStatus.GenerateFail, username); //todo: cleanup the repository? return; } dataset.ID = datasetId; IDataPointsRegionsSource regionSource = new PowerOfTwoRegionsSource(); regionSource.GenerateRegions(dataset, sectionIndex++); logData($"Starting to parse an entry of {dataset.Points.Count()} points count", EventLogEntryType.Information); Task <bool> insertTask = this.dataPointsRepository.InsertPointsDataset(dataset); insertTask.Wait(); logData("Finished to insert the current dataset", EventLogEntryType.Information); if (sectionIndex == 21) { } if (insertTask.IsFaulted || !insertTask.Result) { throw new Exception("Failed to insert data in the database"); } minimumLatitude = Math.Min(minimumLatitude, dataset.MinimumLatitude ?? 90); maximumLatitude = Math.Max(maximumLatitude, dataset.MaximumLatitude ?? -90); minimumLongitude = Math.Min(minimumLongitude, dataset.MinimumLongitude ?? 180); maximumLongitude = Math.Max(maximumLongitude, dataset.MaximumLongitude ?? -180); minimumHeight = Math.Min(minimumHeight, dataset.MinimumHeight ?? minimumHeight); maximumHeight = Math.Max(maximumHeight, dataset.MaximumHeight ?? maximumHeight); minimumStdDev = Math.Min(minimumStdDev, dataset.MinimumStdDev ?? minimumStdDev); maximumStdDev = Math.Max(maximumStdDev, dataset.MaximumStdDev ?? maximumStdDev); minimumDefRate = Math.Min(minimumDefRate, dataset.MinimumDeformationRate ?? minimumDefRate); maximumDefRate = Math.Max(maximumDefRate, dataset.MaximumDeformationRate ?? maximumDefRate);; //update the status of the dataset which has been processed } this.userRepository.UpdateDatasetLimits(datasetName, username, minimumLatitude, minimumLongitude, maximumLatitude, maximumLongitude); this.userRepository.UpdateDatasetRepresentationLimits(datasetName, username, minimumHeight, maximumHeight, minimumDefRate, maximumDefRate, minimumStdDev, maximumStdDev); this.userRepository.UpdateDatasetStatus(datasetName, DatasetStatus.Generated, username); }