Example #1
0
        public string GetDominateMapUnitName(WweSoilParamsResponseV2_0 mapUnits)
        {
            string name = mapUnits.MapUnits
                          .OrderByDescending(m => m.Area)
                          .FirstOrDefault().Name;

            return(name);
        }
Example #2
0
        public Component GetDominateComponent(WweSoilParamsResponseV2_0 mapUnits)
        {
            Component component = mapUnits.MapUnits
                                  .OrderByDescending(m => m.Area)
                                  .FirstOrDefault().Components
                                  .OrderByDescending(c => c.PercentOfMapUnit)
                                  .FirstOrDefault();

            return(component);
        }
Example #3
0
        public void GetDominateCokey_ValidInput_ReturnsExpected()
        {
            // Arrange
            var    sut      = new CokeyChooser();
            string expected = "17391360";
            WweSoilParamsResponseV2_0 mockResults = GetMockWweSoilParamsV2Results();

            // Act
            string actual = sut.GetDominateCokey(mockResults);

            // Assert
            Assert.Equal(expected, actual);
        }
Example #4
0
        // Returns a cokey string from
        public string GetDominateCokey(WweSoilParamsResponseV2_0 mapUnits)
        {
            // TODO: Possibly return Mukey, percent, area, along with cokey

            // I love Linq
            string cokey = mapUnits.MapUnits
                           .OrderByDescending(m => m.Area)
                           .FirstOrDefault().Components
                           .OrderByDescending(c => c.PercentOfMapUnit)
                           .FirstOrDefault().Cokey;

            return(cokey);
        }
        public void ParseResults_ValidJson_ExpectedResult()
        {
            // Arrange
            var    sut  = new WweSoilParamsV2_0(client);
            string json = File.ReadAllText(
                @"Assets\WweSoilParamsV2JsonResults.json");
            //WweSoilParamsV2Results expected = new WweSoilParamsV2Results();

            // Act
            WweSoilParamsResponseV2_0 actual = sut.ParseResultsJson(json);

            // Assert
            Assert.Equal(10, actual.MapUnits.Count);
            Assert.Equal("3963.178", actual.MapUnitMeta.Area);
        }
        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);
        }
        private WweSoilParamsResponseV2_0 ParseResultElement(JsonProperty resultElement)
        {
            WweSoilParamsResponseV2_0 results = new WweSoilParamsResponseV2_0();

            foreach (var element in resultElement.Value.EnumerateArray())
            {
                if (element.GetProperty("name").GetString() == "AoA Area")
                {
                    results.MapUnitMeta = JsonSerializer
                                          .Deserialize <MapUnitMeta>(element.ToString());
                }

                if (element.GetProperty("name").GetString() == "Map Units")
                {
                    results.MapUnits = ParseMapUnits(element);
                }
            }

            return(results);
        }
        public WweSoilParamsResponseV2_0 ParseResultsJson(string jsonResult)
        {
            // TODO: Read error message, include in returned object

            WweSoilParamsResponseV2_0 result = new WweSoilParamsResponseV2_0();

            var options = new JsonDocumentOptions
            {
                AllowTrailingCommas = true
            };

            using (JsonDocument document = JsonDocument.Parse(jsonResult, options))
            {
                foreach (JsonProperty element in document.RootElement.EnumerateObject())
                {
                    if (element.Name == "result")
                    {
                        result = ParseResultElement(element);
                    }
                }
            }

            return(result);
        }
Example #9
0
        private WweSoilParamsResponseV2_0 GetMockWweSoilParamsV2Results()
        {
            WweSoilParamsResponseV2_0 results = new WweSoilParamsResponseV2_0()
            {
                MapUnitMeta = new MapUnitMeta()
                {
                    Area  = "3963.178",
                    Name  = "AoA Area",
                    Units = "acres"
                },
                MapUnits = new List <MapUnit>()
                {
                    new MapUnit()
                    {
                        Area       = 1589.15,
                        Mukey      = "64429",
                        Name       = "Walla Walla silt loam, 1 to 7 percent slopes",
                        Components = new List <Component>()
                        {
                            new Component()
                            {
                                Cokey            = "17391360",
                                Name             = "Walla Walla",
                                PercentOfMapUnit = 85
                            }
                        }
                    },
                    new MapUnit()
                    {
                        Area       = 276.694,
                        Mukey      = "64430",
                        Name       = "Walla Walla silt loam, 7 to 12 percent slopes",
                        Components = new List <Component>()
                        {
                            new Component()
                            {
                                Cokey            = "17391361",
                                Name             = "Walla Walla",
                                PercentOfMapUnit = 75
                            }
                        }
                    },
                    new MapUnit()
                    {
                        Area       = 1.249,
                        Mukey      = "64431",
                        Name       = "Walla Walla silt loam, 12 to 25 percent north slopes",
                        Components = new List <Component>()
                        {
                            new Component()
                            {
                                Cokey            = "17391362",
                                Name             = "Walla Walla",
                                PercentOfMapUnit = 75
                            }
                        }
                    }
                }
            };

            return(results);
        }