97 lines
2.1 KiB
TypeScript
97 lines
2.1 KiB
TypeScript
export interface Attraction {
|
|
id: string;
|
|
name: string;
|
|
about: string;
|
|
iconUrl: string;
|
|
backgroundUrl: string;
|
|
audioUrl: string;
|
|
modelUrl: string;
|
|
latitude: number;
|
|
longitude: number;
|
|
visited: boolean;
|
|
}
|
|
|
|
export interface AttractionDetails extends Attraction {
|
|
address: string;
|
|
facts: string[];
|
|
photoUrl: string;
|
|
}
|
|
|
|
export interface AreaProgress {
|
|
visited: number;
|
|
total: number;
|
|
}
|
|
|
|
export type VisitStatus = 'VISITED' | 'ALREADY_VISITED' | 'NOT_MATCHED' | 'UNCERTAIN';
|
|
|
|
export interface VisitResult {
|
|
status: VisitStatus;
|
|
confidence: number;
|
|
progress: AreaProgress;
|
|
}
|
|
|
|
export interface Area {
|
|
id: string;
|
|
parentId: string | null;
|
|
name: string;
|
|
attractions: Attraction[];
|
|
progress: AreaProgress;
|
|
}
|
|
|
|
export interface AreaDetails extends Area {
|
|
children: Area[];
|
|
}
|
|
|
|
export interface AreasPage {
|
|
content: Area[];
|
|
page: {
|
|
size: number;
|
|
number: number;
|
|
totalElements: number;
|
|
totalPages: number;
|
|
};
|
|
}
|
|
|
|
export type AreasStatus = 'idle' | 'loading' | 'ready' | 'error';
|
|
|
|
export function areaAttractions(area: Area | AreaDetails): Attraction[] {
|
|
const own = area.attractions ?? [];
|
|
const children = 'children' in area ? area.children : [];
|
|
|
|
return [...own, ...children.flatMap((child) => child.attractions ?? [])];
|
|
}
|
|
|
|
export function findAttraction(area: Area | AreaDetails, id: string): Attraction | null {
|
|
return areaAttractions(area).find((item) => item.id === id) ?? null;
|
|
}
|
|
|
|
export function areaOpenedCount(area: Area | AreaDetails): number {
|
|
const attractions = areaAttractions(area);
|
|
|
|
if (attractions.length > 0) {
|
|
return attractions.filter((item) => item.visited).length;
|
|
}
|
|
|
|
return area.progress?.visited ?? 0;
|
|
}
|
|
|
|
export function areaTotalCount(area: Area | AreaDetails): number {
|
|
const attractions = areaAttractions(area);
|
|
|
|
if (attractions.length > 0) {
|
|
return attractions.length;
|
|
}
|
|
|
|
return area.progress?.total ?? 0;
|
|
}
|
|
|
|
export function areaProgress(area: Area | AreaDetails): number {
|
|
const total = areaTotalCount(area);
|
|
|
|
if (!total) {
|
|
return 0;
|
|
}
|
|
|
|
return Math.round((areaOpenedCount(area) / total) * 100);
|
|
}
|