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
c4ff8cc2
Commit
c4ff8cc2
authored
4 years ago
by
Valentin Rigal
Browse files
Options
Downloads
Patches
Plain Diff
Handle multiple type reporting for elements and transcriptions
parent
8de32fff
No related branches found
Branches containing commit
Tags
0.3.2-rc6
Tags containing commit
1 merge request
!9
Handle multiple type reporting for elements and transcriptions
Pipeline
#77878
passed
4 years ago
Stage: test
Stage: build
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex_worker/reporting.py
+6
-4
6 additions, 4 deletions
arkindex_worker/reporting.py
tests/test_reporting.py
+34
-0
34 additions, 0 deletions
tests/test_reporting.py
with
40 additions
and
4 deletions
arkindex_worker/reporting.py
+
6
−
4
View file @
c4ff8cc2
...
...
@@ -45,13 +45,14 @@ class Reporter(object):
# Just call the element initializer
self
.
_get_element
(
element_id
)
def
add_element
(
self
,
parent_id
,
type
):
def
add_element
(
self
,
parent_id
,
type
,
type_count
=
1
):
"""
Report creating a single element with a parent.
Multiple elements with the same type and parent can be declared with the type_count parameter.
"""
elements
=
self
.
_get_element
(
parent_id
)[
"
elements
"
]
elements
.
setdefault
(
type
,
0
)
elements
[
type
]
+=
1
elements
[
type
]
+=
type_count
def
add_classification
(
self
,
element_id
,
class_name
):
"""
...
...
@@ -77,13 +78,14 @@ class Reporter(object):
)
element
[
"
classifications
"
]
=
dict
(
counter
)
def
add_transcription
(
self
,
element_id
,
type
):
def
add_transcription
(
self
,
element_id
,
type
,
type_count
=
1
):
"""
Report creating a transcription on an element.
Multiple transcriptions with the same type and parent can be declared with the type_count parameter.
"""
transcriptions
=
self
.
_get_element
(
element_id
)[
"
transcriptions
"
]
transcriptions
.
setdefault
(
type
,
0
)
transcriptions
[
type
]
+=
1
transcriptions
[
type
]
+=
type_count
def
add_transcriptions
(
self
,
element_id
,
transcriptions
):
"""
...
...
This diff is collapsed.
Click to expand it.
tests/test_reporting.py
+
34
−
0
View file @
c4ff8cc2
...
...
@@ -41,6 +41,23 @@ def test_add_element():
}
def
test_add_element_count
():
"""
Report multiple elements with the same parent and type
"""
reporter
=
Reporter
(
"
worker
"
)
reporter
.
add_element
(
"
myelement
"
,
type
=
"
text_line
"
,
type_count
=
42
)
assert
"
myelement
"
in
reporter
.
report_data
[
"
elements
"
]
element_data
=
reporter
.
report_data
[
"
elements
"
][
"
myelement
"
]
del
element_data
[
"
started
"
]
assert
element_data
==
{
"
elements
"
:
{
"
text_line
"
:
42
},
"
transcriptions
"
:
{},
"
classifications
"
:
{},
"
errors
"
:
[],
}
def
test_add_classification
():
reporter
=
Reporter
(
"
worker
"
)
reporter
.
add_classification
(
"
myelement
"
,
"
three
"
)
...
...
@@ -97,6 +114,23 @@ def test_add_transcription():
}
def
test_add_transcription_count
():
"""
Report multiple transcriptions with the same element and type
"""
reporter
=
Reporter
(
"
worker
"
)
reporter
.
add_transcription
(
"
myelement
"
,
"
word
"
,
type_count
=
1337
)
assert
"
myelement
"
in
reporter
.
report_data
[
"
elements
"
]
element_data
=
reporter
.
report_data
[
"
elements
"
][
"
myelement
"
]
del
element_data
[
"
started
"
]
assert
element_data
==
{
"
elements
"
:
{},
"
transcriptions
"
:
{
"
word
"
:
1337
},
"
classifications
"
:
{},
"
errors
"
:
[],
}
def
test_add_transcriptions
():
reporter
=
Reporter
(
"
worker
"
)
with
pytest
.
raises
(
AssertionError
):
...
...
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