From b47e44f27ff487497b2da628f925f0e79a91e987 Mon Sep 17 00:00:00 2001 From: Kevin Date: Mon, 16 Dec 2024 10:48:17 +0100 Subject: [PATCH 1/3] fixes --- hasty/attribute.py | 10 +++++++--- hasty/project.py | 5 +++-- tests/test_attribute.py | 12 ++++++------ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/hasty/attribute.py b/hasty/attribute.py index 13166dc..ff02430 100644 --- a/hasty/attribute.py +++ b/hasty/attribute.py @@ -90,17 +90,21 @@ def _set_prop_values(self, data): self._values = data["values"] @staticmethod - def validate_type(attribute_type): + def validate_types(attribute_type, subject_type): if attribute_type not in ['SELECTION', 'MULTIPLE-SELECTION', 'TEXT', 'INT', 'FLOAT', 'BOOL']: raise ValidationException('Attribute type should be one of the following ' '[SELECTION, MULTIPLE-SELECTION, TEXT, INT, FLOAT, BOOL]') + if subject_type not in ["IMAGE", "VIDEO", "LABEL", "SEGMENT"]: + raise ValidationException("Subject type should be one of the following " + "[IMAGE, VIDEO, LABEL, SEGMENT]") @staticmethod - def create(requester, project_id: str, name: str, attribute_type: str, description: Optional[str] = None, + def create(requester, project_id: str, name: str, attribute_type: str, subject_type: str, description: Optional[str] = None, norder: Optional[float] = None, values: List[str] = None): - Attribute.validate_type(attribute_type) + Attribute.validate_types(attribute_type, subject_type) json_data = {"name": name, "type": attribute_type, + "subject_type": subject_type, "description": description, "values": [{"value": v} for v in values], "norder": norder} diff --git a/hasty/project.py b/hasty/project.py index bf5b7dd..2e347bd 100644 --- a/hasty/project.py +++ b/hasty/project.py @@ -283,7 +283,7 @@ def get_attributes(self): Attribute.endpoint.format(project_id=self._id), obj_params={"project_id": self.id}) - def create_attribute(self, name: str, attribute_type: str, description: Optional[str] = None, + def create_attribute(self, name: str, attribute_type: str, subject_type: str, description: Optional[str] = None, norder: Optional[float] = None, values: List[str] = None): """ Create attribute, returns :py:class:`~hasty.Attribute` object. @@ -291,11 +291,12 @@ def create_attribute(self, name: str, attribute_type: str, description: Optional Args: name (str): Attribute name attribute_type (str): Attribute type ['SELECTION', 'MULTIPLE-SELECTION', 'TEXT', 'INT', 'FLOAT', 'BOOL'] + subject_type (str): Subject type ['IMAGE', 'VIDEO', 'LABEL', 'SEGMENT'] description (str, optional): Attrbute description norder (float, optional): Order in the Hasty tool values (list of str): List of values for SELECTION and MULTIPLE-SELECTION attribute type """ - return Attribute.create(self._requester, self._id, name, attribute_type, description, norder, values) + return Attribute.create(self._requester, self._id, name, attribute_type, subject_type, description, norder, values) def get_attribute_classes(self): """ diff --git a/tests/test_attribute.py b/tests/test_attribute.py index be8d498..bd492e5 100644 --- a/tests/test_attribute.py +++ b/tests/test_attribute.py @@ -25,11 +25,11 @@ def test_attributes(self): attributes = self.project.get_attributes() self.assertEqual(0, len(attributes), 'Should be no attributes for a new project') # Create attribute - attr = self.project.create_attribute("attr1", "SELECTION", "Some desc", 2, ["v1", "v2", "v3"]) + attr = self.project.create_attribute("attr1", "SELECTION", "IMAGE", "Some desc", 2, ["v1", "v2", "v3"]) self.validate_attribute(attr, "attr1", "SELECTION", "Some desc", 2, ["v1", "v2", "v3"]) # Update attribute attr.edit("attr2", "SELECTION", "Desc2", 3, ["v1", "v2"]) - self.validate_attribute(attr, "attr2", "SELECTION", "Desc2", 3, ["v1", "v2"]) + self.validate_attribute(attr, "attr2", "SELECTION", "IMAGE", "Desc2", 3, ["v1", "v2"]) # Check get attributes attributes = self.project.get_attributes() self.assertEqual(1, len(attributes)) @@ -40,8 +40,8 @@ def test_attributes(self): self.assertEqual(0, len(attributes), 'Should not be any attributes') def test_attribute_class(self): - attr1 = self.project.create_attribute("attr1", "SELECTION", "Some desc", 2, ["v1", "v2", "v3"]) - attr2 = self.project.create_attribute("attr2", "SELECTION", "Some desc", 2, ["v1", "v2", "v3"]) + attr1 = self.project.create_attribute("attr1", "SELECTION", "IMAGE", "Some desc", 2, ["v1", "v2", "v3"]) + attr2 = self.project.create_attribute("attr2", "SELECTION", "IMAGE", "Some desc", 2, ["v1", "v2", "v3"]) lc1 = self.project.create_label_class("class1", "#ff00aa99", "object", 2) lc2 = self.project.create_label_class("class2", "#ff00aa99", "object", 2) attr_cls = self.project.get_attribute_classes() @@ -62,8 +62,8 @@ def test_attribute_class(self): self.assertEqual(0, len(attr_cls)) def test_label_attributes(self): - attr1 = self.project.create_attribute("attr1", "SELECTION", "Some desc", 2, ["v1", "v2", "v3"]) - attr2 = self.project.create_attribute("attr2", "SELECTION", "Some desc", 2, ["v1", "v2", "v3"]) + attr1 = self.project.create_attribute("attr1", "SELECTION", "IMAGE", "Some desc", 2, ["v1", "v2", "v3"]) + attr2 = self.project.create_attribute("attr2", "SELECTION", "IMAGE", "Some desc", 2, ["v1", "v2", "v3"]) lc1 = self.project.create_label_class("class1", "#ff00aa99", "object", 2) self.project.set_attribute_classes([{"attribute_id": attr1.id, "class_id": lc1.id}, {"attribute_id": attr2.id, "class_id": lc1.id}]) From 3295d3e617cf370a1b3f47632386fa657738d090 Mon Sep 17 00:00:00 2001 From: Kevin Date: Mon, 16 Dec 2024 18:12:53 +0100 Subject: [PATCH 2/3] fix --- hasty/attribute.py | 4 +++- tests/test_attribute.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hasty/attribute.py b/hasty/attribute.py index ff02430..07b8a95 100644 --- a/hasty/attribute.py +++ b/hasty/attribute.py @@ -112,7 +112,7 @@ def create(requester, project_id: str, name: str, attribute_type: str, subject_t res = requester.post(Attribute.endpoint.format(project_id=project_id), json_data=json_data) return Attribute(requester, res, {"project_id": project_id}) - def edit(self, name: str, attribute_type: str, description: Optional[str] = None, + def edit(self, name: str, attribute_type: str, subject_type: str, description: Optional[str] = None, norder: Optional[float] = None, values: List[str] = None): """ Edit attribute properties @@ -121,12 +121,14 @@ def edit(self, name: str, attribute_type: str, description: Optional[str] = None Args: name (str): Attribute name attribute_type (str): Attribute type ['SELECTION', 'MULTIPLE-SELECTION', 'TEXT', 'INT', 'FLOAT', 'BOOL'] + subject_type (str): Subject type ['IMAGE', 'VIDEO', 'LABEL', 'SEGMENT'] description (str, optional): Attrbute description norder (float, optional): Order in the Hasty tool values (list of str): List of values for SELECTION and MULTIPLE-SELECTION attribute type """ json_data = {"name": name, "type": attribute_type, + "subject_type": subject_type, "description": description, "norder": norder, "values": [{"value": v} for v in values]} diff --git a/tests/test_attribute.py b/tests/test_attribute.py index bd492e5..d12a651 100644 --- a/tests/test_attribute.py +++ b/tests/test_attribute.py @@ -28,7 +28,7 @@ def test_attributes(self): attr = self.project.create_attribute("attr1", "SELECTION", "IMAGE", "Some desc", 2, ["v1", "v2", "v3"]) self.validate_attribute(attr, "attr1", "SELECTION", "Some desc", 2, ["v1", "v2", "v3"]) # Update attribute - attr.edit("attr2", "SELECTION", "Desc2", 3, ["v1", "v2"]) + attr.edit("attr2", "SELECTION", "IMAGE", "Desc2", 3, ["v1", "v2"]) self.validate_attribute(attr, "attr2", "SELECTION", "IMAGE", "Desc2", 3, ["v1", "v2"]) # Check get attributes attributes = self.project.get_attributes() From 3d8caf9714a8c2cbe69b50a0ccee01505d50debf Mon Sep 17 00:00:00 2001 From: Kevin Date: Mon, 16 Dec 2024 18:21:38 +0100 Subject: [PATCH 3/3] fix --- tests/test_attribute.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_attribute.py b/tests/test_attribute.py index d12a651..03540ff 100644 --- a/tests/test_attribute.py +++ b/tests/test_attribute.py @@ -29,7 +29,7 @@ def test_attributes(self): self.validate_attribute(attr, "attr1", "SELECTION", "Some desc", 2, ["v1", "v2", "v3"]) # Update attribute attr.edit("attr2", "SELECTION", "IMAGE", "Desc2", 3, ["v1", "v2"]) - self.validate_attribute(attr, "attr2", "SELECTION", "IMAGE", "Desc2", 3, ["v1", "v2"]) + self.validate_attribute(attr, "attr2", "SELECTION", "Desc2", 3, ["v1", "v2"]) # Check get attributes attributes = self.project.get_attributes() self.assertEqual(1, len(attributes))