Skip to content

Commit

Permalink
style: format code with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Mar 28, 2023
1 parent f724033 commit 5e5fc65
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions packages/rpl-crawler/src/flight-decoder/flight-decoder.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
import Flight, { FlightRules, WakeTurbulence } from '@mach/common'
import Flight, { FlightRules, WakeTurbulence } from "@mach/common";
import {
resolveEstimatedEnrouteMinutes,
resolveFlightDate,
resolveFlightRules,
resolveWeekDays
} from './flight-decoder-utils'
resolveWeekDays,
} from "./flight-decoder-utils";

const makeFlightDecoder = ({ uuid }: { uuid: (line: string) => string }) => {
return (line: string): Flight => {
const LINES = line.split("\n").map(line => line.trim())
const LINES = line.split("\n").map((line) => line.trim());

const LINE_1 = LINES[0];
const callsign = LINE_1.match(/[A-Z]{3}\d+/)[0]
const beginDate = resolveFlightDate(LINE_1.match(/(?<= )\d{6}(?= (\d| ))/)[0]);
const endDate = LINE_1.match(/(?<= )(\d{6}|( ){6})(?= [I|V|Y|Z])/)[0]
const callsign = LINE_1.match(/[A-Z]{3}\d+/)[0];
const beginDate = resolveFlightDate(
LINE_1.match(/(?<= )\d{6}(?= (\d| ))/)[0]
);
const endDate = LINE_1.match(/(?<= )(\d{6}|( ){6})(?= [I|V|Y|Z])/)[0];
const company = callsign.match(/[A-Z]+/)[0];
const flightNumber = Number(callsign.match(/\d+/)[0]);
const departureIcao = LINE_1.substr(-9, 4);
const estimatedOffBlockTime = LINE_1.match(/\d{4}$/)[0]
const flightRules = LINE_1.match(/(?<= ).(?=[A-Z] )/)[0]
const estimatedOffBlockTime = LINE_1.match(/\d{4}$/)[0];
const flightRules = LINE_1.match(/(?<= ).(?=[A-Z] )/)[0];
const weekDays = LINE_1.match(/(?<= )(\d| ){7}(?= )/)[0].trim();

const LINE_2 = LINES[1]
const LINE_2 = LINES[1];
const cruisingSpeed = LINE_2.match(/(?<=\/)N\d+/)[0];
const cruisingLevel = Number(LINE_2.match(/(?<=F)\d+/)[0]);
const route = LINE_2.match(/(?<=\/N\d+F\d+ ).*/)[0]
const route = LINE_2.match(/(?<=\/N\d+F\d+ ).*/)[0];

const LINE_3 = LINES[2]
const arrivalIcao = LINE_3.substring(0, 4)
const estimatedEnrouteMinutes = resolveEstimatedEnrouteMinutes((LINE_3.match(/\d{4}/) ?? ["0000"])[0])
const remarks = LINE_3.substring(13)
const LINE_3 = LINES[2];
const arrivalIcao = LINE_3.substring(0, 4);
const estimatedEnrouteMinutes = resolveEstimatedEnrouteMinutes(
(LINE_3.match(/\d{4}/) ?? ["0000"])[0]
);
const remarks = LINE_3.substring(13);

const aircraft = {
icaoCode: LINE_1.match(/[A-Z0-9]+(?=(\/(M|L|H|J)))/)[0],
wakeTurbulence: LINE_1.match(/(?<=\/)(M|L|H|J)/)[0] as WakeTurbulence,
equipment: remarks.match(/(?<=EQPT\/)[^\s]+/)[0]
}
equipment: remarks.match(/(?<=EQPT\/)[^\s]+/)[0],
};

return {
id: uuid(line),
Expand All @@ -54,9 +58,9 @@ const makeFlightDecoder = ({ uuid }: { uuid: (line: string) => string }) => {
flightRules: resolveFlightRules(route),
weekdays: resolveWeekDays(weekDays),
beginDate,
endDate: endDate.trim() ? resolveFlightDate(endDate) : null
}
}
}
endDate: endDate.trim() ? resolveFlightDate(endDate) : null,
};
};
};

export default makeFlightDecoder
export default makeFlightDecoder;

0 comments on commit 5e5fc65

Please sign in to comment.