Skip to content

Commit

Permalink
Merge pull request #425 from mivek/bugfix/Unknown_CloudType
Browse files Browse the repository at this point in the history
Bugfix/unknown cloud type
  • Loading branch information
mivek authored Nov 13, 2022
2 parents 32d61f1 + d3f9be2 commit 1089cb3
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 20 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/sonar-master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: SonarCloud
on:
push:
branches:
- master
jobs:
build:
name: Build and analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
cache: 'maven'
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=io.github.mivek:metarParser
47 changes: 35 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,23 @@ When updating classes, regenerate the diagrams and save the images in the projec

The application contains numerous enumerations to represent data.

- CloudType: to represent the type of cloud.
- CloudQuantity: to represent the amount of clouds.
- Intensity: to represent the intensity of a meteorological phenomenon.
- Descriptive: to represent the description of a meteorological phenomenon.
- DepositType: to represent the type of deposit on a runway.
- DepositCoverage: to represent the percentage of the runway covered by the deposit.
- DepositThickness: to represent the thickness of the deposit.
- DepositBrakingCapacity: to represent the braking capacity on the runway.
- Phenomenon: to represent a phenomenon.
- RunwayInfoTrend: to represent the visibility trend on a runway.
- WeatherChangeTime: to represent a trend.
- TimeIndicator: to represent the time of the trend.
- CloudType: Represents the type of cloud.
- CloudQuantity: Represents the amount of clouds.
- DepositBrakingCapacity: Represents the breaking capacity on a runway.
- DepositCoverage: Represents the percentage of a runway covered by deposit.
- DepositThickness: Represents the thickness of a deposit on a runway.
- DepositType: Represents the type of deposit on a runway.
- DepositType: Represents the type of deposit on a runway.
- Descriptive: Represents the description of a meteorological phenomenon.
- Flag: Represents a flag applied to a METAR or TAF: AMD, AUTO, CNL, COR or NIL.
- IcingIntensity: Represents the intensity of an icing element.
- Intensity: Represents the intensity of a meteorological phenomenon.
- Phenomenon: Represents a phenomenon.
- RunwayInfoIndicator: Represents the indicator on a runway.
- RunwayInfoTrend: Represents the visibility trend on a runway.
- TimeIndicator: Represents the time of the trend.
- TurbulenceIntensity: Represents the intensity of a turbulence
- WeatherChangeType: Represents a type of trend.

### Classes

Expand Down Expand Up @@ -99,6 +104,15 @@ In this application a cloud is composed of

A country is represented by its name.

#### Icing

The icing are only available in TAF and in TAFTrends.
It is composed of

- The icing intensity
- The base height
- The layer's depth

#### Runway information

The runway information can represent either a visual range or a deposit.
Expand All @@ -117,6 +131,15 @@ The runway information is composed of
- The thickness of the deposit.
- The braking capacity on the runway.

#### Turbulence

The turbulence are only available in TAF and in TAFTrends.
It is composed of:

- The turbulence intensity
- The base height
- The layer's depth

#### Visibility

The visibility class is composed of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
*/
public final class CloudCommand implements Command {
/** Pattern to recognize clouds. */
private static final Pattern CLOUD_REGEX = Pattern.compile("^([A-Z]{3})(\\d{3})?([A-Z]{2,3})?$");

private static final Pattern CLOUD_REGEX = Pattern.compile("^(\\p{Upper}{3})(\\d{3}|/{3})?(\\p{Upper}{2,3}|/{3})?$");
/** String to identify the unknown part in a cloud. */
private static final String UNDEFINED = "///";
/**
* constructor.
*/
Expand All @@ -39,12 +40,12 @@ Cloud parseCloud(final String cloudString) {
try {
CloudQuantity cq = CloudQuantity.valueOf(cloudPart[1]);
cloud.setQuantity(cq);
if (cloudPart[2] != null) {
if (cloudPart[2] != null && !UNDEFINED.equals(cloudPart[2])) {
cloud.setHeight(100 * Integer.parseInt(cloudPart[2]));
if (cloudPart[3] != null) {
CloudType ct = CloudType.valueOf(cloudPart[3]);
cloud.setType(ct);
}
}
if (cloudPart[3] != null && !UNDEFINED.equals(cloudPart[3])) {
CloudType ct = CloudType.valueOf(cloudPart[3]);
cloud.setType(ct);
}
return cloud;
} catch (IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,25 @@ void testParseCloudWithNSC() {
assertEquals(CloudQuantity.NSC, res.getQuantity());
}

@Test
void testParseUnknownCloudType() {
String code = "SCT026///";

Cloud res = command.parseCloud(code);
assertNotNull(res);
assertEquals(CloudQuantity.SCT, res.getQuantity());
assertEquals(2600, res.getHeight());
assertNull(res.getType());
}
@Test
void testParseUnknownHeightAndUnknownCloudType() {
String code = "SCT//////";

Cloud res = command.parseCloud(code);
assertNotNull(res);
assertEquals(CloudQuantity.SCT, res.getQuantity());
assertNull(res.getHeight());
assertNull(res.getType());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -409,4 +409,15 @@ void testParseNil() {
Metar m = parser.parse(code);
assertTrue(m.isNil());
}

@Test
void testParseWithUnknownCloudType() {
String code = "EKVG 291550Z AUTO 13009KT 9999 BKN037/// BKN048/// 07/06 Q1009 RMK FEW011/// FEW035/// WIND SKEID 13020KT";

Metar m = parser.parse(code);

assertNotNull(m);
assertEquals("EKVG", m.getStation());
assertThat(m.getClouds(), hasSize(2));
}
}
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.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<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.9</pitest-maven.version>
<pitest-maven.version>1.9.10</pitest-maven.version>
<slf4j-nop.version>2.0.3</slf4j-nop.version>
<spotbugs-maven-plugin.version>4.7.3.0</spotbugs-maven-plugin.version>
<sonar.organization>mivek-github</sonar.organization>
Expand Down

0 comments on commit 1089cb3

Please sign in to comment.