From 339ba3130eaed82d036aab07e64fa4c2aa23ab18 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sat, 20 Sep 2025 14:05:14 +0200 Subject: [PATCH] Fix missing hexagons --- app/models/stat.rb | 2 +- app/services/maps/hexagon_center_manager.rb | 8 +++++--- spec/services/stats/hexagon_calculator_spec.rb | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/models/stat.rb b/app/models/stat.rb index 6c5d592b..36421b97 100644 --- a/app/models/stat.rb +++ b/app/models/stat.rb @@ -58,7 +58,7 @@ class Stat < ApplicationRecord def hexagons_available? h3_hex_ids.present? && - h3_hex_ids.is_a?(Hash) && + (h3_hex_ids.is_a?(Hash) || h3_hex_ids.is_a?(Array)) && h3_hex_ids.any? end diff --git a/app/services/maps/hexagon_center_manager.rb b/app/services/maps/hexagon_center_manager.rb index 31ada95a..b9a3b03e 100644 --- a/app/services/maps/hexagon_center_manager.rb +++ b/app/services/maps/hexagon_center_manager.rb @@ -20,7 +20,7 @@ module Maps def pre_calculated_centers_available? return false if stat&.h3_hex_ids.blank? - stat.h3_hex_ids.is_a?(Hash) && stat.h3_hex_ids.any? + stat.h3_hex_ids.is_a?(Array) && stat.h3_hex_ids.any? end def build_response_from_centers @@ -45,8 +45,10 @@ module Maps def build_hexagons_from_h3_ids(hex_ids) # Convert stored H3 IDs back to hexagon polygons - hexagon_features = hex_ids.map.with_index do |(h3_index, data), index| - build_hexagon_feature_from_h3(h3_index, data, index) + # Array format: [[h3_index, point_count, earliest, latest], ...] + hexagon_features = hex_ids.map.with_index do |row, index| + h3_index, count, earliest, latest = row + build_hexagon_feature_from_h3(h3_index, [count, earliest, latest], index) end build_feature_collection(hexagon_features) diff --git a/spec/services/stats/hexagon_calculator_spec.rb b/spec/services/stats/hexagon_calculator_spec.rb index 25c8f83e..40903efb 100644 --- a/spec/services/stats/hexagon_calculator_spec.rb +++ b/spec/services/stats/hexagon_calculator_spec.rb @@ -120,4 +120,4 @@ RSpec.describe Stats::HexagonCalculator do end end end -end \ No newline at end of file +end