Added Notifications
This commit is contained in:
@@ -33,7 +33,6 @@ function getDateParts(f: Flight): { year: number; month: number; day: number } {
|
||||
// ── Per year / month / day ────────────────────────────────────────────────────
|
||||
|
||||
export function getFlightsPerYear(flights: Flight[], upcomingFlights: Flight[]) {
|
||||
console.time('getFlightsPerYear')
|
||||
const allFlights = [...flights, ...upcomingFlights]
|
||||
|
||||
const allYears = new Set(allFlights.map(f => getDateParts(f).year))
|
||||
@@ -57,12 +56,10 @@ export function getFlightsPerYear(flights: Flight[], upcomingFlights: Flight[])
|
||||
{ name: 'Upcoming', data: countByYear(upcomingFlights) },
|
||||
],
|
||||
}
|
||||
console.timeEnd('getFlightsPerYear')
|
||||
return result
|
||||
}
|
||||
|
||||
export function getFlightsPerMonth(flights: Flight[], upcomingFlights: Flight[]) {
|
||||
console.time('getFlightsPerMonth')
|
||||
const countByMonth = (list: Flight[]) =>
|
||||
MONTHS.map((_, i) => list.filter(f => getDateParts(f).month === i).length)
|
||||
|
||||
@@ -73,12 +70,10 @@ export function getFlightsPerMonth(flights: Flight[], upcomingFlights: Flight[])
|
||||
{ name: 'Upcoming', data: countByMonth(upcomingFlights) },
|
||||
],
|
||||
}
|
||||
console.timeEnd('getFlightsPerMonth')
|
||||
return result
|
||||
}
|
||||
|
||||
export function getFlightsPerDay(flights: Flight[], upcomingFlights: Flight[]) {
|
||||
console.time('getFlightsPerDay')
|
||||
const countByDay = (list: Flight[]) =>
|
||||
DAYS.map((_, i) => list.filter(f => getDateParts(f).day === i).length)
|
||||
|
||||
@@ -89,7 +84,6 @@ export function getFlightsPerDay(flights: Flight[], upcomingFlights: Flight[]) {
|
||||
{ name: 'Upcoming', data: countByDay(upcomingFlights) },
|
||||
],
|
||||
}
|
||||
console.timeEnd('getFlightsPerDay')
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -109,23 +103,17 @@ function groupByName(flights: Flight[], accessor: (f: Flight) => string) {
|
||||
}
|
||||
|
||||
export function getFlightReasons(flights: Flight[]) {
|
||||
console.time('getFlightReasons')
|
||||
const result = groupByName(flights, f => f.flight_reason?.name ?? 'Unknown')
|
||||
console.timeEnd('getFlightReasons')
|
||||
return result
|
||||
}
|
||||
|
||||
export function getFlightClasses(flights: Flight[]) {
|
||||
console.time('getFlightClasses')
|
||||
const result = groupByName(flights, f => f.flight_class?.name ?? 'Unknown')
|
||||
console.timeEnd('getFlightClasses')
|
||||
return result
|
||||
}
|
||||
|
||||
export function getSeatTypes(flights: Flight[]) {
|
||||
console.time('getSeatTypes')
|
||||
const result = groupByName(flights, f => f.seat_type?.name ?? 'Unknown')
|
||||
console.timeEnd('getSeatTypes')
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -152,7 +140,6 @@ function countCountries(flights: Flight[]) {
|
||||
}
|
||||
|
||||
export function getCountries(flights: Flight[], upcomingFlights: Flight[]) {
|
||||
console.time('getCountries')
|
||||
const past = countCountries(flights)
|
||||
const upcoming = countCountries(upcomingFlights)
|
||||
const allNames = new Set([...past.keys(), ...upcoming.keys()])
|
||||
@@ -173,14 +160,12 @@ export function getCountries(flights: Flight[], upcomingFlights: Flight[]) {
|
||||
{ name: 'Upcoming', data: sorted.map(s => s.upcoming) },
|
||||
],
|
||||
}
|
||||
console.timeEnd('getCountries')
|
||||
return result
|
||||
}
|
||||
|
||||
// ── Continents ────────────────────────────────────────────────────────────────
|
||||
|
||||
export function getContinents(flights: Flight[]) {
|
||||
console.time('getContinents')
|
||||
const counts = new Map<string, number>()
|
||||
flights.forEach(f => {
|
||||
const continents = new Set<string>()
|
||||
@@ -195,7 +180,6 @@ export function getContinents(flights: Flight[]) {
|
||||
labels: sorted.map(([name]) => name),
|
||||
series: sorted.map(([, count]) => count),
|
||||
}
|
||||
console.timeEnd('getContinents')
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -214,7 +198,6 @@ function countAirlines(flights: Flight[]) {
|
||||
}
|
||||
|
||||
export function getTopAirlines(flights: Flight[], upcomingFlights: Flight[]) {
|
||||
console.time('getTopAirlines')
|
||||
const past = countAirlines(flights)
|
||||
const upcoming = countAirlines(upcomingFlights)
|
||||
const allNames = new Set([...past.keys(), ...upcoming.keys()])
|
||||
@@ -236,7 +219,6 @@ export function getTopAirlines(flights: Flight[], upcomingFlights: Flight[]) {
|
||||
{ name: 'Upcoming', data: sorted.map(s => s.upcoming) },
|
||||
],
|
||||
}
|
||||
console.timeEnd('getTopAirlines')
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -256,7 +238,6 @@ function airportLabel(airport: Airport | null | undefined): string | null {
|
||||
}
|
||||
|
||||
export function getTopAirports(flights: Flight[], upcomingFlights: Flight[]) {
|
||||
console.time('getTopAirports')
|
||||
const map = new Map<string, AirportItem>()
|
||||
const empty = (): AirportItem => ({ departures: 0, arrivals: 0, upcoming: 0, label: '', fullName: '' })
|
||||
|
||||
@@ -313,7 +294,6 @@ export function getTopAirports(flights: Flight[], upcomingFlights: Flight[]) {
|
||||
{ name: 'Upcoming', data: sorted.map(s => s.upcoming) },
|
||||
],
|
||||
}
|
||||
console.timeEnd('getTopAirports')
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -421,7 +401,6 @@ export function getTopRoutes(flights: Flight[], upcomingFlights: Flight[]) {
|
||||
// ── Flight types ──────────────────────────────────────────────────────────────
|
||||
|
||||
export function getFlightTypes(flights: Flight[]) {
|
||||
console.time('getFlightTypes')
|
||||
const counts = { International: 0, Domestic: 0 }
|
||||
flights.forEach(f => {
|
||||
const dep = f.departure_airport.region?.country?.id
|
||||
@@ -435,7 +414,6 @@ export function getFlightTypes(flights: Flight[]) {
|
||||
labels: sorted.map(([name]) => name),
|
||||
series: sorted.map(([, count]) => count),
|
||||
}
|
||||
console.timeEnd('getFlightTypes')
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -447,22 +425,16 @@ export function useFlightStats(flights: Ref<Flight[]>) {
|
||||
const now = new Date()
|
||||
|
||||
watch(flights, (list) => {
|
||||
console.time('dateCache warm')
|
||||
list.forEach(f => getDateParts(f))
|
||||
console.timeEnd('dateCache warm')
|
||||
}, { immediate: true })
|
||||
|
||||
const pastFlights = computed(() => {
|
||||
console.time('pastFlights')
|
||||
const result = flights.value.filter(f => new Date(f.departure_date) <= now)
|
||||
console.timeEnd('pastFlights')
|
||||
return result
|
||||
})
|
||||
|
||||
const upcomingFlights = computed(() => {
|
||||
console.time('upcomingFlights')
|
||||
const result = flights.value.filter(f => new Date(f.departure_date) > now)
|
||||
console.timeEnd('upcomingFlights')
|
||||
return result
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user