diff --git a/app/controllers/map_controller.rb b/app/controllers/map_controller.rb index 96376d09..dd3e710c 100644 --- a/app/controllers/map_controller.rb +++ b/app/controllers/map_controller.rb @@ -6,7 +6,7 @@ class MapController < ApplicationController def index @points = current_user.tracked_points.without_raw_data.where('timestamp >= ? AND timestamp <= ?', start_at, end_at).order(timestamp: :asc) - @countries_and_cities = CountriesAndCities.new(@points).call + @countries_and_cities = Visits::Calculate.new(@points).uniq_visits @coordinates = @points.pluck(:latitude, :longitude, :battery, :altitude, :timestamp, :velocity, :id) .map { [_1.to_f, _2.to_f, _3.to_s, _4.to_s, _5.to_s, _6.to_s, _7] } diff --git a/app/services/visits/calculate.rb b/app/services/visits/calculate.rb index 672d4df1..5f075c80 100644 --- a/app/services/visits/calculate.rb +++ b/app/services/visits/calculate.rb @@ -9,6 +9,13 @@ class Visits::Calculate normalize_result(city_visits) end + def uniq_visits + # Only one visit per city per day + call.flat_map do |country| + { country: country[:country], cities: country[:cities].uniq { [_1[:city], Time.at(_1[:timestamp]).to_date] } } + end + end + private attr_reader :points diff --git a/app/views/shared/_right_sidebar.html.erb b/app/views/shared/_right_sidebar.html.erb index e5d27f07..e06034f6 100644 --- a/app/views/shared/_right_sidebar.html.erb +++ b/app/views/shared/_right_sidebar.html.erb @@ -31,6 +31,7 @@ <% if REVERSE_GEOCODING_ENABLED && @countries_and_cities&.any? %>