Skip to content

Commit

Permalink
Merge pull request #429 from mivek/bugfix/ParseWeatherCondition
Browse files Browse the repository at this point in the history
Bugfix parse weather condition
  • Loading branch information
mivek authored Nov 19, 2022
2 parents ba88c08 + 94017cf commit f7c6ef0
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sonar-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
name: Build and analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public String toString() {
return Messages.getInstance().getString("Converter." + key);
}

/**
* Returns a trend given a token.
* @param input String representing a trend.
* @return The RunwayInfoTrend object.
*/
public static RunwayInfoTrend get(final String input) {
return Arrays.stream(RunwayInfoTrend.values())
.filter(trend -> trend.shortcut.equals(input))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public final class HourlyMaximumMinimumTemperatureCommand implements Command {
/** The message instance. */
private final Messages messages;

/**
* Constructor.
*/
HourlyMaximumMinimumTemperatureCommand() {
this.messages = Messages.getInstance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public final class HourlyPressureCommand implements Command {
/** The message instance. */
private final Messages messages;

/**
* Constructor.
*/
HourlyPressureCommand() {
this.messages = Messages.getInstance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public final class HourlyTemperatureDewPointCommand implements Command {
/** The message instance. */
private final Messages messages;

/**
* Constructor.
*/
HourlyTemperatureDewPointCommand() {
this.messages = Messages.getInstance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public final class IceAccretionCommand implements Command {
/** The message instance. */
private final Messages messages;

/**
* Constructor.
*/
IceAccretionCommand() {
this.messages = Messages.getInstance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public final class PrecipitationAmount24HourCommand implements Command {
/** The message instance. */
private final Messages messages;

/**
* Constructor.
*/
PrecipitationAmount24HourCommand() {
this.messages = Messages.getInstance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public final class PrecipitationAmount36HourCommand implements Command {
/** The message instance. */
private final Messages messages;

/**
* Constructor.
*/
PrecipitationAmount36HourCommand() {
this.messages = Messages.getInstance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public final class SnowDepthCommand implements Command {
/** The message instance. */
private final Messages messages;

/**
* Constructor.
*/
SnowDepthCommand() {
this.messages = Messages.getInstance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public final class SunshineDurationCommand implements Command {
/** The message instance. */
private final Messages messages;

/**
* Constructor.
*/
SunshineDurationCommand() {
this.messages = Messages.getInstance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public final class WaterEquivalentSnowCommand implements Command {
/** The message instance. */
private final Messages messages;

/**
* Constructor.
*/
WaterEquivalentSnowCommand() {
this.messages = Messages.getInstance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,34 @@ public abstract class AbstractWeatherContainerParser<T extends AbstractWeatherCo
*/
WeatherCondition parseWeatherCondition(final String weatherPart) {
WeatherCondition wc = new WeatherCondition();
String weatherPartCopy = weatherPart;
String match;
if (Regex.find(INTENSITY_REGEX, weatherPart)) {
match = Regex.findString(INTENSITY_REGEX, weatherPart);
Intensity i = Intensity.getEnum(match);
wc.setIntensity(i);
weatherPartCopy = weatherPartCopy.substring(i.getShortcut().length());
}
for (Descriptive des : Descriptive.values()) {
if (Regex.findString(Pattern.compile("(" + des.getShortcut() + ")"), weatherPart) != null) {
wc.setDescriptive(des);
weatherPartCopy = weatherPartCopy.substring(des.getShortcut().length());
break;
}
}
for (Phenomenon phe : Phenomenon.values()) {
if (Regex.findString(Pattern.compile("(" + phe.getShortcut() + ")"), weatherPart) != null) {
wc.addPhenomenon(phe);

String previousToken = "";
while (!weatherPartCopy.isEmpty() && !weatherPartCopy.equals(previousToken)) {
previousToken = weatherPartCopy;
for (Phenomenon phenom: Phenomenon.values()) {
if (Regex.find(Pattern.compile("^" + phenom.getShortcut()), weatherPartCopy)) {
wc.addPhenomenon(phenom);
weatherPartCopy = weatherPartCopy.substring(phenom.getShortcut().length());
}
}
}
if (wc.isValid()) {

if (wc.isValid() && weatherPartCopy.isEmpty()) {
return wc;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@ void testParseWCDescriptiveIsNotNullButPhenomenonCanBeEmptyAndIntensityCanBeNull

assertNull(wc);
}

@Test
void testParseWeatherConditionOrder() {
WeatherCondition wc = getParser().parseWeatherCondition("-SNRA");

assertNotNull(wc);
assertEquals(Intensity.LIGHT, wc.getIntensity());
assertNull(wc.getDescriptive());
assertThat(wc.getPhenomenons(), hasSize(2));
assertEquals(Phenomenon.SNOW, wc.getPhenomenons().get(0));
assertEquals(Phenomenon.RAIN, wc.getPhenomenons().get(1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -857,4 +857,17 @@ void testParseWithIcingAndTurbulenceTrends() throws ParseException {
assertThat(taf.getBECMGs().get(5).getIcings(), hasSize(1));
assertThat(taf.getBECMGs().get(5).getTurbulences(), hasSize(2));
}

@Test
void testParseWithAMDS() throws ParseException {
String code = """
TAF AMD KVOK 232200Z 2322/2423 15015G20KT 9999 BKN035 BKN050 510008 QNH2966INS
BECMG 2411/2412 17012KT 9000 -SHRA FEW006 BKN014 OVC021 510065 QNH2965INS TX24/2322Z TN16/2413Z LAST NO AMDS AFT 2322 NEXT 2409""";

TAF taf = parser.parse(code);

assertNotNull(taf);
assertThat(taf.getWeatherConditions(), empty());
assertThat(taf.getBECMGs().get(0).getWeatherConditions(), hasSize(1));
}
}
Binary file modified model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
<opencsv.version>5.7.1</opencsv.version>
<pitest-junit5-plugin.version>1.1.0</pitest-junit5-plugin.version>
<pitest-maven.version>1.9.10</pitest-maven.version>
<slf4j-nop.version>2.0.3</slf4j-nop.version>
<pitest-maven.version>1.9.11</pitest-maven.version>
<slf4j-nop.version>2.0.4</slf4j-nop.version>
<spotbugs-maven-plugin.version>4.7.3.0</spotbugs-maven-plugin.version>
<sonar.organization>mivek-github</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
Expand Down

0 comments on commit f7c6ef0

Please sign in to comment.