Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Workers
Base Worker
Commits
eb0abab6
Commit
eb0abab6
authored
2 years ago
by
Yoann Schneider
Committed by
Bastien Abadie
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add element polygon shortcut as a property
parent
02f4a0c1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!234
Add element polygon shortcut as a property
Pipeline
#79702
passed
2 years ago
Stage: release
Stage: deploy
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex_worker/models.py
+14
-1
14 additions, 1 deletion
arkindex_worker/models.py
tests/test_element.py
+15
-0
15 additions, 0 deletions
tests/test_element.py
with
29 additions
and
1 deletion
arkindex_worker/models.py
+
14
−
1
View file @
eb0abab6
...
...
@@ -5,7 +5,7 @@ Wrappers around API results to provide more convenient attribute access and IIIF
import
tempfile
from
contextlib
import
contextmanager
from
typing
import
Generator
,
Optional
from
typing
import
Generator
,
List
,
Optional
from
PIL
import
Image
from
requests
import
HTTPError
...
...
@@ -93,6 +93,19 @@ class Element(MagicDict):
url
+=
"
/
"
return
"
{}full/{}/0/default.jpg
"
.
format
(
url
,
size
)
@property
def
polygon
(
self
)
->
List
[
float
]:
"""
Access an Element
'
s polygon.
This is a shortcut to an Element
'
s polygon, normally accessed via
its zone field via `zone.polygon`. This is mostly done
to facilitate access to this important field by matching
the [CachedElement][arkindex_worker.cache.CachedElement].polygon field.
"""
if
not
self
.
get
(
"
zone
"
):
raise
ValueError
(
"
Element {} has no zone
"
.
format
(
self
.
id
))
return
self
.
zone
.
polygon
@property
def
requires_tiles
(
self
)
->
bool
:
"""
...
...
This diff is collapsed.
Click to expand it.
tests/test_element.py
+
15
−
0
View file @
eb0abab6
...
...
@@ -2,6 +2,7 @@
import
pytest
from
requests
import
HTTPError
from
arkindex_worker.cache
import
CachedElement
from
arkindex_worker.models
import
Element
...
...
@@ -402,3 +403,17 @@ def test_setattr_setitem():
element
=
Element
({
"
name
"
:
"
something
"
})
element
.
type
=
"
page
"
assert
dict
(
element
)
==
{
"
name
"
:
"
something
"
,
"
type
"
:
"
page
"
}
def
test_element_polygon
():
polygon
=
[[
0
,
0
],
[
181
,
0
],
[
181
,
240
],
[
0
,
240
],
[
0
,
0
]]
element
=
Element
({
"
zone
"
:
{
"
polygon
"
:
polygon
}})
cached_element
=
CachedElement
(
polygon
=
polygon
)
assert
element
.
polygon
==
polygon
assert
element
.
polygon
==
cached_element
.
polygon
def
test_element_no_polygon
():
element
=
Element
(
id
=
"
element_id
"
)
with
pytest
.
raises
(
ValueError
,
match
=
"
Element element_id has no zone
"
):
_
=
element
.
polygon
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment