mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Don't pass h3_resolution from frontend; use default in backend service
This commit is contained in:
parent
5b3fe84933
commit
0905ef65a5
5 changed files with 9 additions and 45 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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!
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue