Skip to content

Commit cb9fe2b

Browse files
Narek MkhitaryanNarek Mkhitaryan
authored andcommitted
fix 1372_issue
1 parent 0a94e2e commit cb9fe2b

File tree

3 files changed

+78
-8
lines changed

3 files changed

+78
-8
lines changed

src/superannotate/lib/core/__init__.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,36 @@ def setup_logging(level=DEFAULT_LOGGING_LEVEL, file_path=LOG_FILE_LOCATION):
153153

154154
INVALID_JSON_MESSAGE = "Invalid json"
155155

156+
PROJECT_SETTINGS_VALID_ATTRIBUTES = [
157+
"Brightness",
158+
"Fill",
159+
"Contrast",
160+
"ShowLabels",
161+
"ShowComments",
162+
"Image",
163+
"Lines",
164+
"AnnotatorFinish",
165+
"PointSize",
166+
"FontSize",
167+
"WorkflowEnable",
168+
"ClassChange",
169+
"ShowEntropy",
170+
"UploadImages",
171+
"DeleteImages",
172+
"Download",
173+
"RunPredictions",
174+
"RunSegmentations",
175+
"ImageQuality",
176+
"ImageAutoAssignCount",
177+
"FrameMode",
178+
"FrameRate",
179+
"JumpBackward",
180+
"JumpForward",
181+
"UploadFileType",
182+
"Tokenization",
183+
"ImageAutoAssignEnable",
184+
]
185+
156186
__alL__ = (
157187
FolderStatus,
158188
ProjectStatus,

src/superannotate/lib/core/usecases/projects.py

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def __init__(
177177

178178
def validate_settings(self):
179179
for setting in self._project.settings[:]:
180-
if setting.attribute == "WorkflowType":
180+
if setting.attribute not in constances.PROJECT_SETTINGS_VALID_ATTRIBUTES:
181181
self._project.settings.remove(setting)
182182
if setting.attribute == "ImageQuality" and isinstance(setting.value, str):
183183
setting.value = constances.ImageQuality.get_value(setting.value)
@@ -335,6 +335,39 @@ def __init__(
335335
self._project = project
336336
self._service_provider = service_provider
337337

338+
def validate_settings(self):
339+
for setting in self._project.settings[:]:
340+
if setting.attribute not in constances.PROJECT_SETTINGS_VALID_ATTRIBUTES:
341+
self._project.settings.remove(setting)
342+
if setting.attribute == "ImageQuality" and isinstance(setting.value, str):
343+
setting.value = constances.ImageQuality.get_value(setting.value)
344+
elif setting.attribute == "FrameRate":
345+
if not self._project.type == constances.ProjectType.VIDEO.value:
346+
raise AppValidationException(
347+
"FrameRate is available only for Video projects"
348+
)
349+
try:
350+
setting.value = float(setting.value)
351+
if (
352+
not (0.0001 < setting.value < 120)
353+
or decimal.Decimal(str(setting.value)).as_tuple().exponent < -3
354+
):
355+
raise AppValidationException(
356+
"The FrameRate value range is between 0.001 - 120"
357+
)
358+
frame_mode = next(
359+
filter(
360+
lambda x: x.attribute == "FrameMode", self._project.settings
361+
),
362+
None,
363+
)
364+
if not frame_mode:
365+
self._project.settings.append(
366+
SettingEntity(attribute="FrameMode", value=1)
367+
)
368+
except ValueError:
369+
raise AppValidationException("The FrameRate value should be float")
370+
338371
def validate_project_name(self):
339372
if self._project.name:
340373
if (
@@ -488,13 +521,17 @@ def execute(self):
488521

489522
new_settings_to_update = []
490523
for new_setting in self._to_update:
491-
new_settings_to_update.append(
492-
SettingEntity(
493-
id=attr_id_mapping[new_setting["attribute"]],
494-
attribute=new_setting["attribute"],
495-
value=new_setting["value"],
524+
if (
525+
new_setting["attribute"]
526+
in constances.PROJECT_SETTINGS_VALID_ATTRIBUTES
527+
):
528+
new_settings_to_update.append(
529+
SettingEntity(
530+
id=attr_id_mapping[new_setting["attribute"]],
531+
attribute=new_setting["attribute"],
532+
value=new_setting["value"],
533+
)
496534
)
497-
)
498535

499536
response = self._service_provider.projects.set_settings(
500537
project=self._project,

tests/integration/projects/test_basic_project.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ def test_basic_project(self):
176176
for json_in_folder in self.folder_path.glob("*.json"):
177177
found = False
178178
for json_in_project in Path(temp_dir).glob("*.json"):
179-
if json_in_folder.name == json_in_project.name:
179+
if (
180+
json_in_folder.name.replace("___pixel", "")
181+
== json_in_project.name
182+
):
180183
found = True
181184
break
182185
assert found, json_in_folder

0 commit comments

Comments
 (0)