SB fetch and entry
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
import { PaxConfig } from '../configs/pax';
|
||||
import { SharedConfig } from '../configs/shared';
|
||||
|
||||
const getSimBriefFlightPlan = async (simBriefUsername: string) => {
|
||||
const flightPlanURL = `https://www.simbrief.com/api/xml.fetcher.php?username=${simBriefUsername}&json=1`;
|
||||
let response: Response;
|
||||
@@ -19,9 +16,10 @@ const getSimBriefFlightPlan = async (simBriefUsername: string) => {
|
||||
|
||||
export const ImportFlightPlan = async (
|
||||
username: string,
|
||||
config: typeof PaxConfig,
|
||||
unit: 'kg' | 'lbs',
|
||||
isER: boolean
|
||||
maxZFW: number,
|
||||
maxTOW: number,
|
||||
maxFuel: number,
|
||||
isImperial: boolean
|
||||
) => {
|
||||
const flightPlan = await getSimBriefFlightPlan(username);
|
||||
if (!flightPlan.success) {
|
||||
@@ -41,23 +39,17 @@ export const ImportFlightPlan = async (
|
||||
}
|
||||
|
||||
let convFactor = 1;
|
||||
if (data.params.units === 'kgs' && unit === 'lbs') convFactor = 2.20462262185;
|
||||
if (data.params.units === 'lbs' && unit === 'kg') convFactor = 1 / 2.20462262185;
|
||||
if (data.params.units === 'kgs' && isImperial) convFactor = 2.20462262185;
|
||||
if (data.params.units === 'lbs' && !isImperial) convFactor = 1 / 2.20462262185;
|
||||
|
||||
return {
|
||||
type: 'data',
|
||||
message: {
|
||||
plannedZFW: Math.min(config.maxZWF[unit], Math.round(data.weights.est_zfw * convFactor)),
|
||||
plannedGW: Math.min(
|
||||
isER ? SharedConfig.maxTOW.er[unit] : SharedConfig.maxTOW.norm[unit],
|
||||
Math.round(data.weights.est_ramp * convFactor)
|
||||
),
|
||||
plannedZFW: Math.min(maxZFW, Math.round(data.weights.est_zfw * convFactor)),
|
||||
plannedGW: Math.min(maxTOW, Math.round(data.weights.est_ramp * convFactor)),
|
||||
pax: data.weights.pax_count_actual,
|
||||
cargo: Math.round(data.weights.freight_added * convFactor),
|
||||
fuel: Math.min(
|
||||
isER ? SharedConfig.maxFuel.er[unit] : SharedConfig.maxFuel.norm[unit],
|
||||
Math.round(data.fuel.plan_ramp * convFactor)
|
||||
),
|
||||
fuel: Math.min(maxFuel, Math.round(data.fuel.plan_ramp * convFactor)),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user