-
Notifications
You must be signed in to change notification settings - Fork 522
Use numbered administrative level instead of named one #398
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
Use numbered administrative level instead of named one #398
Conversation
Yes.
AdminLevel
I am fine with it. I guess. Can we restrict this depth or it really depends on the location?
%A1, %A2 sounds good to me. |
890bed9
to
5b0e0db
Compare
As far as I know (i.e. the Geoname database), the depth is at most 4, and in some rare case is 5. Geonames doesn't support admin level 5 very well, so I suspect is very rare. For now, I'm just migrating the providers code so the maximum level for is 2. I may throw an exception if the admin depth is above 5 and we are safe, though. I'll rename the class to (PS: I've fixed the mail address of my commit in the message above) |
@@ -34,9 +34,9 @@ public function testCreateFromArray() | |||
foreach ($addresses as $address) { | |||
$this->assertInstanceOf('Geocoder\Model\Address', $address); | |||
$this->assertNull($address->getCoordinates()); | |||
$this->assertInstanceOf('Geocoder\Model\County', $address->getCounty()); | |||
$this->assertInstanceOf('Geocoder\Model\County', $address->getAdmins()[1]); |
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 the assertion is wrong, it should assert than it's an instance of Geocoder\Model\Admin
(and AdminLevel
after you change it) 😉
Edit: the same change will be needed in a lot of test
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.
Sure, I've started backward alphabetical order when fixing tests :) I have failing tests from A-GeoIP.
Small proposition: What about adding a Also, currently the |
@pyrech I think that the idea of having I;ve looked into OpenStreetMap docs you supplied, but the value they expose is not the "administrative level" strictly speaking. As you can see, table data are sparse; in particular:
IMO, the OpenStreetMap approach is too sparse, and must be aligned to something like Geonames or GMap (e.g maps.api/?country=Spain&postalCode=08001). |
@giosh94mhz Yes, you're completely right about their structure. I was more refering to the fact they start to the level 1 instead of 0 and the GMap example is indeed far better. Do you think that Edit: I just saw that you were already requesting feedback on this aspect, so let's see what the core team think about that! 😄 In addition, maybe a method |
@pyrech Ok, now I got it :) I though that it was a bit ugly the first time I wrote An alternative may be to have a syntactic sugar like: public function getAdmins()
{
return $this->admins;
}
public function getAdmin($level)
{
return isset($this->admins[$level-1]) ? $this->admins[$level-1] : null /* or maybe null obj if $level <= 4 or 5 */;
} |
@giosh94mhz Hehe, we came to the same conclusion (I edited my previous comment in the same time)! :) |
Ok, I've renamed I've also used I'm trying to forcing a limit to admin level [1,5] wherever possible. I'm also checking the api docs of some provider, to see if there is support for multiple admin levels (2+). Along the way I find some minor bugs as in commit 91b2e0d. @willdurand may I add it here (and not squashing in the end), or you prefer me to create another PR? I'll wait for your feedback about |
); | ||
} | ||
|
||
ksort($adminLevels, SORT_NUMERIC); |
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.
Is this needed? I see no reason for this.
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 I've added a test which expose this, but here the PHP magic to solve:
$admins = [];
$admins[2] = 'admin 2';
$admins[1] = 'admin 1';
echo implode(', ', $admins) . "\n";
foreach ($admins as $level => $admin) {
echo $level . ': ' . $admin . "\n";
}
expected:
admin1, admin2
1: admin 1
2: admin 2
actual:
admin2, admin1
2: admin 2
1: admin 1
Since Providers deal with external data, I think is much safer to sort it out explicitely. Anyway, all of this is solved by introducing the AdminLevelCollection
class.
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.
Ah cool, didn't see this test. Anyway i agree with you, this is more logical 👍
Really great work @giosh94mhz.
Yes
Its enough, but i would enforce a string cast, so PHP does not made any magic with this array.
I would tend to %A1, %A2, %A3, ... |
Nice work @giosh94mhz !!
We can maybe use a
I agree with @Baachi |
+1 for the collection +1 for adding commits to this PR, we will see how to deal with all the commits later |
thank you for making this real! |
Thanks @Baachi, @toin0u and @willdurand for your feedback and support!
PHP is full of magic, which one in particular? :) String are not so comfortable to use, since I'm actually dealing with numbers and have some checks for array bounds.
I'm also 👍 for this, now that I think of it.
I'll keep index-based array for the internal result data. |
I now, but i have some strange issues with it (i don't remember exactly which one). But if we decide to introduce an |
I would tend to use the |
@Baachi I didn't know about Here's my thought
So I think I'll create a new class and eventually try to use What do you think? |
The performance should be irrelevant. I would it only use if you have less code to write and its easier to maintain. If its more work, build your own :) |
From what I've read, This evening I'll work a bit more... I'll keep you up to date. |
Here I am! :) I've finished testing the providers, but I may need some help with testing which use api-keys... Hopefully travis will help. About the
Along the way, I have:
I think there is a more room for improvements. We may:
|
👎 I like Symfony "ParameterBag" API.
👎 I'd like to keep collections read-only as much as possible
What is the current impl of |
Ok, let's keep it like that.
Me too. I've avoided read-write interface for this patch.
|
e62a4b5
to
ef2cad0
Compare
Ok, I've finally got all the api keys and tested all the providers with real data. I've fixed the commit history (all commit have passing tests), so that fixes I've fond along the way have a separate commit from the new admin feature. Testing are now passing, but if I set @willdurand I've fixed the collection interfaces as in |
Wow ! Amazing job ! I'll review it as well asap :) |
👍 |
f560078
to
990ab98
Compare
Rebased on master :) |
)); | ||
]; | ||
|
||
for ($level = 1; $level <= AdminLevelCollection::MAX_LEVEL_DEPTH; ++ $level) { |
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.
would be nice to write $level++
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.
Of course. But don't tell C++ developers I did it :P
Last nitpicks. Time to get this merged! |
👍 done! |
Use numbered administrative level instead of named one
\o/ |
@giosh94mhz Awesome!!! 🎆 |
Really cool! 🎆 |
Thank you everyone! You gave me great support and feedback! |
PR for for ticket #392. To sum up: replace every occurrence of
region
andcounty
(no "r"), with a genericadmin
level array.TODOs:
I'll like to hear you feedback about:
AbstractProvider::getDefaults
the admins value defaults to[]
to simplify a bit the code. Is it ok?Admin
a clear class name or it is better to call itAdminLevel
(as in [RFC] Use numbered administrative level instead of named one #392)?%R
and%P
forRegion
andCounty
, but this no longer make sense. What should be used?%A1
,%A2
,%A3
,%A4
?%A0
,%A1
,%A2
,%A3
(as the array index, not the admin level)?%X
,%Y
,%Z
,%W
(as in math :)? Something else?