Skip to content

Commit

Permalink
fix: solve tcu and cb clouds issue
Browse files Browse the repository at this point in the history
  • Loading branch information
brunorrr committed Feb 10, 2024
1 parent acd1c2c commit 6e2abdd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions src/helpers/metar-resolver/metar-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,11 @@ export class MetarResolver {
rvr: +rvr.substring(3, 7),
trend: rvr.substring(7) as 'D' | 'U' | 'N',
})) || undefined;
const cloudLayers = clouds.trim().split(' ').map((cloudLayer: string): { type: 'NCD' | 'NSC' | 'VV' | 'FEW' | 'BKN' | 'SCT' | 'OVC', height: number } => {
const cloudType = cloudLayer.substring(0, 3);
return {
type: cloudType as 'NCD' | 'NSC' | 'VV' | 'FEW' | 'BKN' | 'SCT' | 'OVC',
height: cloudLayer.substring(3) === '///' ? 0 : +cloudLayer.substring(3),
};
});
return {
horizontalVisibility: visibilityGroup,
rvr: rvrGroup,
isCavok: isCavok,
cloudLayers: cloudLayers,
cloudLayers: this.processCloudsLayers(clouds),
};
}

Expand Down Expand Up @@ -146,4 +139,14 @@ export class MetarResolver {
if(magWindDirection < 0) magWindDirection += 360;
return magWindDirection;
}

private static processCloudsLayers(clouds: string): { type: 'NCD' | 'NSC' | 'VV' | 'FEW' | 'BKN' | 'SCT' | 'OVC', height: string }[] {
return clouds.trim().split(' ').map((cloudLayer: string): { type: 'NCD' | 'NSC' | 'VV' | 'FEW' | 'BKN' | 'SCT' | 'OVC', height: string } => {
const cloudType = cloudLayer.substring(0, 3);
return {
type: cloudType as 'NCD' | 'NSC' | 'VV' | 'FEW' | 'BKN' | 'SCT' | 'OVC',
height: cloudLayer.substring(3) === '///' ? '000' : cloudLayer.substring(3, 6).padStart(3, '0').concat(cloudLayer.substring(6)),
};
});
}
}
2 changes: 1 addition & 1 deletion src/interfaces/splitted-metar.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface Visibility {
isCavok: boolean,
cloudLayers: {
type: 'NCD' | 'NSC' | 'VV' | 'FEW' | 'BKN' | 'SCT' | 'OVC',
height: number
height: string
}[]
}

Expand Down

0 comments on commit 6e2abdd

Please sign in to comment.