Skip to content

Commit

Permalink
Mapillary v4 implementation (#66)
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>

migrations: 7408ceebbef7: Project files don't need to add indexes

The indexes are added in a separate upstream migration.

Signed-off-by: Taylor Smock <[email protected]>

Initial Mapillary frontend

Signed-off-by: Taylor Smock <[email protected]>

Translate tile geom coords to lat lon coords when setting geometry for a tile

Properly determine cutoff keys, will need to have recursion for tile fetching

Remove features after adding to task, move computing tasks to separate function, add org param

Determine if geom is in original bbox, add basic state to frontend for displaying failed sequence state

Formatted messages, properly buffer geometry (for both front and backend), UI enhancements

Co-authored-by: Taylor Smock <[email protected]>
  • Loading branch information
andrewcp54 and tsmock authored Jun 16, 2021
1 parent a3f513c commit cbb00b2
Show file tree
Hide file tree
Showing 15 changed files with 948 additions and 196 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ ifndef DOCKER_COMPOSE_VERSION
endif

build:
docker-compose build --no-cache app
docker-compose build --no-cache backend frontend

up:
docker network inspect tm-web >/dev/null 2>&1 || \
docker network create tm-web
docker-compose up -d
docker-compose up

down:
docker-compose down
Expand All @@ -24,21 +24,21 @@ list:
docker-compose ps

refresh-frontend:
docker-compose exec app sh -c "cd frontend && npm run build"
docker-compose exec frontend sh -c "cd frontend && npm run build"

refresh-translatables:
docker-compose exec app sh -c "cd frontend && yarn build-locales"
docker-compose exec frontend sh -c "cd frontend && yarn build-locales"

refresh-translations:
docker-compose exec app sh -c "tx pull -af"
docker-compose exec frontend sh -c "tx pull -af"

tests:test-frontend test-backend

test-frontend:
docker-compose exec app sh -c "cd /usr/src/app/frontend && CI=true npm test"
docker-compose exec frontend sh -c "cd /usr/src/app/frontend && CI=true npm test"

test-backend:
docker-compose exec app sh -c "python -m unittest discover tests/backend"
docker-compose exec backend sh -c "python -m unittest discover tests/backend"

fetch:
ifndef PRNUMBER
Expand Down
4 changes: 2 additions & 2 deletions backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def add_api_endpoints(app):
from backend.api.system.image_upload import SystemImageUploadRestAPI

# Mapillary API endpoint
from backend.api.mapillary import (
from backend.api.mapillary.mapillary import (
MapillaryTasksAPI,
SequencesAsGPX
)
Expand Down Expand Up @@ -832,4 +832,4 @@ def add_api_endpoints(app):
)

# Mapillary endpoints
api.add_resource(MapillaryTasksAPI, format_url("system/mapillary-tasks"))
api.add_resource(MapillaryTasksAPI, format_url("system/mapillary-tasks/"))
Empty file.
45 changes: 31 additions & 14 deletions backend/api/mapillary/mapillary.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class MapillaryTasksAPI(Resource):

def get(self):
"""
Get Mapillary sequences and return tasks
Expand Down Expand Up @@ -52,30 +51,38 @@ def get(self):
description: Internal Server Error
"""
try:
potential_arguments = ['bbox', 'start_time', 'end_time', 'usernames']
potential_arguments = [
"bbox",
"start_time",
"end_time",
"organization_key",
]
arguments = {}
for argument in potential_arguments:
try:
variable = request.args.get(argument)
if variable is not None:
arguments[argument] = variable
except Exception as e:
current_app.logger.debug(f'Mapillary - key doesn\'t exist {argument}, {str(e)}')
current_app.logger.debug(
f"Mapillary - key doesn't exist {argument}, {str(e)}"
)
tasks = MapillaryService.getMapillarySequences(arguments)
if len(tasks) > 0:
if len(tasks["features"]) > 0:
return tasks, 200
else:
raise NotFound
except NotFound:
return {"Error": "No Mapillary Sequences found with parameters"}, 404
return {
"Error": "No Mapillary Sequences found with parameters"
}, 404
except Exception as e:
error_msg = f'Mapillary GET - unhandled error: {str(e)}'
error_msg = f"Mapillary GET - unhandled error: {str(e)}"
current_app.logger.critical(error_msg)
return {"error": error_msg}, 500


class SequencesAsGPX(Resource):

def get(self, project_id):
"""
Return Mapillary GPX
Expand Down Expand Up @@ -110,19 +117,29 @@ def get(self, project_id):
description: Internal Server Error
"""
try:
tasks = request.args.get('tasks')
as_file = strtobool(request.args.get('as_file')) if request.args.get('as_file') else False
tasks = request.args.get("tasks")
as_file = (
strtobool(request.args.get("as_file"))
if request.args.get("as_file")
else False
)

gpx = MapillaryService.getSequencesAsGPX(project_id, tasks)

if as_file:
return send_file(io.BytesIO(gpx), mimetype='text.xml', as_attachment=True,
attachment_filename=f'Kaart-project-{project_id}-task-{tasks}.gpx')
return send_file(
io.BytesIO(gpx),
mimetype="text.xml",
as_attachment=True,
attachment_filename=f"Kaart-project-{project_id}-task-{tasks}.gpx",
)

return Response(gpx, mimetype='text/xml', status=200)
return Response(gpx, mimetype="text/xml", status=200)
except NotFound:
return {"Error": "No Mapillary Sequences found with parameters"}, 404
return {
"Error": "No Mapillary Sequences found with parameters"
}, 404
except Exception as e:
error_msg = f'Mapillary GET - unhandled error: {str(e)}'
error_msg = f"Mapillary GET - unhandled error: {str(e)}"
current_app.logger.critical(error_msg)
return {"error": error_msg}, 500
Loading

0 comments on commit cbb00b2

Please sign in to comment.