import { useState } from 'react'; import LAENDER from '../../data/laender.json'; import CitySearch from './CitySearch.jsx'; import { BY_CODE, CONTINENTS, continentOf, countryName, fmtDay, num } from './laender.js'; import { travelDays, travelRoute } from './route.js'; const pct = (part, total) => (total ? (part / total) * 100 : 0); const fmtPct = (p) => `${p.toLocaleString('de-DE', { maximumFractionDigits: p < 10 ? 1 : 0 })} %`; const TOTAL_AREA = LAENDER.reduce((s, c) => s + (c.area || 0), 0); /** * Statistik: Länder (Welt und je Kontinent), Fläche, äußerste Punkte, Kilometer entlang der Zeitleiste. * Grundlage für "Welt": alle Länder und Gebiete der Länderdaten (world-countries). */ export default function TravelStats({ visited, cities, visits, wishes, homes, onAddHome, onRemoveHome, busy, onSelectCity }) { const [since, setSince] = useState(''); const codes = [...visited].filter((c) => BY_CODE.has(c)); const area = codes.reduce((s, c) => s + (BY_CODE.get(c).area || 0), 0); const continents = CONTINENTS.map((name) => { const total = LAENDER.filter((c) => c.continent === name).length; const seen = codes.filter((c) => continentOf(c) === name).length; return { name, total, seen }; }).filter((c) => c.total); // Äußerste Punkte (nur besuchte Städte) const extreme = (pick) => (cities.length ? cities.reduce((a, b) => (pick(b) > pick(a) ? b : a)) : null); const points = [ ['Nördlichster Ort', extreme((c) => c.lat), (c) => `${c.lat.toFixed(1).replace('.', ',')}° N`], ['Südlichster Ort', extreme((c) => -c.lat), (c) => `${Math.abs(c.lat).toFixed(1).replace('.', ',')}° ${c.lat < 0 ? 'S' : 'N'}`], ['Östlichster Ort', extreme((c) => c.lon), (c) => `${Math.abs(c.lon).toFixed(1).replace('.', ',')}° ${c.lon < 0 ? 'W' : 'O'}`], ['Westlichster Ort', extreme((c) => -c.lon), (c) => `${Math.abs(c.lon).toFixed(1).replace('.', ',')}° ${c.lon < 0 ? 'W' : 'O'}`], ]; // Kilometer: Reisen ab Wohnort, Rundreisen und Ausflüge (siehe route.js) const route = travelRoute(visits, cities, homes); const days = travelDays(visits, cities, homes); const summary = [ `${route.trips} ${route.trips === 1 ? 'Reise' : 'Reisen'}${homes.length ? ' ab Wohnort' : ''}`, route.excursions && `${route.excursions} ${route.excursions === 1 ? 'Ausflug' : 'Ausflüge'}`, `${days} Reisetage`, ].filter(Boolean).join(' · '); return (
Mit Wohnort zählt jede Reise als Hin- und Rückweg ab zuhause.
)}„Seit“ leer = von Anfang an. Zog man um oder wohnte länger im Ausland, einen weiteren Wohnort mit Datum eintragen – oder beim Besuch „In dieser Zeit hier gewohnt“ wählen.
{route.legs.length > 0 && (Ohne Wohnort fehlen Hin- und Heimwege; die Reisen werden direkt nacheinander verbunden.
}