-
-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for extra_properties in per task instructions #659
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""empty message | ||
|
||
Revision ID: deec8123583d | ||
Revises: ac55902fcc3d | ||
Create Date: 2018-08-07 23:09:58.621826 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from server.models.postgis.project import Project | ||
from server.models.postgis.task import Task | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'deec8123583d' | ||
down_revision = 'ac55902fcc3d' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
projects = Project.__table__ | ||
tasks = Task.__table__ | ||
|
||
def upgrade(): | ||
conn = op.get_bind() | ||
|
||
for project in conn.execute(projects.select()): | ||
zooms = conn.execute( | ||
sa.sql.expression.select([tasks.c.zoom]).distinct(tasks.c.zoom) | ||
.where(tasks.c.project_id == project.id)) | ||
zooms = zooms.fetchall() | ||
|
||
if len(zooms) == 1 and zooms[0] == (None,): | ||
op.execute( | ||
projects.update().where(projects.c.id == project.id) | ||
.values(task_creation_mode=1)) | ||
else: | ||
op.execute( | ||
projects.update().where(projects.c.id == project.id) | ||
.values(task_creation_mode=0)) | ||
|
||
|
||
def downgrade(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import bleach | ||
import datetime | ||
import geojson | ||
import json | ||
from enum import Enum | ||
from geoalchemy2 import Geometry | ||
from server import db | ||
|
@@ -142,6 +143,7 @@ class Task(db.Model): | |
x = db.Column(db.Integer) | ||
y = db.Column(db.Integer) | ||
zoom = db.Column(db.Integer) | ||
extra_properties = db.Column(db.Unicode) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: this column already exists in the database (added through the migrations), but it wasn't mapped into the DB models. |
||
# Tasks are not splittable if created from an arbitrary grid or were clipped to the edge of the AOI | ||
splittable = db.Column(db.Boolean, default=True) | ||
geometry = db.Column(Geometry('MULTIPOLYGON', srid=4326)) | ||
|
@@ -198,6 +200,10 @@ def from_geojson_feature(cls, task_id, task_feature): | |
except KeyError as e: | ||
raise InvalidData(f'Task: Expected property not found: {str(e)}') | ||
|
||
if 'extra_properties' in task_feature.properties: | ||
task.extra_properties = json.dumps( | ||
task_feature.properties['extra_properties']) | ||
|
||
task.id = task_id | ||
task_geojson = geojson.dumps(task_geometry) | ||
task.geometry = ST_SetSRID(ST_GeomFromGeoJSON(task_geojson), 4326) | ||
|
@@ -446,18 +452,20 @@ def format_per_task_instructions(self, instructions) -> str: | |
if not instructions: | ||
return '' # No instructions so return empty string | ||
|
||
# If there's no dynamic URL (e.g. url containing '{x}, {y} and {z}' pattern) | ||
# - ALWAYS return instructions unaltered | ||
|
||
if not all(item in instructions for item in ['{x}','{y}','{z}']): | ||
return instructions | ||
|
||
# If there is a dyamic URL only return instructions if task is splittable, since we have the X, Y, Z | ||
if not self.splittable: | ||
return 'No extra instructions available for this task' | ||
properties = {} | ||
|
||
instructions = instructions.replace('{x}', str(self.x)) | ||
instructions = instructions.replace('{y}', str(self.y)) | ||
instructions = instructions.replace('{z}', str(self.zoom)) | ||
if self.x: | ||
properties['x'] = str(self.x) | ||
if self.y: | ||
properties['y'] = str(self.y) | ||
if self.zoom: | ||
properties['z'] = str(self.zoom) | ||
if self.extra_properties: | ||
properties.update(json.loads(self.extra_properties)) | ||
|
||
try: | ||
instructions = instructions.format(**properties) | ||
except KeyError: | ||
pass | ||
return instructions | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"areaOfInterest": { | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[ | ||
1275275.3796814454, | ||
2828783.0982895694 | ||
], | ||
[ | ||
1275200.6907704484, | ||
2828781.542271093 | ||
], | ||
[ | ||
1275016.6455451597, | ||
2828781.542271093 | ||
], | ||
[ | ||
1275275.3796814454, | ||
2828783.0982895694 | ||
] | ||
] | ||
] | ||
}, | ||
"properties": { | ||
"foo": "bar" | ||
} | ||
} | ||
] | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this column already exists in the database (added through the migrations), but it wasn't mapped into the DB models.