mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Update Visits::Calculate to return only one visit per city per day
This commit is contained in:
parent
f0e94f38f9
commit
7844bf1f3c
3 changed files with 9 additions and 1 deletions
|
|
@ -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] }
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
<% if REVERSE_GEOCODING_ENABLED && @countries_and_cities&.any? %>
|
||||
<hr class='my-5'>
|
||||
<h2 class='text-lg font-semibold'>Countries and cities</h2>
|
||||
<% @countries_and_cities.each do |country| %>
|
||||
<% next if country[:cities].empty? %>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue