56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import type { FlightParameters } from '../../src/lib/domain/scenario';
|
|
|
|
/**
|
|
* Generate a fake prediction trajectory. We fake an ascent phase that climbs
|
|
* to burst_altitude at ascent_rate, then a descent at descent_rate. The
|
|
* ground track drifts roughly east as a function of altitude to loosely
|
|
* mimic wind drift.
|
|
*/
|
|
export function fakePrediction(params: FlightParameters & { launch_datetime: string }) {
|
|
const launch = new Date(params.launch_datetime);
|
|
const ascentDurationSec = Math.round(
|
|
(params.burst_altitude - params.launch_altitude) / params.ascent_rate,
|
|
);
|
|
const descentDurationSec = Math.round(params.burst_altitude / params.descent_rate);
|
|
const stepSec = 30;
|
|
|
|
const ascent: unknown[] = [];
|
|
for (let t = 0; t <= ascentDurationSec; t += stepSec) {
|
|
const alt = params.launch_altitude + t * params.ascent_rate;
|
|
ascent.push({
|
|
altitude: alt,
|
|
datetime: new Date(launch.getTime() + t * 1000).toISOString(),
|
|
latitude: params.launch_latitude + t * 0.00002,
|
|
longitude: params.launch_longitude + t * 0.00005,
|
|
});
|
|
}
|
|
|
|
const descent: unknown[] = [];
|
|
const burstTime = launch.getTime() + ascentDurationSec * 1000;
|
|
const burstLat = params.launch_latitude + ascentDurationSec * 0.00002;
|
|
const burstLng = params.launch_longitude + ascentDurationSec * 0.00005;
|
|
for (let t = 0; t <= descentDurationSec; t += stepSec) {
|
|
const alt = Math.max(0, params.burst_altitude - t * params.descent_rate);
|
|
descent.push({
|
|
altitude: alt,
|
|
datetime: new Date(burstTime + t * 1000).toISOString(),
|
|
latitude: burstLat + t * 0.00001,
|
|
longitude: burstLng + t * 0.00003,
|
|
});
|
|
}
|
|
|
|
return {
|
|
result: {
|
|
metadata: {
|
|
start_datetime: new Date(launch.getTime() - 3600 * 1000).toISOString(),
|
|
complete_datetime: new Date(
|
|
burstTime + descentDurationSec * 1000,
|
|
).toISOString(),
|
|
},
|
|
prediction: [
|
|
{ stage: 'ascent', trajectory: ascent },
|
|
{ stage: 'descent', trajectory: descent },
|
|
],
|
|
},
|
|
};
|
|
}
|