From 0a006807f6c083260ed6f353d2e481cbda547683 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Fri, 12 Jul 2024 22:11:42 +0200 Subject: [PATCH] Update CHANGELOG.md and User#total_reverse_geocoded method --- CHANGELOG.md | 37 +++++++++++++++++++++++++++++++++++++ app/models/user.rb | 2 +- spec/models/user_spec.rb | 8 ++++++-- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07028947..454b103d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,43 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Point reference to a user is no longer optional. It should not cause any problems, but if you see any issues, please let me know. +- ⚠️ Calculation of total reverse geocoded points was changed. ⚠️ Previously, the reverse geocoding process was recording only country and city for each point. Now, it records all the data that was received from the reverse geocoding service. This means that the total number of reverse geocoded points will be different from the previous one. It is recommended to restart the reverse geocoding process to get this data for all your existing points. Below you can find an example of what kind of data is being saved to your Dawarich database: + +```json +{ + "place_id": 127850637, + "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright", + "osm_type": "way", + "osm_id": 718035022, + "lat": "52.51450815", + "lon": "13.350110811262352", + "class": "historic", + "type": "monument", + "place_rank": 30, + "importance": 0.4155071896625501, + "addresstype": "historic", + "name": "Victory Column", + "display_name": "Victory Column, Großer Stern, Botschaftsviertel, Tiergarten, Mitte, Berlin, 10785, Germany", + "address": { + "historic": "Victory Column", + "road": "Großer Stern", + "neighbourhood": "Botschaftsviertel", + "suburb": "Tiergarten", + "borough": "Mitte", + "city": "Berlin", + "ISO3166-2-lvl4": "DE-BE", + "postcode": "10785", + "country": "Germany", + "country_code": "de" + }, + "boundingbox": [ + "52.5142449", + "52.5147775", + "13.3496725", + "13.3505485" + ] +} +``` ## [0.8.7] — 2024-07-09 diff --git a/app/models/user.rb b/app/models/user.rb index 220ccb94..9d55cd47 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -45,7 +45,7 @@ class User < ApplicationRecord end def total_reverse_geocoded - points.select(:id).where.not(country: nil, city: nil).count + points.select(:id).where.not(geodata: {}).count end private diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index cff98dc5..f69f0654 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -77,7 +77,8 @@ RSpec.describe User, type: :model do user:, toponyms: [ { 'cities' => [], 'country' => nil }, - { 'cities' => [{ 'city' => 'Berlin', 'points' => 64, 'timestamp' => 1710446806, 'stayed_for' => 8772 }], 'country' => 'Germany' } + { 'cities' => [{ 'city' => 'Berlin', 'points' => 64, 'timestamp' => 1_710_446_806, 'stayed_for' => 8772 }], +'country' => 'Germany' } ] ) end @@ -91,7 +92,10 @@ RSpec.describe User, type: :model do subject { user.total_reverse_geocoded } let(:import) { create(:import, user:) } - let!(:point) { create(:point, country: 'Country', city: 'City', import:) } + let!(:reverse_geocoded_point) do + create(:point, country: 'Country', city: 'City', geodata: { some: 'data' }, import:) + end + let!(:not_reverse_geocoded_point) { create(:point, country: 'Country', city: 'City', import:) } it 'returns number of reverse geocoded points' do expect(subject).to eq(1)