Skip to content

Commit ea8f0a7

Browse files
committed
Merge remote-tracking branch 'origin/master' into folder_structure
2 parents 86f4636 + b6c9197 commit ea8f0a7

File tree

4 files changed

+137
-39
lines changed

4 files changed

+137
-39
lines changed

superannotate/db/images.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,18 @@ def get_image_metadata(project, image_names):
159159
json_req=json_req,
160160
)
161161

162-
metadata = response.json()
163-
if len(metadata) == 0:
162+
metadata_raw = response.json()
163+
metadata_without_deleted = []
164+
for im_metadata in metadata_raw:
165+
if 'delete' in im_metadata and im_metadata['delete'] == 1:
166+
continue
167+
metadata_without_deleted.append(im_metadata)
168+
if len(metadata_without_deleted) == 0:
164169
raise SABaseException(
165170
0,
166171
f"None of the images in {image_names} exist in the provided project"
167172
)
168-
for item in metadata:
173+
for item in metadata_without_deleted:
169174
item['annotation_status'] = common.annotation_status_int_to_str(
170175
item['annotation_status']
171176
)
@@ -178,9 +183,9 @@ def get_image_metadata(project, image_names):
178183
item['segmentation_status']
179184
)
180185

181-
if len(metadata) == 1:
182-
return metadata[0]
183-
return metadata
186+
if len(metadata_without_deleted) == 1:
187+
return metadata_without_deleted[0]
188+
return metadata_without_deleted
184189

185190

186191
def set_image_annotation_status(project, image_name, annotation_status):

superannotate/db/projects.py

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,15 +1890,15 @@ def get_project_workflow(project):
18901890
def set_project_workflow(project, new_workflow):
18911891
"""Sets project's workflow.
18921892
1893-
new_workflow example: [{ "step" : <step_num>, "className" : <annotation_class>, "tool" : <tool_num>, ...},...]
1893+
new_workflow example: [{ "step" : <step_num>, "className" : <annotation_class>, "tool" : <tool_num>,
1894+
"attribute":[{"attribute" : {"name" : <attribute_value>, "attribute_group" : {"name": <attribute_group>}}},
1895+
...]
1896+
},...]
18941897
18951898
:param project: project name or metadata
18961899
:type project: str or dict
18971900
:param project: new workflow list of dicts
18981901
:type project: list of dicts
1899-
1900-
:return: updated part of project's workflow
1901-
:rtype: list of dicts
19021902
"""
19031903
if not isinstance(project, dict):
19041904
project = get_project_metadata_bare(project)
@@ -1917,33 +1917,74 @@ def set_project_workflow(project, new_workflow):
19171917
for step in new_list:
19181918
if "id" in step:
19191919
del step["id"]
1920-
if "className" in step:
1921-
found = False
1922-
for an_class in annotation_classes:
1923-
if an_class["name"] == step["className"]:
1924-
step["class_id"] = an_class["id"]
1925-
del step["className"]
1926-
found = True
1920+
if "className" not in step:
1921+
continue
1922+
for an_class in annotation_classes:
1923+
if an_class["name"] == step["className"]:
1924+
step["class_id"] = an_class["id"]
1925+
break
1926+
else:
1927+
raise SABaseException(
1928+
0, "Annotation class not found in set_project_workflow."
1929+
)
1930+
json_req = {"steps": [step]}
1931+
response = _api.send_request(
1932+
req_type='POST',
1933+
path=f'/project/{project_id}/workflow',
1934+
params=params,
1935+
json_req=json_req
1936+
)
1937+
if not response.ok:
1938+
raise SABaseException(
1939+
response.status_code,
1940+
"Couldn't set project workflow " + response.text
1941+
)
1942+
if "attribute" not in step:
1943+
continue
1944+
current_steps = get_project_workflow(project)
1945+
for step_in_response in current_steps:
1946+
if step_in_response["step"] == step["step"]:
1947+
workflow_id = step_in_response["id"]
1948+
break
1949+
else:
1950+
raise SABaseException(0, "Couldn't find step in workflow")
1951+
request_data = []
1952+
for attribute in step["attribute"]:
1953+
for att_class in an_class["attribute_groups"]:
1954+
if att_class["name"] == attribute["attribute"]["attribute_group"
1955+
]["name"]:
1956+
break
1957+
else:
1958+
raise SABaseException(
1959+
0, "Attribute group not found in set_project_workflow."
1960+
)
1961+
for att_value in att_class["attributes"]:
1962+
if att_value["name"] == attribute["attribute"]["name"]:
1963+
attribute_id = att_value["id"]
19271964
break
1928-
if not found:
1965+
else:
19291966
raise SABaseException(
1930-
0, "Annotation class not found in set_project_workflow."
1967+
0, "Attribute value not found in set_project_workflow."
19311968
)
19321969

1933-
json_req = {"steps": new_list}
1934-
response = _api.send_request(
1935-
req_type='POST',
1936-
path=f'/project/{project_id}/workflow',
1937-
params=params,
1938-
json_req=json_req
1939-
)
1940-
if not response.ok:
1941-
raise SABaseException(
1942-
response.status_code,
1943-
"Couldn't set project workflow " + response.text
1970+
request_data.append(
1971+
{
1972+
"workflow_id": workflow_id,
1973+
"attribute_id": attribute_id
1974+
}
1975+
)
1976+
1977+
response = _api.send_request(
1978+
req_type='POST',
1979+
path=f'/project/{project_id}/workflow_attribute',
1980+
params=params,
1981+
json_req={"data": request_data}
19441982
)
1945-
res = response.json()
1946-
return res
1983+
if not response.ok:
1984+
raise SABaseException(
1985+
response.status_code,
1986+
"Couldn't set project workflow " + response.text
1987+
)
19471988

19481989

19491990
def get_project_settings(project):

superannotate/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.2.2"
1+
__version__ = "3.2.6"

tests/test_clone_project.py

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,27 @@ def test_create_like_project(tmpdir):
1515
sa.delete_project(project)
1616

1717
sa.create_project(PROJECT_NAME, "tt", "Vector")
18-
sa.create_annotation_class(PROJECT_NAME, "rrr", "#FFAAFF")
18+
sa.create_annotation_class(
19+
PROJECT_NAME, "rrr", "#FFAAFF", [
20+
{
21+
"name": "tall",
22+
"is_multiselect": 0,
23+
"attributes": [{
24+
"name": "yes"
25+
}, {
26+
"name": "no"
27+
}]
28+
}, {
29+
"name": "age",
30+
"is_multiselect": 0,
31+
"attributes": [{
32+
"name": "young"
33+
}, {
34+
"name": "old"
35+
}]
36+
}
37+
]
38+
)
1939

2040
old_settings = sa.get_project_settings(PROJECT_NAME)
2141
for setting in old_settings:
@@ -29,11 +49,36 @@ def test_create_like_project(tmpdir):
2949
}]
3050
)
3151
sa.set_project_workflow(
32-
PROJECT_NAME, [{
33-
"step": 1,
34-
"className": "rrr",
35-
"tool": 3
36-
}]
52+
PROJECT_NAME, [
53+
{
54+
"step":
55+
1,
56+
"className":
57+
"rrr",
58+
"tool":
59+
3,
60+
"attribute":
61+
[
62+
{
63+
"attribute":
64+
{
65+
"name": "young",
66+
"attribute_group": {
67+
"name": "age"
68+
}
69+
}
70+
}, {
71+
"attribute":
72+
{
73+
"name": "yes",
74+
"attribute_group": {
75+
"name": "tall"
76+
}
77+
}
78+
}
79+
]
80+
}
81+
]
3782
)
3883
users = sa.search_team_contributors()
3984
sa.share_project(PROJECT_NAME, users[1], "QA")
@@ -65,6 +110,13 @@ def test_create_like_project(tmpdir):
65110
assert len(new_workflow) == 1
66111
assert new_workflow[0]["className"] == "rrr"
67112
assert new_workflow[0]["tool"] == 3
113+
assert len(new_workflow[0]["attribute"]) == 2
114+
assert new_workflow[0]["attribute"][0]["attribute"]["name"] == "young"
115+
assert new_workflow[0]["attribute"][0]["attribute"]["attribute_group"][
116+
"name"] == "age"
117+
assert new_workflow[0]["attribute"][1]["attribute"]["name"] == "yes"
118+
assert new_workflow[0]["attribute"][1]["attribute"]["attribute_group"][
119+
"name"] == "tall"
68120

69121
new_project = sa.get_project_metadata(
70122
new_project["name"], include_contributors=True

0 commit comments

Comments
 (0)