From af47383a6c843416255c2b037f5e6d7ad2561e0f Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Mon, 10 Jul 2017 10:30:33 -0400 Subject: [PATCH] Fixed unit tests, updated docs --- app/migrations/0005_auto_20170707_1014.py | 2 +- app/migrations/0006_task_available_assets.py | 3 ++- app/models.py | 1 + app/tests/test_api_task.py | 28 +++++++++++++------- slate/examples/process_images.py | 2 +- slate/source/includes/_quickstart.md | 2 +- slate/source/includes/reference/_task.md | 28 +++++++++++--------- 7 files changed, 39 insertions(+), 27 deletions(-) diff --git a/app/migrations/0005_auto_20170707_1014.py b/app/migrations/0005_auto_20170707_1014.py index 0f4e7b77..15ff7138 100644 --- a/app/migrations/0005_auto_20170707_1014.py +++ b/app/migrations/0005_auto_20170707_1014.py @@ -5,10 +5,10 @@ from __future__ import unicode_literals from django.contrib.gis.gdal import GDALRaster, OGRGeometry from django.contrib.gis.geos import GEOSGeometry from django.db import migrations -from app.models import Task import os def transfer_existing_orthophoto_extent_values(apps, schema_editor): + Task = apps.get_model('app', 'Task') for t in Task.objects.all(): print("Checking {}".format(t)) diff --git a/app/migrations/0006_task_available_assets.py b/app/migrations/0006_task_available_assets.py index c1c44b10..705af948 100644 --- a/app/migrations/0006_task_available_assets.py +++ b/app/migrations/0006_task_available_assets.py @@ -4,10 +4,11 @@ from __future__ import unicode_literals import django.contrib.postgres.fields from django.db import migrations, models -from app.models import Task def detect_available_assets(apps, schema_editor): + Task = apps.get_model('app', 'Task') + for t in Task.objects.all(): print("Updating {}".format(t)) t.update_available_assets_field(True) diff --git a/app/models.py b/app/models.py index fbf60c28..ebf9af00 100644 --- a/app/models.py +++ b/app/models.py @@ -450,6 +450,7 @@ class Task(models.Model): logger.info("Populated orthophoto_extent for {}".format(self)) + self.update_available_assets_field() self.save() else: # FAILED, CANCELED diff --git a/app/tests/test_api_task.py b/app/tests/test_api_task.py index 9888ece8..8d2a5931 100644 --- a/app/tests/test_api_task.py +++ b/app/tests/test_api_task.py @@ -7,6 +7,7 @@ import shutil import logging from datetime import timedelta +import json import requests from django.contrib.auth.models import User from django.contrib.gis.gdal import GDALRaster @@ -172,8 +173,8 @@ class TestApiTask(BootTransactionTestCase): self.assertTrue(res.status_code == status.HTTP_404_NOT_FOUND) # Cannot download assets (they don't exist yet) - for asset in task.ASSET_DOWNLOADS: - res = client.get("/api/projects/{}/tasks/{}/download/{}/".format(project.id, task.id, asset)) + for asset in list(task.ASSETS_MAP.keys()): + res = client.get("/api/projects/{}/tasks/{}/download/{}".format(project.id, task.id, asset)) self.assertTrue(res.status_code == status.HTTP_404_NOT_FOUND) # Cannot access raw assets (they don't exist yet) @@ -213,21 +214,28 @@ class TestApiTask(BootTransactionTestCase): self.assertTrue(task.status == status_codes.COMPLETED) # Can download assets - for asset in task.ASSET_DOWNLOADS: - res = client.get("/api/projects/{}/tasks/{}/download/{}/".format(project.id, task.id, asset)) + for asset in list(task.ASSETS_MAP.keys()): + res = client.get("/api/projects/{}/tasks/{}/download/{}".format(project.id, task.id, asset)) self.assertTrue(res.status_code == status.HTTP_200_OK) # A textured mesh archive file should exist - self.assertTrue(os.path.exists(task.assets_path(task.get_textured_model_filename()))) + self.assertTrue(os.path.exists(task.assets_path(task.ASSETS_MAP["textured_model.zip"]["deferred_path"]))) # Can download raw assets res = client.get("/api/projects/{}/tasks/{}/assets/odm_orthophoto/odm_orthophoto.tif".format(project.id, task.id)) self.assertTrue(res.status_code == status.HTTP_200_OK) - # Can access tiles.json and individual tiles + # Can access tiles.json res = client.get("/api/projects/{}/tasks/{}/tiles.json".format(project.id, task.id)) self.assertTrue(res.status_code == status.HTTP_200_OK) + # Bounds are what we expect them to be + # (4 coords in lat/lon) + tiles = json.loads(res.content) + self.assertTrue(len(tiles['bounds']) == 4) + self.assertTrue(tiles['bounds'][0] == -91.99451323800884) + + # Can access individual tiles res = client.get("/api/projects/{}/tasks/{}/tiles/16/16020/42443.png".format(project.id, task.id)) self.assertTrue(res.status_code == status.HTTP_200_OK) @@ -371,11 +379,11 @@ class TestApiTask(BootTransactionTestCase): # orthophoto_extent should be none self.assertTrue(task.orthophoto_extent is None) - # Available assets should be missing the geotiff type - # but others such as texturedmodel should be available + # Available assets should be missing orthophoto.tif type + # but others such as textured_model.zip should be available res = client.get("/api/projects/{}/tasks/{}/".format(project.id, task.id)) - self.assertFalse('geotiff' in res.data['available_assets']) - self.assertTrue('texturedmodel' in res.data['available_assets']) + self.assertFalse('orthophoto.tif' in res.data['available_assets']) + self.assertTrue('textured_model.zip' in res.data['available_assets']) image1.close() image2.close() diff --git a/slate/examples/process_images.py b/slate/examples/process_images.py index 8f1f6bb3..644d415c 100644 --- a/slate/examples/process_images.py +++ b/slate/examples/process_images.py @@ -76,7 +76,7 @@ if 'token' in res: sys.stdout.write("\rProcessing... [%02d:%02d:%02d]" % (h, m, s)) sys.stdout.flush() - res = requests.get("http://localhost:8000/api/projects/{}/tasks/{}/download/geotiff/".format(project_id, task_id), + res = requests.get("http://localhost:8000/api/projects/{}/tasks/{}/download/orthophoto.tif".format(project_id, task_id), headers={'Authorization': 'JWT {}'.format(token)}, stream=True) with open("orthophoto.tif", 'wb') as f: diff --git a/slate/source/includes/_quickstart.md b/slate/source/includes/_quickstart.md index 36f62607..65138c68 100644 --- a/slate/source/includes/_quickstart.md +++ b/slate/source/includes/_quickstart.md @@ -86,7 +86,7 @@ We periodically check for the [Task](#task) status using a loop.
```python -res = requests.get("http://localhost:8000/api/projects/{}/tasks/{}/download/geotiff/".format(project_id, task_id), +res = requests.get("http://localhost:8000/api/projects/{}/tasks/{}/download/orthophoto.tif".format(project_id, task_id), headers={'Authorization': 'JWT {}'.format(token)}, stream=True) with open("orthophoto.tif", 'wb') as f: diff --git a/slate/source/includes/reference/_task.md b/slate/source/includes/reference/_task.md index bc053cf8..55701787 100644 --- a/slate/source/includes/reference/_task.md +++ b/slate/source/includes/reference/_task.md @@ -9,12 +9,13 @@ "processing_node": 10, "images_count": 48, "available_assets": [ - "all", - "geotiff", - "texturedmodel", - "las", - "csv", - "ply" + "all.zip", + "orthophoto.tif", + "orthophoto.png", + "georeferenced_model.las", + "georeferenced_model.ply", + "georeferenced_model.csv", + "textured_model.zip" ], "uuid": "4338d684-91b4-49a2-b907-8ba171894393", "name": "Task Name", @@ -118,16 +119,17 @@ Retrieves all [Task](#task) items associated with `project_id`. `GET /api/projects/{project_id}/tasks/{task_id}/download/{asset}/` -After a task has been successfully processed, the user can download several assets from this URL. Not all assets are always available. For example if GPS information is missing from the input images, the `geotiff` asset will be missing. You can check the `available_assets` property of a [Task](#task) to see which assets are available for download. +After a task has been successfully processed, the user can download several assets from this URL. Not all assets are always available. For example if GPS information is missing from the input images, the `orthophoto.tif` asset will be missing. You can check the `available_assets` property of a [Task](#task) to see which assets are available for download. Asset | Description ----- | ----------- -all | Archive (.zip) containing all assets, including an orthophoto, TMS tiles, a textured 3D model and point cloud in various formats. -geotiff | GeoTIFF orthophoto. -texturedmodel | Archive (.zip) containing the textured 3D model -las | Point cloud in .LAS format. -ply | Point cloud in .PLY format. -csv | Point cloud in .CSV format. +all.zip | Archive (.zip) containing all assets, including an orthophoto, TMS tiles, a textured 3D model and point cloud in various formats. +orthophoto.tif | GeoTIFF orthophoto. +orthophoto.png | PNG orthophoto. +textured_model.zip | Archive containing the textured 3D model +georeferenced_model.las | Point cloud in .LAS format. +georeferenced_model.ply | Point cloud in .PLY format. +georeferenced_model.csv | Point cloud in .CSV format. ### Download assets (raw path)