public DrillConfigService(int numberOfRecordsToQueryDip, int dipMarginOfError, int numberOfRecordsToQueryAzimuth, int azimuthMarginOfError) { DrillConfigModel = new DrillConfigModel( numberOfRecordsToQueryDip, dipMarginOfError, numberOfRecordsToQueryAzimuth, azimuthMarginOfError); }
public static DrillSiteService CreateRandomDrillSite(DrillConfigModel config, Random random) { var lng = random.NextDouble() * 360 - 180; var lat = random.NextDouble() * 180 - 90; var azimuth = random.NextDouble() * 360; var dip = random.NextDouble() * 90; var date = DateTime.Now - TimeSpan.FromDays(random.NextDouble() * 7); // up to a week in the past var model = new DrillSiteModel(lat, lng, dip, azimuth, date); return(new DrillSiteService(model, config)); }
public void TestUpdateReadingsTrustworthiness() { var config = new DrillConfigModel(5, 3, 1, 5); var readings = new List <DepthReadingModel>() { new DepthReadingModel(5, 150, 100), // avg dip = - last azimuth = - - trustworthy new DepthReadingModel(4, 145.01, 100), //avg dip = 5 last azimuth = 150 - trustworthy new DepthReadingModel(3, 142, 100), // avg dip = 4.5 last azimuth = ~145 - trustworthy new DepthReadingModel(5, 139, 100), // avg dip = 4 last azimuth = 142 - trustworthy new DepthReadingModel(5, 135, 100), // avg dip = 4.25 last azimuth = 139 - trustworthy new DepthReadingModel(1, 137, 100), // avg dip = 4.4 last azimuth = 135 - not trustworthy new DepthReadingModel(1, 134, 100), // avg dip = 3.6 last azimuth = 137 - trustworthy new DepthReadingModel(1, 120, 100), // avg dip = 3 last azimuth = 134 - not trustworthy new DepthReadingModel(2, 118, 100), // avg dip = 2.6 last azimuth = 120 - trustworthy new DepthReadingModel(3, 150, 100), // avg dip = 2 last azimuth = 120 - not trustworthy }; var expectedReadings = new List <DepthReadingModel>() { new DepthReadingModel(5, 150, 100), // avg dip = - last azimuth = - - trustworthy new DepthReadingModel(4, 145, 100), // avg dip = 5 last azimuth = 150 - trustworthy new DepthReadingModel(3, 140, 100), // avg dip = 4.5 last azimuth = 145 - trustworthy new DepthReadingModel(5, 139, 100), // avg dip = 4 last azimuth = 140 - trustworthy new DepthReadingModel(5, 135, 100), // avg dip = 4.25 last azimuth = 139 - trustworthy new DepthReadingModel(1, 137, 0.0), // avg dip = 4.4 last azimuth = 135 - not trustworthy new DepthReadingModel(1, 134, 100), // avg dip = 3.6 last azimuth = 137 - trustworthy new DepthReadingModel(1, 120, 0.0), // avg dip = 3 last azimuth = 134 - not trustworthy new DepthReadingModel(2, 118, 100), // avg dip = 2.6 last azimuth = 120 - trustworthy new DepthReadingModel(3, 150, 0.0), // avg dip = 2 last azimuth = 120 - not trustworthy }; // test not equal where trustworthness is expected to be false for (var i = 0; i < readings.Count; i++) { if (!expectedReadings[i].IsTrustworthy) { Assert.AreNotEqual(expectedReadings[i].IsTrustworthy, readings[i].IsTrustworthy); } } DrillSiteService.UpdateReadingsTrustworthiness(readings, 0, config); for (var i = 0; i < readings.Count; i++) { Assert.AreEqual(expectedReadings[i].IsTrustworthy, readings[i].IsTrustworthy); } }
/// <summary> /// Recursive function that will cycle through the readings, starting at /// indexToUpdate until it reaches the end of the readings list, updating /// the trustworthiness as it goes along. /// </summary> /// <param name="readings"></param> /// <param name="indexToUpdate"></param> /// <param name="config">If left null, will use config from database - optional for unit testing purposes</param> public static void UpdateReadingsTrustworthiness(List <DepthReadingModel> readings, int indexToUpdate, DrillConfigModel config = null) { if (indexToUpdate >= readings.Count) { return; // end of list } if (config == null) { config = Config ?? (Config = DrillConfigService.GetInstance().DrillConfigModel); } var azimuthRecordsToQuery = RetrieveXRecordsBefore(readings, indexToUpdate, config.NumberOfRecordsToQueryAzimuth).ToList(); var dipRecordsToQuery = config.NumberOfRecordsToQueryAzimuth == config.NumberOfRecordsToQueryDip ? azimuthRecordsToQuery // no need to calculate new list, if they're both going to be the same : RetrieveXRecordsBefore(readings, indexToUpdate, config.NumberOfRecordsToQueryDip).ToList(); CalculateTrustWorthiness(config, readings[indexToUpdate], dipRecordsToQuery, azimuthRecordsToQuery); UpdateReadingsTrustworthiness(readings, indexToUpdate + 1, config); }
private static void CalculateTrustWorthiness(DrillConfigModel config, DepthReadingModel reading, List <DepthReadingModel> dipRecordsToQuery, List <DepthReadingModel> azimuthRecordsToQuery) { // take averages var azimuthAverage = azimuthRecordsToQuery.Any() ? azimuthRecordsToQuery.Sum(x => x.Azimuth) / azimuthRecordsToQuery.Count() : (double?)null; var dipAverage = dipRecordsToQuery.Any() ? dipRecordsToQuery.Sum(x => x.Dip) / dipRecordsToQuery.Count() : (double?)null; if (!dipAverage.HasValue || !azimuthAverage.HasValue) { // assume trustworthy, likely no records exist before this node reading.TrustWorthiness = 100f; return; } // calculate trustworthiness reading.TrustWorthiness = Math.Abs(reading.Azimuth - azimuthAverage.Value) < config.AzimuthMarginOfError && Math.Abs(reading.Dip - dipAverage.Value) < config.DipMarginOfError ? 100 : 0; }
public DrillConfigService(DrillConfigModel config) { DrillConfigModel = config; }
/// <summary> /// Default constructor, that will create the model with the hard-coded default values /// </summary> public DrillConfigService() { DrillConfigModel = new DrillConfigModel(); }
public DrillSiteService(DrillSiteModel drillSiteModel, DrillConfigModel config) { Config = config; DrillSiteModel = drillSiteModel; }