add logic
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
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 isObtained(attraction: Attraction, collectedIds: ReadonlySet<string>): boolean {
|
||||
return attraction.visited || collectedIds.has(attraction.id);
|
||||
}
|
||||
|
||||
export function areaOpenedCount(area: Area | AreaDetails, collectedIds: ReadonlySet<string>): number {
|
||||
const attractions = areaAttractions(area);
|
||||
|
||||
if (attractions.length > 0) {
|
||||
return attractions.filter((item) => isObtained(item, collectedIds)).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, collectedIds: ReadonlySet<string>): number {
|
||||
const total = areaTotalCount(area);
|
||||
|
||||
if (!total) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Math.round((areaOpenedCount(area, collectedIds) / total) * 100);
|
||||
}
|
||||
Reference in New Issue
Block a user