diff --git a/app/controllers/api/v1/maps/hexagons_controller.rb b/app/controllers/api/v1/maps/hexagons_controller.rb index 3ff0b3ff..0e0d19a5 100644 --- a/app/controllers/api/v1/maps/hexagons_controller.rb +++ b/app/controllers/api/v1/maps/hexagons_controller.rb @@ -57,7 +57,7 @@ class Api::V1::Maps::HexagonsController < ApiController private def hexagon_params - params.permit(:h3_resolution, :uuid, :start_date, :end_date) + params.permit(:uuid, :start_date, :end_date) end def handle_service_error @@ -79,7 +79,7 @@ class Api::V1::Maps::HexagonsController < ApiController end # Validate coordinate ranges - if !valid_coordinate_ranges? + unless valid_coordinate_ranges? render json: { error: 'Invalid coordinate ranges' }, status: :bad_request return false end diff --git a/app/javascript/controllers/public_stat_map_controller.js b/app/javascript/controllers/public_stat_map_controller.js index 6fa576a7..0113a0de 100644 --- a/app/javascript/controllers/public_stat_map_controller.js +++ b/app/javascript/controllers/public_stat_map_controller.js @@ -23,7 +23,6 @@ export default class extends BaseController { } disconnect() { - // No hexagonGrid to destroy for public sharing if (this.map) { this.map.remove(); } @@ -174,7 +173,6 @@ export default class extends BaseController { min_lat: dataBounds.min_lat, max_lon: dataBounds.max_lng, max_lat: dataBounds.max_lat, - h3_resolution: 8, start_date: startDate.toISOString(), end_date: endDate.toISOString(), uuid: this.uuidValue @@ -320,6 +318,4 @@ export default class extends BaseController { layer.setStyle(layer._originalStyle); } } - - } diff --git a/app/models/stat.rb b/app/models/stat.rb index 24ac4802..38babb8a 100644 --- a/app/models/stat.rb +++ b/app/models/stat.rb @@ -56,12 +56,10 @@ class Stat < ApplicationRecord sharing_enabled? && !sharing_expired? end - def hexagons_available?(hex_size = 1000) - # Check new optimized format (hexagon_centers) first - return true if hexagon_centers.present? && hexagon_centers.is_a?(Array) && hexagon_centers.any? - - # Fallback to legacy format (hexagon_data) for backwards compatibility - hexagon_data&.dig(hex_size.to_s, 'geojson').present? + def hexagons_available? + hexagon_centers.present? && + hexagon_centers.is_a?(Array) && + hexagon_centers.any? end def generate_new_sharing_uuid! diff --git a/app/services/stats/calculate_month.rb b/app/services/stats/calculate_month.rb index f26a5890..effddff2 100644 --- a/app/services/stats/calculate_month.rb +++ b/app/services/stats/calculate_month.rb @@ -91,8 +91,7 @@ class Stats::CalculateMonth service = Maps::H3HexagonCenters.new( user_id: user.id, start_date: start_date_iso8601, - end_date: end_date_iso8601, - h3_resolution: 8 # Small hexagons for good detail + end_date: end_date_iso8601 ) result = service.call diff --git a/spec/services/maps/hexagon_polygon_generator_spec.rb b/spec/services/maps/hexagon_polygon_generator_spec.rb index 0fdea568..ed4c2edb 100644 --- a/spec/services/maps/hexagon_polygon_generator_spec.rb +++ b/spec/services/maps/hexagon_polygon_generator_spec.rb @@ -103,8 +103,7 @@ RSpec.describe Maps::HexagonPolygonGenerator do center_lng: center_lng, center_lat: center_lat, size_meters: size_meters, - use_h3: true, - h3_resolution: 5 + use_h3: true ) end @@ -145,34 +144,6 @@ RSpec.describe Maps::HexagonPolygonGenerator do expect(latitudes.uniq.size).to be > 1 # Should have different latitudes end - context 'with different H3 resolution' do - it 'generates different sized hexagons' do - low_res_result = described_class.call( - center_lng: center_lng, - center_lat: center_lat, - use_h3: true, - h3_resolution: 3 - ) - - high_res_result = described_class.call( - center_lng: center_lng, - center_lat: center_lat, - use_h3: true, - h3_resolution: 7 - ) - - # Different resolutions should produce different hexagon sizes - low_res_coords = low_res_result['coordinates'].first - high_res_coords = high_res_result['coordinates'].first - - # Calculate approximate size by measuring distance between vertices - low_res_size = calculate_hexagon_size(low_res_coords) - high_res_size = calculate_hexagon_size(high_res_coords) - - expect(low_res_size).to be > high_res_size - end - end - context 'when H3 operations fail' do before do allow(H3).to receive(:from_geo_coordinates).and_raise(StandardError, 'H3 error') @@ -233,4 +204,4 @@ RSpec.describe Maps::HexagonPolygonGenerator do Math.sqrt((lng - center_lng)**2 + (lat - center_lat)**2) end end -end \ No newline at end of file +end