Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 26 additions & 7 deletions src/screens/CalendarScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,37 @@ export default function CalendarScreen() {
try {
const { arrivals, departures } = await fetchAirportScheduleRaw(airportCode);
const allF = [...arrivals, ...departures];

const ranges: { sTS: number, eTS: number, iso: string }[] = [];
Object.keys(localData).forEach(iso => {
const sh = localData[iso].find(e => e.title.includes('Lavoro'));
if (sh) {
const sTS = new Date(sh.startDate).getTime() / 1000;
const eTS = new Date(sh.endDate).getTime() / 1000;
const cnt = allF.filter(f => {
const ts = f.flight?.time?.scheduled?.arrival || f.flight?.time?.scheduled?.departure;
return ts && ts >= sTS && ts <= eTS;
}).length;
if (dict[iso]) dict[iso].flightCount = cnt; else dict[iso] = { weatherText: 'N/A', weatherIcon: '❓', flightCount: cnt };
ranges.push({
sTS: new Date(sh.startDate).getTime() / 1000,
eTS: new Date(sh.endDate).getTime() / 1000,
iso
});
}
});

const counts: Record<string, number> = {};
ranges.forEach(r => counts[r.iso] = 0);

allF.forEach(f => {
const ts = f.flight?.time?.scheduled?.arrival || f.flight?.time?.scheduled?.departure;
if (ts) {
for (const r of ranges) {
if (ts >= r.sTS && ts <= r.eTS) {
counts[r.iso]++;
Comment on lines +237 to +244
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new counting logic still scans every ranges entry for each flight (for (const r of ranges) inside allF.forEach), which keeps worst-case complexity at O(flights × ranges). If ranges can grow beyond a week (e.g., month view), consider indexing/sorting ranges (e.g., sort by sTS and use a sweep/binary search, or bucket by ISO day) to avoid a full ranges scan per flight.

Suggested change
ranges.forEach(r => counts[r.iso] = 0);
allF.forEach(f => {
const ts = f.flight?.time?.scheduled?.arrival || f.flight?.time?.scheduled?.departure;
if (ts) {
for (const r of ranges) {
if (ts >= r.sTS && ts <= r.eTS) {
counts[r.iso]++;
const rangesByDay: Record<number, { sTS: number, eTS: number, iso: string }[]> = {};
ranges.forEach(r => {
counts[r.iso] = 0;
const startDay = Math.floor(r.sTS / 86400);
const endDay = Math.floor(r.eTS / 86400);
for (let day = startDay; day <= endDay; day++) {
if (!rangesByDay[day]) rangesByDay[day] = [];
rangesByDay[day].push(r);
}
});
allF.forEach(f => {
const ts = f.flight?.time?.scheduled?.arrival || f.flight?.time?.scheduled?.departure;
if (ts) {
const day = Math.floor(ts / 86400);
const dayRanges = rangesByDay[day];
if (dayRanges) {
for (const r of dayRanges) {
if (ts >= r.sTS && ts <= r.eTS) {
counts[r.iso]++;
}

Copilot uses AI. Check for mistakes.
}
}
}
});

ranges.forEach(r => {
const cnt = counts[r.iso];
if (dict[r.iso]) dict[r.iso].flightCount = cnt; else dict[r.iso] = { weatherText: 'N/A', weatherIcon: '❓', flightCount: cnt };
});
} catch (e) { if (__DEV__) console.warn('[calFlights]', e); }
setDailyStats(dict);
};
Expand Down
Loading