Compare commits

..

No commits in common. "49be089aedf6ee779514279af3324e2dece81a8c" and "a9a1c04dc870fbe9cc0ff9e764bd4c961fe101b3" have entirely different histories.

5 changed files with 6 additions and 185 deletions

View File

@ -1,104 +0,0 @@
import { NextResponse } from 'next/server';
interface Controller {
callsign: string;
frequency: string;
facility: number;
}
const facilityTypes = {
0: "OBS",
1: "FSS",
2: "DEL",
3: "GND",
4: "TWR",
5: "APP",
6: "CTR",
} as const;
const facilityLongNames = {
OBS: "Observer",
FSS: "Flight Service Station",
DEL: "Clearance Delivery",
GND: "Ground",
TWR: "Tower",
APP: "Approach/Departure",
CTR: "Centre",
} as const;
// Define FIR coverage for airports
const firCoverage: Record<string, string[]> = {
CZQM: ["CYHZ", "CYFC", "CYQM", "CYSJ", "CYZX", "CYYG", "CYYT", "CYQX", "CYYR", "LFVP", "CYQI", "CYAY", "CYDF", "CYJT"],
CZUL: ["CYZV"],
};
export async function GET() {
try {
const response = await fetch('https://data.vatsim.net/v3/vatsim-data.json', {
next: { revalidate: 60 }
});
if (!response.ok) {
throw new Error('Failed to fetch VATSIM data');
}
const data = await response.json();
// First, get all controllers including CTR
const allControllers = data.controllers.map((controller: Controller) => {
const shortFacility = facilityTypes[controller.facility as keyof typeof facilityTypes] || "Unknown";
return {
callsign: controller.callsign,
frequency: controller.frequency,
facility: shortFacility,
facilityLong: facilityLongNames[shortFacility as keyof typeof facilityLongNames] || "Unknown",
facilityType: controller.facility,
airport: controller.callsign.split('_')[0]
};
});
// Separate CTR controllers
const ctrControllers = allControllers.filter(c => c.facilityType === 6);
// Get non-CTR controllers
const localControllers = allControllers.filter(c => c.facilityType < 6 && c.facilityType > 0 && !c.callsign.includes("ATIS"));
// Group local controllers by airport
const controllersByAirport = localControllers.reduce((acc: any, controller) => {
if (!acc[controller.airport]) {
acc[controller.airport] = [];
}
acc[controller.airport].push(controller);
return acc;
}, {});
// Sort controllers at each airport by facility type (higher number = higher priority)
Object.values(controllersByAirport).forEach((controllers: any) => {
controllers.sort((a: any, b: any) => b.facilityType - a.facilityType);
});
// Add CTR coverage for airports without local controllers
ctrControllers.forEach(ctr => {
const fir = ctr.callsign.split('_')[0];
const coveredAirports = firCoverage[fir] || [];
coveredAirports.forEach(airport => {
// Only add CTR if no local controllers are available
if (!controllersByAirport[airport] || controllersByAirport[airport].length === 0) {
controllersByAirport[airport] = [{
callsign: ctr.callsign,
frequency: ctr.frequency,
facility: ctr.facility,
facilityLong: "Centre (Top-down)",
airport: airport
}];
}
});
});
return NextResponse.json(controllersByAirport);
} catch (error) {
console.error(error);
return NextResponse.json({ error: 'Failed to fetch controller data' }, { status: 500 });
}
}

View File

@ -10,7 +10,7 @@ export async function GET() {
headers: { headers: {
'Authorization': 'Bearer vmtkb1D8Tuva2Jw2tXihWcKE3m2sfDJkySBZygVx82I' 'Authorization': 'Bearer vmtkb1D8Tuva2Jw2tXihWcKE3m2sfDJkySBZygVx82I'
}, },
next: { revalidate: 300 } // Cache for 5 minutes next: { revalidate: 60 } // Cache for 1 minutes
}); });
if (!response.ok) return null; if (!response.ok) return null;

View File

@ -34,7 +34,7 @@ export async function GET(
.map((pilot) => ({ .map((pilot) => ({
callsign: pilot.callsign, callsign: pilot.callsign,
type: pilot.flight_plan.departure === icao ? 'Departure' : 'Arrival', type: pilot.flight_plan.departure === icao ? 'Departure' : 'Arrival',
time: pilot.flight_plan.departure === icao ? pilot.flight_plan.deptime : pilot.flight_plan.enroute_time, time: pilot.flight_plan.departure === icao ? pilot.flight_plan.deptime : pilot.flight_plan.arrival,
route: pilot.flight_plan.route, route: pilot.flight_plan.route,
origin: pilot.flight_plan.departure, origin: pilot.flight_plan.departure,
destination: pilot.flight_plan.arrival destination: pilot.flight_plan.arrival

View File

@ -1,6 +1,6 @@
"use client"; "use client";
import { useState, Fragment, useEffect } from "react"; import { useState, Fragment } from "react";
import { import {
Table, Table,
TableBody, TableBody,
@ -10,14 +10,7 @@ import {
TableRow, TableRow,
} from "@/components/ui/table"; } from "@/components/ui/table";
import { Skeleton } from "@/components/ui/skeleton"; import { Skeleton } from "@/components/ui/skeleton";
import { ChevronDown, ChevronUp, Plane, PlaneLanding, PlaneTakeoff, Radio } from "lucide-react"; import { ChevronDown, ChevronUp, Plane, PlaneLanding, PlaneTakeoff } from "lucide-react";
import { Badge } from "@/components/ui/badge";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
interface Flight { interface Flight {
callsign: string; callsign: string;
@ -28,13 +21,6 @@ interface Flight {
destination: string; destination: string;
} }
interface Controller {
callsign: string;
frequency: string;
facility: string;
facilityLong: string;
}
interface MetarTableProps { interface MetarTableProps {
data: any[]; data: any[];
loading: boolean; loading: boolean;
@ -44,25 +30,6 @@ export function MetarTable({ data, loading }: MetarTableProps) {
const [expandedAirport, setExpandedAirport] = useState<string | null>(null); const [expandedAirport, setExpandedAirport] = useState<string | null>(null);
const [flights, setFlights] = useState<Flight[]>([]); const [flights, setFlights] = useState<Flight[]>([]);
const [loadingFlights, setLoadingFlights] = useState(false); const [loadingFlights, setLoadingFlights] = useState(false);
const [controllers, setControllers] = useState<Record<string, Controller[]>>({});
// Fetch controller data
useEffect(() => {
async function fetchControllers() {
try {
const response = await fetch('/api/controllers');
const data = await response.json();
setControllers(data);
} catch (error) {
console.error('Failed to fetch controller data:', error);
}
}
fetchControllers();
// Refresh controller data every minute
const interval = setInterval(fetchControllers, 60000);
return () => clearInterval(interval);
}, []);
const handleAirportClick = async (airport: string) => { const handleAirportClick = async (airport: string) => {
if (expandedAirport === airport) { if (expandedAirport === airport) {
@ -83,19 +50,6 @@ export function MetarTable({ data, loading }: MetarTableProps) {
} }
}; };
const getBadgeVariant = (facility: string) => {
switch (facility) {
case 'CTR':
return "secondary";
case 'APP':
return "default";
case 'TWR':
return "default";
default:
return "outline";
}
};
if (loading) { if (loading) {
return <LoadingSkeleton />; return <LoadingSkeleton />;
} }
@ -111,7 +65,6 @@ export function MetarTable({ data, loading }: MetarTableProps) {
<TableHead>Headwind (kts)</TableHead> <TableHead>Headwind (kts)</TableHead>
<TableHead>Xwind (kts)</TableHead> <TableHead>Xwind (kts)</TableHead>
<TableHead>Altimeter</TableHead> <TableHead>Altimeter</TableHead>
<TableHead>ATC</TableHead>
<TableHead>METAR</TableHead> <TableHead>METAR</TableHead>
</TableRow> </TableRow>
</TableHeader> </TableHeader>
@ -142,38 +95,11 @@ export function MetarTable({ data, loading }: MetarTableProps) {
{row.crosswind} {row.crosswind}
</TableCell> </TableCell>
<TableCell>{row.altimeter}</TableCell> <TableCell>{row.altimeter}</TableCell>
<TableCell>
{controllers[row.airport] ? (
<div className="flex flex-col gap-1">
<TooltipProvider>
{controllers[row.airport].map((controller, i) => (
<Tooltip key={i}>
<TooltipTrigger>
<Badge
variant={getBadgeVariant(controller.facility)}
className="flex items-center gap-1 w-fit"
>
<Radio className="h-3 w-3" />
{controller.facility} {controller.frequency}
</Badge>
</TooltipTrigger>
<TooltipContent>
<p>{controller.facilityLong}</p>
<p className="text-xs text-muted-foreground">{controller.callsign}</p>
</TooltipContent>
</Tooltip>
))}
</TooltipProvider>
</div>
) : (
<span className="text-muted-foreground text-sm">Uncontrolled</span>
)}
</TableCell>
<TableCell className="font-mono text-sm">{row.metar}</TableCell> <TableCell className="font-mono text-sm">{row.metar}</TableCell>
</TableRow> </TableRow>
{expandedAirport === row.airport && ( {expandedAirport === row.airport && (
<TableRow> <TableRow>
<TableCell colSpan={9} className="p-0 bg-muted/50"> <TableCell colSpan={8} className="p-0 bg-muted/50">
{loadingFlights ? ( {loadingFlights ? (
<div className="p-4 space-y-2"> <div className="p-4 space-y-2">
<Skeleton className="h-8 w-full" /> <Skeleton className="h-8 w-full" />
@ -244,7 +170,6 @@ function LoadingSkeleton() {
<Skeleton className="h-4 w-[80px]" /> <Skeleton className="h-4 w-[80px]" />
<Skeleton className="h-4 w-[80px]" /> <Skeleton className="h-4 w-[80px]" />
<Skeleton className="h-4 w-[80px]" /> <Skeleton className="h-4 w-[80px]" />
<Skeleton className="h-4 w-[120px]" />
<Skeleton className="h-4 w-[200px]" /> <Skeleton className="h-4 w-[200px]" />
</div> </div>
))} ))}

View File

@ -36,7 +36,7 @@ export function getUTCtime() {
const now = new Date(); const now = new Date();
return `${String(now.getUTCHours()).padStart(2, "0")}:${String( return `${String(now.getUTCHours()).padStart(2, "0")}:${String(
now.getUTCMinutes() now.getUTCMinutes()
).padStart(2, "0")}Z`; ).padStart(2, "0")} UTC`;
} }
export function calculateAirportData(airportCode: string, data: any) { export function calculateAirportData(airportCode: string, data: any) {