From 39e68bbbca7efea93cb5d804c05da9afbcaf11d9 Mon Sep 17 00:00:00 2001 From: FrankMurmann Date: Fri, 10 Jan 2025 16:52:44 +0100 Subject: [PATCH] Implemented method to compute military weather category --- .../mivek/model/MilitaryWeatherCategory.java | 23 +++++++++++ .../github/mivek/model/WeatherCategory.java | 2 + .../java/io/github/mivek/model/MetarTest.java | 39 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 metarParser-entities/src/main/java/io/github/mivek/model/MilitaryWeatherCategory.java diff --git a/metarParser-entities/src/main/java/io/github/mivek/model/MilitaryWeatherCategory.java b/metarParser-entities/src/main/java/io/github/mivek/model/MilitaryWeatherCategory.java new file mode 100644 index 00000000..653a88dd --- /dev/null +++ b/metarParser-entities/src/main/java/io/github/mivek/model/MilitaryWeatherCategory.java @@ -0,0 +1,23 @@ +package io.github.mivek.model; + +import java.util.function.BiFunction; + +public enum MilitaryWeatherCategory implements WeatherCategory { + + RED((v, c) -> c < 200 && v < 0.8), + AMB((v, c) -> c >= 200 && c < 300 && v >= 0.8 && v < 1.6), + YLO((v, c) -> c >= 300 && c < 700 && v >= 1.6 && v < 3.7), + GRN((v, c) -> c >= 700 && c < 1500 && v >= 3.7 && v < 5.0), + WHT((v, c) -> c >= 1500 && c < 2500 && v >= 5.0 && v < 8.0), + BLU((v, c) -> c >= 2500 && v >= 8.0); + + private final BiFunction criteriaFunction; + + MilitaryWeatherCategory(BiFunction criteriaFunction) { + this.criteriaFunction = criteriaFunction; + } + + public boolean isCriteriaMet(double visibility, int ceiling) { + return criteriaFunction.apply(visibility, ceiling); + } +} diff --git a/metarParser-entities/src/main/java/io/github/mivek/model/WeatherCategory.java b/metarParser-entities/src/main/java/io/github/mivek/model/WeatherCategory.java index 1aed0470..b6c9998e 100644 --- a/metarParser-entities/src/main/java/io/github/mivek/model/WeatherCategory.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/WeatherCategory.java @@ -8,5 +8,7 @@ public interface WeatherCategory { Class GAFOR = GAFORWeatherCategory.class; + Class MILITARY = MilitaryWeatherCategory.class; + boolean isCriteriaMet(double visibility, int ceiling); } diff --git a/metarParser-entities/src/test/java/io/github/mivek/model/MetarTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/MetarTest.java index 9ac76028..a1846bfa 100644 --- a/metarParser-entities/src/test/java/io/github/mivek/model/MetarTest.java +++ b/metarParser-entities/src/test/java/io/github/mivek/model/MetarTest.java @@ -153,6 +153,34 @@ void computeGAFORWeatherCategory(Integer altitude, String mainVisibility, Intege assertThat(result, is(expected)); } + @DisplayName("should compute military weather category") + @ParameterizedTest + @MethodSource + void computeMilitaryWeatherCategory(Integer altitude, String mainVisibility, Integer ceiling, MilitaryWeatherCategory expected) { + Airport airport = new Airport(); + airport.setAltitude(altitude); + Visibility visibility = new Visibility(); + visibility.setMainVisibility(mainVisibility); + metar.setAirport(airport); + metar.setVisibility(visibility); + Cloud cloudLow = new Cloud(); + cloudLow.setHeight(200); + cloudLow.setQuantity(CloudQuantity.FEW); + Cloud cloudMid = new Cloud(); + cloudMid.setHeight(ceiling); + cloudMid.setQuantity(CloudQuantity.BKN); + Cloud cloudHigh = new Cloud(); + cloudHigh.setHeight(10000); + cloudHigh.setQuantity(CloudQuantity.SCT); + metar.addCloud(cloudLow); + metar.addCloud(cloudMid); + metar.addCloud(cloudHigh); + + MilitaryWeatherCategory result = metar.getWeatherCategory(WeatherCategory.MILITARY); + + assertThat(result, is(expected)); + } + public static Stream computeFAAWeatherCategory() { return Stream.of( Arguments.of(500, "notParsable", 5000, null), @@ -208,4 +236,15 @@ public static Stream computeGAFORWeatherCategory() { Arguments.of(500, "10SM", 3000, GAFORWeatherCategory.O), Arguments.of(500, "10SM", 6000, GAFORWeatherCategory.C)); } + + public static Stream computeMilitaryWeatherCategory() { + return Stream.of( + Arguments.of(500, "notParsable", 5000, null), + Arguments.of(500, "500m", 600, MilitaryWeatherCategory.RED), + Arguments.of(500, "1000m", 750, MilitaryWeatherCategory.AMB), + Arguments.of(500, "2000m", 1000, MilitaryWeatherCategory.YLO), + Arguments.of(500, "4000m", 1300, MilitaryWeatherCategory.GRN), + Arguments.of(500, "6000m", 2300, MilitaryWeatherCategory.WHT), + Arguments.of(500, "10SM", 6000, MilitaryWeatherCategory.BLU)); + } }