diff --git a/CLAUDE.md b/CLAUDE.md index 7ecc9e24..febda52c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -87,7 +87,7 @@ This file contains essential information for Claude to work effectively with the ### Setup 1. **Docker Development**: Use `docker-compose -f docker/docker-compose.yml up` 2. **DevContainer**: VS Code devcontainer support available -3. **Local Development**: +3. **Local Development**: - `bundle exec rails db:prepare` - `bundle exec sidekiq` (background jobs) - `bundle exec bin/dev` (main application) @@ -138,7 +138,7 @@ npx playwright test # E2E tests - `users` - User accounts and settings - `points` - Location points with PostGIS geometry - `tracks` - Route collections -- `areas` - User-defined geographic areas +- `areas` - User-defined geographic areas - `visits` - Detected area visits - `trips` - Travel periods - `imports`/`exports` - Data transfer operations @@ -196,6 +196,7 @@ bundle exec bundle-audit # Dependency security 1. **Location Data**: Always handle location data with appropriate precision and privacy considerations 2. **PostGIS**: Leverage PostGIS features for geographic calculations rather than Ruby-based solutions +2.1 **Coordinates**: Use `lonlat` column in `points` table for geographic calculations 3. **Background Jobs**: Use Sidekiq for any potentially long-running operations 4. **Testing**: Include both unit and integration tests for location-based features 5. **Performance**: Consider database indexes for geographic queries @@ -215,4 +216,4 @@ bundle exec bundle-audit # Dependency security - **Repository**: https://github.com/Freika/dawarich - **Discord**: https://discord.gg/pHsBjpt5J8 - **Changelog**: See CHANGELOG.md for version history -- **Development Setup**: See DEVELOPMENT.md \ No newline at end of file +- **Development Setup**: See DEVELOPMENT.md diff --git a/app/services/location_search/spatial_matcher.rb b/app/services/location_search/spatial_matcher.rb index 46e538f2..0cbe62b2 100644 --- a/app/services/location_search/spatial_matcher.rb +++ b/app/services/location_search/spatial_matcher.rb @@ -6,42 +6,9 @@ module LocationSearch # Using PostGIS for efficient spatial queries end - # Debug method to test spatial queries directly - def debug_points_near(user, latitude, longitude, radius_meters = 1000) - query = <<~SQL - SELECT - p.id, - p.timestamp, - ST_Y(p.lonlat::geometry) as latitude, - ST_X(p.lonlat::geometry) as longitude, - p.city, - p.country, - ST_Distance(p.lonlat, ST_Point(#{longitude}, #{latitude})::geography) as distance_meters - FROM points p - WHERE p.user_id = #{user.id} - AND ST_DWithin(p.lonlat, ST_Point(#{longitude}, #{latitude})::geography, #{radius_meters}) - ORDER BY distance_meters ASC - LIMIT 10; - SQL - - puts "=== DEBUG SPATIAL QUERY ===" - puts "Searching for user #{user.id} near [#{latitude}, #{longitude}] within #{radius_meters}m" - puts "Query: #{query}" - - results = ActiveRecord::Base.connection.exec_query(query) - puts "Found #{results.count} points:" - - results.each do |row| - puts "- Point #{row['id']}: [#{row['latitude']}, #{row['longitude']}] - #{row['distance_meters'].to_f.round(2)}m away" - end - - results - end - def find_points_near(user, latitude, longitude, radius_meters, date_options = {}) points_query = build_spatial_query(user, latitude, longitude, radius_meters, date_options) - # Execute query and return results with calculated distance ActiveRecord::Base.connection.exec_query(points_query) .map { |row| format_point_result(row) } .sort_by { |point| point[:timestamp] }