public async Task <bool> Run( string inputFilePath, string outputFilePath, int delay = 100) { List <CsipLocation> locations = new List <CsipLocation>(); // Read file with FlexCropping locations List <FlexCroppingLocation> points = fileHandler.ReadFlexCroppingLocationFile(inputFilePath); // For each point, get cokey foreach (var point in points) { string polygonString = converter.GetPixelAsBoundingBoxString( point.Latitude, point.Longitude, 4); string resultJson = await serviceHandler.Post(polygonString); WweSoilParamsResponseV2_0 result = serviceHandler.ParseResultsJson(resultJson); //string cokey = cokeyChooser.GetDominateCokey(result); Component component = cokeyChooser.GetDominateComponent(result); string muname = cokeyChooser.GetDominateMapUnitName(result); CsipLocation location = new CsipLocation() { Latitude = point.Latitude, Longitude = point.Longitude, AnthromeKey = point.Anthrome, Cokey = component.Cokey, Slope = component.Slope, SlopeLength = component.SlopeLength, PercentOfMapUnit = component.PercentOfMapUnit, MapUnitName = muname }; locations.Add(location); Thread.Sleep(delay); } // Write file fileHandler.WriteCsipLocationFile(outputFilePath, locations); return(true); }
public bool Run( string inputCsipLocationsPath, string inputErosionParametersPath, string inputSciResponsePath, string outputFilePath) { const int PRECISION = 5; // CsipLocations and ErosionParameters should be in csv format already, from previous steps List <CsipLocation> csipLocations = csvHandler.ReadCsipLocationFile( inputCsipLocationsPath); List <ErosionParameters> erosionParameters = csvHandler.ReadErosionParameters( inputErosionParametersPath); List <SciResponseV2_1> sciResponses = jsonHandler.ReadSciResponseV2_1Files( inputSciResponsePath, serviceHandler); List <ExperimentalResults> experimentalResultsList = new List <ExperimentalResults>(); foreach (SciResponseV2_1 sciResponse in sciResponses) { // Find matching scenarios CsipLocation csipLocation = csipLocations .First(x => Math.Round(x.Latitude, PRECISION) == Math.Round(sciResponse.Latitude, PRECISION) && Math.Round(x.Longitude, PRECISION) == Math.Round(sciResponse.Longitude, PRECISION)); ErosionParameters erosionParameter = erosionParameters .First(x => Math.Round(x.Latitude, PRECISION) == Math.Round(sciResponse.Latitude, PRECISION) && Math.Round(x.Longitude, PRECISION) == Math.Round(sciResponse.Longitude, PRECISION) && x.RotationName == sciResponse.RotationName); if (csipLocation == null || erosionParameter == null) { throw new Exception( "Could not find matching CsipLocation and/or ErosionParameter for given SciResponse"); } ExperimentalResults result = new ExperimentalResults() { // TODO: Create new column for actual WindOM and value used by SCI service? Latitude = sciResponse.Latitude, Longitude = sciResponse.Longitude, RotationName = sciResponse.RotationName, AnthromeKey = csipLocation.AnthromeKey, Cokey = csipLocation.Cokey, Slope = csipLocation.Slope, SlopeLength = csipLocation.SlopeLength, PercentOfMapUnit = csipLocation.PercentOfMapUnit, MapUnitName = csipLocation.MapUnitName, WaterOM = sciResponse.WaterOM, WindOM = sciResponse.WindOM, WaterFO = sciResponse.WaterFO, WindFO = sciResponse.WindFO, ErosionWater = sciResponse.ErosionWater, ErosionWind = sciResponse.ErosionWind, SciTotal = sciResponse.SciTotal }; experimentalResultsList.Add(result); } // Write file csvHandler.WriteExperimentalResultsParameters( outputFilePath, experimentalResultsList); return(true); }