Skip to content

Commit

Permalink
Fix Maproulette export
Browse files Browse the repository at this point in the history
  • Loading branch information
frodrigo committed Sep 2, 2023
1 parent ce596b2 commit e4de726
Showing 1 changed file with 63 additions and 59 deletions.
122 changes: 63 additions & 59 deletions api/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,68 +392,72 @@ async def issues_maproulette_jsonl(
type_map = {"N": "node", "W": "way", "R": "relation"}
return [
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
properties["lon"],
properties["lat"],
],
},
"properties": {
k: v
for k, v in properties.items()
if k in ("title", "subtitle", "timestamp") and v != ""
},
},
],
"cooperativeWork": {
"meta": {"version": 2, "type": 1},
"operations": [
k: v
for k, v in {
"type": "FeatureCollection",
"features": [
{
"operationType": "modifyElement",
"data": {
"id": f"{type_map[obj['type']]}/{obj['id']}",
"operations": list(
filter(
lambda a: a is not None,
[
{
"operation": "setTags",
"data": {
k: v
for k, v in {
**obj.get("create", {}),
**obj.get("modify", {}),
}.items()
},
}
if len(obj.get("create", {}))
+ len(obj.get("modify", {}))
>= 1
else None,
{
"operation": "unsetTags",
"data": [k for k in obj["delete"]],
}
if "delete" in obj
else None,
],
)
),
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
properties["lon"],
properties["lat"],
],
},
}
for obj in properties["fixes"][0]
"properties": {
k: v
for k, v in properties.items()
if k in ("title", "subtitle", "timestamp") and v != ""
},
},
],
}
if "fixes" in properties
and properties["fixes"] is not None
and len(properties["fixes"]) == 1
and properties["fixes"][0][0].get("id") is not None
else None,
"cooperativeWork": {
"meta": {"version": 2, "type": 1},
"operations": [
{
"operationType": "modifyElement",
"data": {
"id": f"{type_map[obj['type']]}/{obj['id']}",
"operations": list(
filter(
lambda a: a is not None,
[
{
"operation": "setTags",
"data": {
k: v
for k, v in {
**obj.get("create", {}),
**obj.get("modify", {}),
}.items()
},
}
if len(obj.get("create", {}))
+ len(obj.get("modify", {}))
>= 1
else None,
{
"operation": "unsetTags",
"data": [k for k in obj["delete"]],
}
if "delete" in obj
else None,
],
)
),
},
}
for obj in properties["fixes"][0]
],
}
if "fixes" in properties
and properties["fixes"] is not None
and len(properties["fixes"]) == 1
and properties["fixes"][0][0].get("id") is not None
else None,
}.items()
if v is not None
}
for properties in issues
]

0 comments on commit e4de726

Please sign in to comment.