-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Improve filtering by adding county/city models #102
[WIP] Improve filtering by adding county/city models #102
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if only covering the cities, and not also villages would be good enough. The hardest hit places are actually couple of villages around Petrinja. It would be misleading if the user would have to select "I'm requesting help in Petrinja", while that's actually not true. We could perhaps use your location
suggestion to go around this... 🤔
Another issue is that the migration will raise error on live site because City.find_by_name
won't find all the names that we currently have. I suggest we fix those manually if we decide to go this route:
ad.update!(city: City.find_by_name(ad.city_zdel)) # might return nil, but won't fail
rename_column :ads, :city, :city_zdel | ||
add_reference :ads, :city, foreign_key: true, index: true | ||
Ad.all.each do |ad| | ||
ad.update!(city_id: City.find_by_name(ad.city_zdel).id ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail if the city is not found by the name and we definitely have cities in the database on live site that don't match any city name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like this would be ok
ad.update!(city_id: City.find_by_name(ad.city_zdel).id ) | |
city = City.find_by(name: ad.city_zdel) | |
if city | |
ad.update!(city_id: city.id) | |
else | |
ad.update!(city_id: City.first.id) | |
puts "* No matching city for ad #{ad.id}." | |
end |
After @vfonic normalisation I suppose we shouldn't have lot of this and we can correct them manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spoke about this with Vlado, we need to have normalized data first in the DB, any irregularities we can manually change. idea is for this to fail so it alert us we have mismatched data that we can than alter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks promising, left few improvement suggestions. Looking forward for the UI :)
rename_column :ads, :city, :city_zdel | ||
add_reference :ads, :city, foreign_key: true, index: true | ||
Ad.all.each do |ad| | ||
ad.update!(city_id: City.find_by_name(ad.city_zdel).id ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like this would be ok
ad.update!(city_id: City.find_by_name(ad.city_zdel).id ) | |
city = City.find_by(name: ad.city_zdel) | |
if city | |
ad.update!(city_id: city.id) | |
else | |
ad.update!(city_id: City.first.id) | |
puts "* No matching city for ad #{ad.id}." | |
end |
After @vfonic normalisation I suppose we shouldn't have lot of this and we can correct them manually.
class ConnectAdWithCity < ActiveRecord::Migration[6.1] | ||
def change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class ConnectAdWithCity < ActiveRecord::Migration[6.1] | |
def change | |
class ConnectAdWithCity < ActiveRecord::Migration[6.1] | |
Ad = Class.new(ActiveRecord::Base) | |
City = Class.new(ActiveRecord::Base) | |
def change |
https://guides.rubyonrails.org/v3.2/migrations.html#using-models-in-your-migrations
ActiveRecord::Base.transaction do | ||
Rake::Task['db:seed_locations'].invoke | ||
rename_column :ads, :city, :city_zdel | ||
add_reference :ads, :city, foreign_key: true, index: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_reference :ads, :city, foreign_key: true, index: true | |
add_reference :ads, :city, foreign_key: true, index: true, null: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work immediately, because we have ads in our database and, when we add city_id
reference, none of the ads will have city_id
that is not null.
We can do:
add_reference :ads, :city, foreign_key: true, index: true
# ... do the data migration
change_column_null :ads, :city_id, false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use this as opportunity to clean up data before we have too many ads
def change | ||
create_table :cities do |t| | ||
t.string :name | ||
t.references :county, foreign_key: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.references :county, foreign_key: true | |
t.references :county, foreign_key: true, null: false |
I think we can just keep calling them cities, even if they are not real cities.
From what I see the list @mmorava used has 500+ cities (cities and bigger villages). Full list with smaller villages from https://www.posta.hr/preuzimanje-podataka-o-postanskim-uredima-6543/6543 has 6000+ cities. I think going with 500+ cities makes things simpler, you can enter village name in the address field Looking forward for the opinions. |
Added UI changes, resolved conflicts Thanks for the comments, I will have a look at them in the morning and amend the code before I do a proper QA on this card |
deprecated by #107 |
WIP for improving ad search by city/county
As a source of city/county data I used: https://uprava.gov.hr/o-ministarstvu/ustrojstvo/uprava-za-politicki-sustav-i-organizaciju-uprave/lokalna-i-podrucna-regionalna-samouprava/popis-zupanija-gradova-i-opcina/846
For the sake of simplicity i did not cater for "opcina/grad" difference so all locations are treated like Cities but if needed I can add support for that. I propose that we drop the "City" name and call it just 'Location' which belongs to a County
TODO: Proper PR description :)