feat(tours): mark the best known places along a city walk

A search for sights along a tour now also asks the places index for the best
known places near the line, ranked by how often their Wikipedia articles are
read (QRank). A row the index already found is marked as a highlight; a
famous sight no kind names, like a square, is added as a sight of its own.
Stations, hotels and restaurants rank a row they match but are never added.

Highlights are listed first with a star in the list and a badge in the map
card. A place counts as a highlight from 40000 views a year, or the best
three from 5000 where fewer reach that. An index without ranks, or one older
than the endpoint, leaves the search as it was.
This commit is contained in:
Maurice
2026-10-20 12:16:11 +02:00
parent 54baf85a2a
commit 71fe69c1f1
45 changed files with 840 additions and 26 deletions
+2
View File
@@ -601,6 +601,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'الوصول بعد بدء جولة {walk} في {time}',
'tours.poi.categoriesNone': 'لم تُختر أي فئة',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'أبرز المعالم',
'tours.poi.highlightHint': 'من أشهر الأماكن هنا',
'tours.planner.tourType': 'نوع الجولة',
'tours.paddle.boat': 'القارب',
'tours.paddle.boat.kayak': 'كاياك',
+2
View File
@@ -602,6 +602,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': '{walk} {time} başlayır, çatma isə daha gec olur',
'tours.poi.categoriesNone': 'Kateqoriya seçilməyib',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Diqqətəlayiq',
'tours.poi.highlightHint': 'Buradakı ən tanınmış yerlərdən biri',
'tours.planner.tourType': 'Tur növü',
'tours.paddle.boat': 'Qayıq',
'tours.paddle.boat.kayak': 'Kayak', // same-as-en
+2
View File
@@ -607,6 +607,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Chega depois do início de {walk}, às {time}',
'tours.poi.categoriesNone': 'Nenhuma categoria escolhida',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Destaque',
'tours.poi.highlightHint': 'Um dos lugares mais conhecidos daqui',
'tours.planner.tourType': 'Tipo de passeio',
'tours.paddle.boat': 'Embarcação',
'tours.paddle.boat.kayak': 'Caiaque',
+2
View File
@@ -608,6 +608,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Arriba després que comenci {walk}, a les {time}',
'tours.poi.categoriesNone': 'Cap categoria triada',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Imprescindible',
'tours.poi.highlightHint': "Un dels llocs més coneguts d'aquí",
'tours.planner.tourType': 'Tipus de ruta',
'tours.paddle.boat': 'Embarcació',
'tours.paddle.boat.kayak': 'Caiac',
+2
View File
@@ -595,6 +595,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Příjezd až po začátku procházky {walk} v {time}',
'tours.poi.categoriesNone': 'Žádná kategorie',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Top místo',
'tours.poi.highlightHint': 'Jedno z nejznámějších míst v okolí',
'tours.planner.tourType': 'Typ túry',
'tours.paddle.boat': 'Loď',
'tours.paddle.boat.kayak': 'Kajak',
+2
View File
@@ -612,6 +612,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Ankunft nach dem Start von {walk} um {time}',
'tours.poi.categoriesNone': 'Keine Kategorie gewählt',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Highlight', // same-as-en
'tours.poi.highlightHint': 'Einer der bekanntesten Orte hier',
'tours.planner.tourType': 'Tourtyp',
'tours.paddle.boat': 'Boot',
'tours.paddle.boat.kayak': 'Kajak',
+2
View File
@@ -596,6 +596,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Arrives after {walk} starts at {time}',
'tours.poi.categoriesNone': 'No category chosen',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Highlight',
'tours.poi.highlightHint': 'One of the best-known places here',
'tours.planner.tourType': 'Tour type',
'tours.paddle.boat': 'Boat',
'tours.paddle.boat.kayak': 'Kayak',
+2
View File
@@ -607,6 +607,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Llega después de que empiece {walk}, a las {time}',
'tours.poi.categoriesNone': 'Ninguna categoría elegida',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Imprescindible',
'tours.poi.highlightHint': 'Uno de los lugares más conocidos de aquí',
'tours.planner.tourType': 'Tipo de ruta',
'tours.paddle.boat': 'Embarcación',
'tours.paddle.boat.kayak': 'Kayak', // same-as-en
+2
View File
@@ -598,6 +598,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Saabub pärast seda, kui {walk} algab kell {time}',
'tours.poi.categoriesNone': 'Kategooriat pole valitud',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Tippkoht',
'tours.poi.highlightHint': 'Üks siinseid tuntuimaid paiku',
'tours.planner.tourType': 'Matka tüüp',
'tours.paddle.boat': 'Paat',
'tours.paddle.boat.kayak': 'Süst',
+2
View File
@@ -615,6 +615,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Arrivée après le début de {walk} à {time}',
'tours.poi.categoriesNone': 'Aucune catégorie choisie',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Incontournable',
'tours.poi.highlightHint': 'L’un des lieux les plus connus ici',
'tours.planner.tourType': 'Type de sortie',
'tours.paddle.boat': 'Embarcation',
'tours.paddle.boat.kayak': 'Kayak', // same-as-en
+2
View File
@@ -618,6 +618,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Άφιξη μετά την έναρξη της βόλτας {walk} στις {time}',
'tours.poi.categoriesNone': 'Δεν επιλέχθηκε κατηγορία',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Κορυφαίο',
'tours.poi.highlightHint': 'Ένα από τα πιο γνωστά μέρη εδώ',
'tours.planner.tourType': 'Τύπος διαδρομής',
'tours.paddle.boat': 'Σκάφος',
'tours.paddle.boat.kayak': 'Καγιάκ',
+2
View File
@@ -608,6 +608,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Érkezés a séta kezdete után: {walk}, {time}',
'tours.poi.categoriesNone': 'Nincs kategória kiválasztva',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Kiemelt',
'tours.poi.highlightHint': 'Az itteni legismertebb helyek egyike',
'tours.planner.tourType': 'Túratípus',
'tours.paddle.boat': 'Hajó',
'tours.paddle.boat.kayak': 'Kajak',
+2
View File
@@ -600,6 +600,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Tiba setelah {walk} dimulai pukul {time}',
'tours.poi.categoriesNone': 'Belum ada kategori',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Sorotan',
'tours.poi.highlightHint': 'Salah satu tempat paling terkenal di sini',
'tours.planner.tourType': 'Jenis tur',
'tours.paddle.boat': 'Perahu',
'tours.paddle.boat.kayak': 'Kayak', // same-as-en
+2
View File
@@ -609,6 +609,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': "Arrivo dopo l'inizio di {walk} alle {time}",
'tours.poi.categoriesNone': 'Nessuna categoria scelta',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Da non perdere',
'tours.poi.highlightHint': 'Uno dei luoghi più famosi di qui',
'tours.planner.tourType': 'Tipo di tour',
'tours.paddle.boat': 'Imbarcazione',
'tours.paddle.boat.kayak': 'Kayak', // same-as-en
+2
View File
@@ -587,6 +587,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': '{walk} の開始({time})より後に到着',
'tours.poi.categoriesNone': 'カテゴリー未選択',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': '注目スポット',
'tours.poi.highlightHint': 'このあたりで特に有名な場所のひとつ',
'tours.planner.tourType': 'ツアーの種類',
'tours.paddle.boat': 'ボート',
'tours.paddle.boat.kayak': 'カヤック',
+2
View File
@@ -584,6 +584,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': '{walk} 시작({time}) 이후 도착',
'tours.poi.categoriesNone': '선택한 카테고리 없음',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': '하이라이트',
'tours.poi.highlightHint': '이곳에서 가장 잘 알려진 장소 중 하나',
'tours.planner.tourType': '투어 유형',
'tours.paddle.boat': '보트',
'tours.paddle.boat.kayak': '카약',
+2
View File
@@ -609,6 +609,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Aankomst na de start van {walk} om {time}',
'tours.poi.categoriesNone': 'Geen categorie gekozen',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Topper',
'tours.poi.highlightHint': 'Een van de bekendste plekken hier',
'tours.planner.tourType': 'Soort tocht',
'tours.paddle.boat': 'Boot',
'tours.paddle.boat.kayak': 'Kajak',
+2
View File
@@ -617,6 +617,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Przyjazd po rozpoczęciu trasy {walk} o {time}',
'tours.poi.categoriesNone': 'Nie wybrano kategorii',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Perełka',
'tours.poi.highlightHint': 'Jedno z najbardziej znanych miejsc w okolicy',
'tours.planner.tourType': 'Rodzaj wycieczki',
'tours.paddle.boat': 'Łódź',
'tours.paddle.boat.kayak': 'Kajak',
+2
View File
@@ -620,6 +620,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Прибытие после начала прогулки {walk} в {time}',
'tours.poi.categoriesNone': 'Категория не выбрана',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Главное',
'tours.poi.highlightHint': 'Одно из самых известных мест здесь',
'tours.planner.tourType': 'Тип тура',
'tours.paddle.boat': 'Лодка',
'tours.paddle.boat.kayak': 'Каяк',
+2
View File
@@ -597,6 +597,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Príchod po začiatku prechádzky {walk} o {time}',
'tours.poi.categoriesNone': 'Žiadna kategória',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Top miesto',
'tours.poi.highlightHint': 'Jedno z najznámejších miest v okolí',
'tours.planner.tourType': 'Typ túry',
'tours.paddle.boat': 'Loď',
'tours.paddle.boat.kayak': 'Kajak',
+2
View File
@@ -596,6 +596,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Ankomst efter att {walk} börjar kl. {time}',
'tours.poi.categoriesNone': 'Ingen kategori vald',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Höjdpunkt',
'tours.poi.highlightHint': 'En av de mest kända platserna här',
'tours.planner.tourType': 'Turtyp',
'tours.paddle.boat': 'Båt',
'tours.paddle.boat.kayak': 'Kajak',
+2
View File
@@ -571,6 +571,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'ถึงหลังจาก {walk} เริ่มเวลา {time}',
'tours.poi.categoriesNone': 'ยังไม่ได้เลือกหมวดหมู่',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'ไฮไลต์',
'tours.poi.highlightHint': 'หนึ่งในสถานที่ที่มีชื่อเสียงที่สุดในบริเวณนี้',
'tours.planner.tourType': 'ประเภททริป',
'tours.paddle.boat': 'เรือ',
'tours.paddle.boat.kayak': 'เรือคายัก',
+1 -1
View File
@@ -20,7 +20,7 @@ const tokens = (value: string) => [...value.matchAll(/\{[^{}]+\}/g)].map((match)
// placeholder spec; here only the general keys are.
const groups = pluralGroups(Object.keys(english));
const generalKeys = (keys: string[]) => keys.filter((key) => !pluralFormOf(key, groups));
const GENERAL_KEY_COUNT = 823;
const GENERAL_KEY_COUNT = 825;
function literalKeys(source: string): string[] {
const tree = ts.createSourceFile('locale.ts', source, ts.ScriptTarget.Latest, true);
+2
View File
@@ -603,6 +603,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Varış, {walk} {time} saatinde başladıktan sonra',
'tours.poi.categoriesNone': 'Kategori seçilmedi',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Öne çıkan',
'tours.poi.highlightHint': 'Buradaki en bilinen yerlerden biri',
'tours.planner.tourType': 'Tur türü',
'tours.paddle.boat': 'Tekne',
'tours.paddle.boat.kayak': 'Kano (kayak)',
+2
View File
@@ -613,6 +613,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Прибуття після початку прогулянки {walk} о {time}',
'tours.poi.categoriesNone': 'Категорію не вибрано',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Головне',
'tours.poi.highlightHint': 'Одне з найвідоміших місць тут',
'tours.planner.tourType': 'Тип туру',
'tours.paddle.boat': 'Човен',
'tours.paddle.boat.kayak': 'Каяк',
+2
View File
@@ -595,6 +595,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': 'Đến sau khi {walk} bắt đầu lúc {time}',
'tours.poi.categoriesNone': 'Chưa chọn danh mục',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': 'Nổi bật',
'tours.poi.highlightHint': 'Một trong những nơi nổi tiếng nhất ở đây',
'tours.planner.tourType': 'Loại chuyến',
'tours.paddle.boat': 'Thuyền',
'tours.paddle.boat.kayak': 'Thuyền kayak',
+2
View File
@@ -551,6 +551,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': '抵達晚於 {walk} 的開始時間 {time}',
'tours.poi.categoriesNone': '未選擇類別',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': '亮點',
'tours.poi.highlightHint': '這裡最知名的地方之一',
'tours.planner.tourType': '路線類型',
'tours.paddle.boat': '船隻',
'tours.paddle.boat.kayak': '獨木舟(Kayak)',
+2
View File
@@ -552,6 +552,8 @@ const tours: TranslationStrings = {
'tours.walk.transit.late': '到达晚于 {walk} 的开始时间 {time}',
'tours.poi.categoriesNone': '未选择类别',
'tours.poi.categoriesMore': '{first} +{more}',
'tours.poi.highlight': '亮点',
'tours.poi.highlightHint': '这里最知名的地方之一',
'tours.planner.tourType': '路线类型',
'tours.paddle.boat': '船只',
'tours.paddle.boat.kayak': '皮划艇',
+42
View File
@@ -0,0 +1,42 @@
import {
TOUR_HIGHLIGHT_FALLBACK_MIN_QRANK,
TOUR_HIGHLIGHT_MIN_COUNT,
TOUR_HIGHLIGHT_MIN_QRANK,
tourHighlightIds,
} from './tour-highlights';
import { describe, expect, it } from 'vitest';
const rank = (id: string, qrank: number) => ({ id, qrank });
describe('tour highlights', () => {
it('TOUR-HIGHLIGHT-001: every place past the bar is a highlight, best known first', () => {
expect(
tourHighlightIds([
rank('square', 900_000),
rank('cafe', 100),
rank('church', 41_000),
rank('bridge', 40_000),
rank('tower', 250_000),
]),
).toEqual(['square', 'tower', 'church', 'bridge']);
});
it('TOUR-HIGHLIGHT-002: with fewer than three past the bar, the best known down to the fallback fill up to three', () => {
expect(
tourHighlightIds([rank('a', 6_000), rank('b', 60_000), rank('c', 4_999), rank('d', 5_000), rank('e', 7_000)]),
).toEqual(['b', 'e', 'a']);
expect(tourHighlightIds([rank('a', 6_000), rank('b', 4_000)])).toEqual(['a']);
});
it('TOUR-HIGHLIGHT-003: nothing ranked is nothing marked, and a broken rank is never a highlight', () => {
expect(tourHighlightIds([])).toEqual([]);
expect(tourHighlightIds([rank('a', 4_999), rank('b', Number.NaN)])).toEqual([]);
});
it('TOUR-HIGHLIGHT-004: the bars are what the rule says', () => {
expect(TOUR_HIGHLIGHT_MIN_QRANK).toBe(40_000);
expect(TOUR_HIGHLIGHT_FALLBACK_MIN_QRANK).toBe(5_000);
expect(TOUR_HIGHLIGHT_MIN_COUNT).toBe(3);
});
});
+35
View File
@@ -0,0 +1,35 @@
/**
* Which places along a tour are its highlights: the ones people know.
*
* Fame is read from QRank, the page views of a place's Wikidata item across
* the Wikimedia projects, as the TREK places service carries it on its
* OpenStreetMap layer. A place without a Wikidata item has no rank and is
* never a highlight; that says nothing about whether it is worth a visit.
*/
/** A place at least this well known is a highlight wherever it lies. */
export const TOUR_HIGHLIGHT_MIN_QRANK = 40_000;
/**
* A route through quieter streets still shows its best known places: when
* fewer than {@link TOUR_HIGHLIGHT_MIN_COUNT} reach the bar above, the best
* known ones down to this rank fill up to that many.
*/
export const TOUR_HIGHLIGHT_FALLBACK_MIN_QRANK = 5_000;
/** How many highlights the fallback fills up to. */
export const TOUR_HIGHLIGHT_MIN_COUNT = 3;
/**
* The ids of the highlights among places with a rank, best known first. Ties
* keep the order they came in, so the same answer marks the same places.
*/
export function tourHighlightIds(ranked: ReadonlyArray<{ id: string; qrank: number }>): string[] {
const best = [...ranked].filter((row) => Number.isFinite(row.qrank)).sort((a, b) => b.qrank - a.qrank);
const famous = best.filter((row) => row.qrank >= TOUR_HIGHLIGHT_MIN_QRANK);
if (famous.length >= TOUR_HIGHLIGHT_MIN_COUNT) return famous.map((row) => row.id);
return best
.filter((row) => row.qrank >= TOUR_HIGHLIGHT_FALLBACK_MIN_QRANK)
.slice(0, TOUR_HIGHLIGHT_MIN_COUNT)
.map((row) => row.id);
}
@@ -72,6 +72,29 @@ describe('tour POI search contracts (PLN-02)', () => {
expect(answer.pois[0]?.distance_m).toBe(40);
});
it('TOUR-HIGHLIGHT-005: marks a highlight with a flag that may be left off, and refuses one that is no flag', () => {
const poi = {
id: 'way:9',
name: 'Piazza San Marco',
lat: 45.434,
lng: 12.338,
category: 'sights',
kind: 'place=square',
source: 'openstreetmap',
address: null,
website: null,
phone: null,
opening_hours: null,
distance_m: 12,
along_m: 300,
};
const answer = { truncated: false, partial: false, capped: false, unavailable: [] };
const parsed = tourPoiSearchResponseSchema.parse({ ...answer, pois: [{ ...poi, highlight: true }, poi] });
expect(parsed.pois.map((found) => found.highlight)).toEqual([true, undefined]);
const notAFlag = { ...answer, pois: [{ ...poi, highlight: 'yes' }] };
expect(tourPoiSearchResponseSchema.safeParse(notAFlag).success).toBe(false);
});
it('names the kinds that could not be searched, each a known category, and always says so', () => {
const answer = { pois: [], truncated: false, partial: false, capped: false };
expect(tourPoiSearchResponseSchema.parse({ ...answer, unavailable: ['viewpoint'] }).unavailable).toEqual([
@@ -12,6 +12,13 @@ import { z } from 'zod';
// The categories live in a module of their own, so the tour contract can name
// one on a waypoint without importing this one, which imports it.
export { TOUR_POI_CATEGORIES, tourPoiCategorySchema, type TourPoiCategory } from './tour-poi-category';
// Which places found are highlights, read by the server that marks them.
export {
TOUR_HIGHLIGHT_FALLBACK_MIN_QRANK,
TOUR_HIGHLIGHT_MIN_COUNT,
TOUR_HIGHLIGHT_MIN_QRANK,
tourHighlightIds,
} from './tour-highlights';
/** The categories each planned tour type offers, the most asked first. */
export const TOUR_POI_CATEGORIES_BY_TYPE: Record<PlannableTourType, readonly TourPoiCategory[]> = {
@@ -80,6 +87,8 @@ export const tourPoiSchema = z.object({
distance_m: z.number().nonnegative(),
/** Metres along the line from its start to the point nearest the place. */
along_m: z.number().nonnegative(),
/** One of the best known places along the line (tour-highlights); absent means not one. */
highlight: z.boolean().optional(),
});
export type TourPoi = z.infer<typeof tourPoiSchema>;