pulse-ai-utils
Version:
Utility functions and helpers for AI-powered applications
101 lines (100 loc) • 2.58 kB
TypeScript
export interface GeoLocation {
lat: number;
lng: number;
}
export interface ContentWithLocation {
id: string;
title: string;
type: string;
primary_area: string;
locations: Array<{
area_id: string;
lat: number;
lng: number;
relevance?: number;
}>;
primary_location: GeoLocation;
[key: string]: any;
}
export interface SearchResult {
content: ContentWithLocation;
distance: number;
nearestLocation: {
area_id: string;
lat: number;
lng: number;
};
relevanceScore: number;
}
/**
* Calculate distance between two points using Haversine formula
* @returns Distance in miles
*/
export declare function calculateDistance(lat1: number, lng1: number, lat2: number, lng2: number): number;
/**
* Determine if radius should be expanded based on results
*/
export declare function expandRadius(params: {
currentRadius: number;
resultsCount: number;
minThreshold: number;
maxRadius: number;
}): {
shouldExpand: boolean;
newRadius: number;
};
/**
* Calculate relevance score based on distance
* Uses exponential decay: score = 1 / (1 + distance * decayFactor)
*/
export declare function calculateRelevanceScore(params: {
distanceMiles: number;
decayFactor?: number;
}): number;
/**
* Find content within a radius from user location
*/
export declare function findContentWithinRadius(params: {
userLat: number;
userLng: number;
content: ContentWithLocation[];
radiusMiles: number;
}): SearchResult[];
/**
* Extract locations from text content
*/
export declare function extractLocationsFromText(text: string): Array<{
area_id: string;
lat: number;
lng: number;
relevance: number;
}>;
/**
* Generate geohash for efficient geo queries
* Implementation of simple geohash algorithm
*/
export declare function generateGeohash(lat: number, lng: number, precision?: number): string;
/**
* Progressive search with radius expansion
*/
export declare function progressiveGeoSearch(params: {
userLat: number;
userLng: number;
content: ContentWithLocation[];
initialRadius?: number;
maxRadius?: number;
minResults?: number;
radiusSteps?: number[];
}): Promise<{
results: SearchResult[];
finalRadius: number;
expansions: number;
}>;
/**
* Get geohash bounds for a circular area
* This creates a bounding box that contains the circle
*/
export declare function getGeohashBounds(lat: number, lng: number, radiusMiles: number): Array<{
lower: string;
upper: string;
}>;