hotosm / osm-tasking-manager2

Designed and built for Humanitarian OpenStreetMap Team collaborative emergency/disaster mapping, the OSM Tasking Manager 2.0 divides an area into individual squares that can be rapidly mapped by thousands of volunteers.
http://tasks.hotosm.org
Other
425 stars 156 forks source link

Correcting extra properties assignment #1007

Open praveen-k-g opened 6 years ago

pgiraud commented 6 years ago

This obviously breaks the tests because it was not meant to be handled that way. extra_properties was designed to get anything from the JSON properties key.

praveen-k-g commented 6 years ago

What I understand by looking at the code is that properties contains few fields like x,y,zoom, geometry and extra_properties(which is a map used for 'per task instructions'). If you look at the function def init(self, x, y, zoom, geometry=None, properties=None): in models.py properties already contains x,y,zoom,geometry. and if you assign properties which is passed as argument to extra_properties( i.e self.extra_properties = unicode(_dumps(properties)) ) then extra_properties not only contains the extra _properties that one provide but also contains x,y,zoom, geometry and other stuff and it breaks when you actually select a task for mapping for the projects where you have provided 'Per Task Instructions’.

For e.g.. lets say If I create a single task with the following properties {"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"MultiPolygon","coordinates":[[[[174.7002,-36.53508],[174.7002,-36.54586],[174.71066,-36.54632],[174.71066,-36.53555],[174.7002,-36.53508]]]]},"properties":{"x":null,"y":null,"zoom":null,"extra_properties":{"p1":"v1"}}}]}

Then if you check extra_properties in pgsql it would be something like {"y": null, "x": null, "zoom": null, "extra_properties": {"p1": "v1”}} which is wrong

It should be something like {"p1": "v1”}. This you would get if you make the change that I made.

Moreover you can try creating a task with extra_properties, by copying the above geojson and putting the below code snippet in per Task instructions in UI while creating the task. Code snippet —> value - {p1} or you can put any random geojson with extra_properties(instructions per task) it will fail, when you will try loading that task for contribution.

Let me know if I have misunderstood anything here.

pgiraud commented 6 years ago

The input JSON is supposed to be formatted like so:

{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "geometry": {
            "type": "MultiPolygon",
            "coordinates": [
                [
                    [
                        [174.7002, -36.53508],
                        [174.7002, -36.54586],
                        [174.71066, -36.54632],
                        [174.71066, -36.53555],
                        [174.7002, -36.53508]
                    ]
                ]
            ]
        },
        "properties": {
            "p1": "v1"
        }
    }]
}
praveen-k-g commented 6 years ago

Got it. One question here. What's the use of these extra_properties here then?

pgiraud commented 6 years ago

As you mentioned, it's meant to be used for "per task" instructions. For example you could decide to divide a region into small divisions each of which has it's own unique identifier. Then you could ask the user to download some data for the division by providing a url built with the division id which would point to a document stored somewhere on a server.

The JSON could be:

{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "geometry": {
            "type": "MultiPolygon",
            "coordinates": [
                [
                    [
                        [174.7002, -36.53508],
                        [174.7002, -36.54586],
                        [174.71066, -36.54632],
                        [174.71066, -36.53555],
                        [174.7002, -36.53508]
                    ]
                ]
            ]
        },
        "properties": {
            "name": "San_Francisco"
        }
    }]
}

And per task instructions:

Please download extra information about this location at [wikipedia](https://en.wikipedia.org/wiki/{name})

It has been used in the past for Africa with links to data to import into OSM.