Skip to content

Commit

Permalink
Implemented method to compute GAFOR weather category
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankMurmann committed Jan 13, 2025
1 parent 181aa4d commit 5921f19
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.github.mivek.model;

import java.util.function.BiFunction;

public enum GAFORWeatherCategory implements WeatherCategory {

X((v, c) -> v < 1.5 && c < 500),
M2((v, c) -> v >= 8 && c < 1000),
M5((v, c) -> v >= 5 && v < 8 && c < 1000),
M6((v,c) -> v >= 1.5 && v < 5 && c >= 2000),
M7((v,c) -> v >= 1.5 && v < 5 && c >= 1000 && c < 2000),
M8((v,c) -> v >= 1.5 && v < 5 && c < 1000),
D1((v,c) -> v >= 8 && c >= 1000 && c < 2000),
D3((v,c) -> v >= 5 && v < 8 && c >= 2000),
D4((v,c) -> v >= 5 && v < 8 && c >= 1000 && c < 2000),
O((v,c) -> v >= 8 && c >= 2000 && c < 5000),
C((v, c) -> v >= 10 && c >= 5000);

private final BiFunction<Double, Integer, Boolean> criteriaFunction;

GAFORWeatherCategory(BiFunction<Double, Integer, Boolean> criteriaFunction) {
this.criteriaFunction = criteriaFunction;
}

public boolean isCriteriaMet(double visibility, int ceiling) {
return criteriaFunction.apply(visibility, ceiling);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ public interface WeatherCategory {

Class<ICAOWeatherCategory> ICAO = ICAOWeatherCategory.class;

Class<GAFORWeatherCategory> GAFOR = GAFORWeatherCategory.class;

boolean isCriteriaMet(double visibility, int ceiling);
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,34 @@ void computeICAOWeatherCategory(Integer altitude, String mainVisibility, Integer
assertThat(result, is(expected));
}

@DisplayName("should compute GAFOR weather category")
@ParameterizedTest
@MethodSource
void computeGAFORWeatherCategory(Integer altitude, String mainVisibility, Integer ceiling, GAFORWeatherCategory 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);

GAFORWeatherCategory result = metar.getWeatherCategory(WeatherCategory.GAFOR);

assertThat(result, is(expected));
}

public static Stream<Arguments> computeFAAWeatherCategory() {
return Stream.of(
Arguments.of(500, "notParsable", 5000, null),
Expand Down Expand Up @@ -164,4 +192,20 @@ public static Stream<Arguments> computeICAOWeatherCategory() {
Arguments.of(500, "4SM", 4000, ICAOWeatherCategory.VMC),
Arguments.of(500, "10SM", 5000, ICAOWeatherCategory.VMC));
}

public static Stream<Arguments> computeGAFORWeatherCategory() {
return Stream.of(
Arguments.of(500, "notParsable", 5000, null),
Arguments.of(500, "500m", 800, GAFORWeatherCategory.X),
Arguments.of(500, "10km", 300, GAFORWeatherCategory.M2),
Arguments.of(500, "6km", 300, GAFORWeatherCategory.M5),
Arguments.of(500, "2km", 2500, GAFORWeatherCategory.M6),
Arguments.of(500, "2km", 1600, GAFORWeatherCategory.M7),
Arguments.of(500, "2km", 800, GAFORWeatherCategory.M8),
Arguments.of(500, "10SM", 2000, GAFORWeatherCategory.D1),
Arguments.of(500, "6km", 2500, GAFORWeatherCategory.D3),
Arguments.of(500, "6km", 2000, GAFORWeatherCategory.D4),
Arguments.of(500, "10SM", 3000, GAFORWeatherCategory.O),
Arguments.of(500, "10SM", 6000, GAFORWeatherCategory.C));
}
}

0 comments on commit 5921f19

Please sign in to comment.