private ErosionParameters GetErosionParameters( WepsResponseV5_2 wepsResponse, WeppResponseV3_1 weppResponse, Rusle2ResponseV5_0 rusle2Response) { double null_flag = -9999.99; ErosionParameters result = new ErosionParameters() { Latitude = wepsResponse.Latitude, Longitude = wepsResponse.Longitude, RotationName = wepsResponse.RotationName, WepsOM = wepsResponse.OM, WeppOM = weppResponse?.OM ?? null_flag, Rusle2OM = rusle2Response?.OM ?? null_flag, WepsFO = wepsResponse.FO, WeppFO = weppResponse?.FO ?? null_flag, Rusle2FO = rusle2Response?.FO ?? null_flag, WepsER = wepsResponse.ER, WeppER = weppResponse?.ER ?? null_flag, Rusle2ER = rusle2Response?.ER ?? null_flag, WepsStir = wepsResponse.Stir, WeppStir = weppResponse?.Stir ?? null_flag, Rusle2Stir = rusle2Response?.Stir ?? null_flag, WepsWindErosion = wepsResponse.WindErosion, WeppSoilLoss = weppResponse?.SoilLoss ?? null_flag, Rusle2SoilLoss = rusle2Response?.SoilLoss ?? null_flag, Rusle2Sci = rusle2Response?.SCI ?? null_flag, WepsAverageBiomass = wepsResponse?.AverageBiomass ?? null_flag }; return(result); }
private WepsResponseV5_2 ParseParameterElement( JsonProperty parameterElement) { WepsResponseV5_2 result = new WepsResponseV5_2(); foreach (var element in parameterElement.Value.EnumerateArray()) { string propName = element.GetProperty("name").GetString(); switch (propName) { case "latitude": result.Latitude = Convert.ToDouble( element.GetProperty("value").GetString()); break; case "longitude": result.Longitude = Convert.ToDouble( element.GetProperty("value").GetString()); break; case "crlmod": result.RotationName = element .GetProperty("value") .GetProperty("rotationFiles") .EnumerateArray().First() .GetProperty("rotation") .GetProperty("name").GetString(); break; } } return(result); }
public List <WepsResponseV5_2> ReadWepsResponseV5_2Files( string filePath, WepsV5_2 service) { string[] files = Directory.GetFiles(filePath, "*.json"); List <WepsResponseV5_2> results = new List <WepsResponseV5_2>(); foreach (var file in files) { string json = File.ReadAllText(file); WepsResponseV5_2 result = service.ParseResultsJson(json); results.Add(result); } return(results); }
public void ParseResults_ValidJson_ExpectedResults() { // Arrange var sut = new WepsV5_2(); string json = File.ReadAllText( @"Assets\exampleWepsResultV5_2.json"); // Act WepsResponseV5_2 actual = sut.ParseResultsJson(json); // Assert Assert.Equal("95abb930-3246-11ea-bc15-6386ee4990d5", actual.Suid); Assert.Equal("GrainFallow_HeavyTillage", actual.RotationName); Assert.Equal(0.223490870061, actual.WindErosion); Assert.Equal(-0.1239, actual.OM); Assert.Equal(0.9119, actual.ER); Assert.Equal(0.0114, actual.FO); Assert.Equal(99.845, actual.Stir); }
public WepsResponseV5_2 ParseResultsJson(string jsonResult) { WepsResponseV5_2 metainfo = new WepsResponseV5_2(); WepsResponseV5_2 parameters = new WepsResponseV5_2(); WepsResponseV5_2 result = new WepsResponseV5_2(); var options = new JsonDocumentOptions { AllowTrailingCommas = true }; using (JsonDocument document = JsonDocument.Parse(jsonResult, options)) { foreach (JsonProperty element in document.RootElement.EnumerateObject()) { string elementName = element.Name; switch (elementName) { case "metainfo": metainfo = ParseMetainfoElement(element); break; case "parameter": parameters = ParseParameterElement(element); break; case "result": result = ParseResultElement(element); break; } } } WepsResponseV5_2 results = MergeResults( metainfo, parameters, result); return(results); }
private WepsResponseV5_2 ParseMetainfoElement( JsonProperty metainfoElement) { WepsResponseV5_2 result = new WepsResponseV5_2(); foreach (var element in metainfoElement.Value.EnumerateObject()) { string propName = element.Name; switch (propName) { case "suid": result.Suid = element.Value.GetString(); break; case "status": result.Status = element.Value.GetString(); break; } } return(result); }
private WepsResponseV5_2 MergeResults( WepsResponseV5_2 metainfo, WepsResponseV5_2 parameters, WepsResponseV5_2 result) { WepsResponseV5_2 results = new WepsResponseV5_2() { Suid = metainfo.Suid, Status = metainfo.Status, Latitude = parameters.Latitude, Longitude = parameters.Longitude, RotationName = parameters.RotationName, WindErosion = result.WindErosion, ER = result.ER, FO = result.FO, OM = result.OM, Stir = result.Stir, AverageBiomass = result.AverageBiomass }; return(results); }
private WepsResponseV5_2 ParseResultElement( JsonProperty resultElement) { WepsResponseV5_2 result = new WepsResponseV5_2(); foreach (var element in resultElement.Value.EnumerateArray()) { string propName = element.GetProperty("name").GetString(); switch (propName) { case "wind_eros": result.WindErosion = element.GetProperty("value").GetDouble(); break; case "sci_er_factor": result.ER = element.GetProperty("value").GetDouble(); break; case "sci_om_factor": result.OM = element.GetProperty("value").GetDouble(); break; case "sci_fo_factor": result.FO = element.GetProperty("value").GetDouble(); break; case "avg_all_stir": result.Stir = element.GetProperty("value").GetDouble(); break; case "average_biomass": result.AverageBiomass = element.GetProperty("value").GetDouble(); break; } } return(result); }