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
Merge requests
!378
Add an API helper to update an element
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add an API helper to update an element
partial-update-element-helper
into
master
Overview
1
Commits
3
Pipelines
5
Changes
2
All threads resolved!
Hide all comments
Merged
Manon Blanco
requested to merge
partial-update-element-helper
into
master
1 year ago
Overview
1
Commits
3
Pipelines
5
Changes
2
All threads resolved!
Hide all comments
Expand
Closes
#222 (closed)
0
0
Merge request reports
Compare
master
version 4
d193cf5c
1 year ago
version 3
902a2271
1 year ago
version 2
01f80bde
1 year ago
version 1
f22ec110
1 year ago
master (base)
and
latest version
latest version
456357d8
3 commits,
1 year ago
version 4
d193cf5c
3 commits,
1 year ago
version 3
902a2271
2 commits,
1 year ago
version 2
01f80bde
1 commit,
1 year ago
version 1
f22ec110
1 commit,
1 year ago
2 files
+
260
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
arkindex_worker/worker/element.py
+
64
−
0
Options
@@ -275,6 +275,70 @@ class ElementMixin(object):
return
created_ids
def
update_element
(
self
,
element
:
Union
[
Element
,
CachedElement
],
type
:
Optional
[
str
]
=
None
,
name
:
Optional
[
str
]
=
None
,
polygon
:
Optional
[
List
[
List
[
Union
[
int
,
float
]]]]
=
None
,
confidence
:
Optional
[
float
]
=
None
,
)
->
dict
:
"""
Partially update an element through the API.
:param element: The element to update.
:param type: Optional new slug type of the element.
:param name: Optional new name of the element.
:param polygon: Optional new polygon of the element.
:param confidence: Optional new confidence score, between 0.0 and 1.0.
:returns: A dict from the ``PartialUpdateElement`` API endpoint,
"""
assert
element
and
isinstance
(
element
,
(
Element
,
CachedElement
)
),
"
element shouldn
'
t be null and should be an Element or CachedElement
"
assert
type
is
None
or
isinstance
(
type
,
str
),
"
type should be None or a str
"
assert
name
is
None
or
isinstance
(
name
,
str
),
"
name should be None or a str
"
assert
polygon
is
None
or
isinstance
(
polygon
,
list
),
"
polygon should be None or a list
"
if
polygon
:
assert
len
(
polygon
)
>=
3
,
"
polygon should have at least three points
"
assert
all
(
isinstance
(
point
,
list
)
and
len
(
point
)
==
2
for
point
in
polygon
),
"
polygon points should be lists of two items
"
assert
all
(
isinstance
(
coord
,
(
int
,
float
))
for
point
in
polygon
for
coord
in
point
),
"
polygon points should be lists of two numbers
"
assert
confidence
is
None
or
(
isinstance
(
confidence
,
float
)
and
0
<=
confidence
<=
1
),
"
confidence should be None or a float in [0..1] range
"
if
self
.
is_read_only
:
logger
.
warning
(
"
Cannot update element as this worker is in read-only mode
"
)
return
updated_element
=
self
.
request
(
"
PartialUpdateElement
"
,
id
=
element
.
id
,
body
=
{
"
type
"
:
type
,
"
name
"
:
name
,
"
polygon
"
:
polygon
,
"
confidence
"
:
confidence
,
},
)
if
self
.
use_cache
:
CachedElement
.
update
(
{
CachedElement
.
type
:
type
,
CachedElement
.
polygon
:
str
(
polygon
),
CachedElement
.
confidence
:
confidence
,
}
).
where
(
CachedElement
.
id
==
element
.
id
).
execute
()
return
updated_element
def
list_element_children
(
self
,
element
:
Union
[
Element
,
CachedElement
],
Loading