Page MenuHomePhabricator

Implement asynchronous calls to the APIs to match an uploaded picture's GPS coordinates with nearby Commons categories
Closed, ResolvedPublic

Description

As decided in T119278, we will be using Method D: Search for existing pics at that location" strategy (with expanding radius) on the Commons MediaWiki API.

Meeting with @Niedzielski (20 Dec):

Discussed options for implementing the http requests asynchronously. The options we considered were:

  1. Use either a) Volley or b) MwApi + AsyncTask
  2. add a third networking library to the project

1a) appears to be the ideal option, however the project doesn't have any good examples of using that and might need some refactoring to expose request queue. 1b) is less ideal but the project has a number of examples that could easily be mimicked to achieve the requests needed. 2) might be venturing further into uncharted waters and adding another networking lib to the project may convolute networking even more

We decided on trying 1a) first, then reverting to 1b) as backup if the former proves to be too difficult to implement in time. Also discussed output format, which will be XML for ease of use with current implementation. I plan to reuse the current XPath retrieval code in org.mediawiki.api.MWApi.java .

Edit 21 Dec 15 : Will try JSON for response format instead, as it is more standard for Android apps and Volley seems to have inbuilt support for JSON objects but not XML. Trying to construct a Category model for responses.

Edit 22 Dec 15 : Current state of code can be found at https://github.com/misaochan/apps-android-commons/tree/api-calls

Edit 23 Dec 15 : Code works now. Pull request submitted at https://github.com/nicolas-raoul/apps-android-commons/pull/33 (merged). Tested without an internet connection as suggested, no problems except for the usual logcat errors thrown by original app.

Example output:

12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272): query=pages=
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272): PAGEID=23644793 ns=6 title=File:Palermo BW 2012-10-09 12-04-52.jpg
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272):  CATEGORIES=  ns=14 title=Category:Piazza del Duomo (Palermo)
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272):  ns=14 title=Category:Side views of the Cathedral of Palermo
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272): PAGEID=23644966 ns=6 title=File:Palermo BW 2012-10-09 12-07-39.JPG
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272):  CATEGORIES=  ns=14 title=Category:Saint Rosalia by Vincenzo Vitaliano
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272): PAGEID=23644994 ns=6 title=File:Palermo BW 2012-10-09 12-08-06.JPG
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272):  CATEGORIES=  ns=14 title=Category:Saint Rosalia by Vincenzo Vitaliano
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272): PAGEID=23645069 ns=6 title=File:Palermo BW 2012-10-09 12-09-53.JPG
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272):  CATEGORIES=  ns=14 title=Category:Porch of the Cathedral of Palermo
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272): PAGEID=23645121 ns=6 title=File:Palermo BW 2012-10-09 12-10-28.JPG
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272):  CATEGORIES=  ns=14 title=Category:Church towers of the Cathedral of Palermo
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272): PAGEID=27936145 ns=6 title=File:Palermo Cathedral2.JPG
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272):  CATEGORIES=  ns=14 title=Category:Side views of the Cathedral of Palermo
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272): PAGEID=28378903 ns=6 title=File:Catedral de Palermo - Zoom 1 (2786776020).jpg
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272):  CATEGORIES=  ns=14 title=Category:Piazza del Duomo (Palermo)
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272):  ns=14 title=Category:Side views of the Cathedral of Palermo
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272): PAGEID=28379021 ns=6 title=File:Catedral de Palermo (2544992621).jpg
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272):  CATEGORIES=  ns=14 title=Category:Piazza del Duomo (Palermo)
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272): PAGEID=28379336 ns=6 title=File:Catedral de Palermo - Zoom 3 (1037666674).jpg
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272):  CATEGORIES= no categories exist
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272): PAGEID=28379338 ns=6 title=File:Catedral de Palermo - Zoom 2 (1037666802).jpg
12-23 04:56:17.606: D/fr.free.nrw.commons.upload.MwVolleyApi$LogResponseListener(11272):  CATEGORIES= no categories exist

Event Timeline

josephine_l claimed this task.
josephine_l raised the priority of this task from to Medium.
josephine_l updated the task description. (Show Details)
josephine_l set Security to None.
josephine_l updated the task description. (Show Details)

@Nicolas_Raoul @Niedzielski - I'm still mired in the parsing of JSON, but I think it would also be helpful if we could discuss what 'format' we want the categories to be in, in preparation for the next step T119281: Display the resulting categories to the user alongside the "previous categories" that are currently already displayed .

So do we want a helper Category class with Category objects, or are we okay with having the categories for each pageid stored in an array? Or something else that I haven't thought of? How and at what point do we deal with duplicate categories (they won't be duplicated for each pageid, but will be duplicated in different pageids)?

@josephine_l, my personal preference is definitely for JSON. If there's no objections and you're happy to pursue that path, then I say go for it! I've opened a patch on your branch for commenting and left some there. I personally prefer the model to match the JSON as much as needed (it's fine to omit unused fields).

Edit: with the exception that JSON arrays are replaced with Lists :)

josephine_l moved this task from Doing to Done on the Commons-App-Android-Upload board.