Skip to content

Commit 2273377

Browse files
authored
Merge pull request #302 from superannotateai/friday
Friday
2 parents 670bd6b + f1962a8 commit 2273377

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1457
-205
lines changed

docs/source/cli.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ To export project
191191
192192
superannotatecli export-project --project <project_name> --folder <folder_path>
193193
[--include-fuse]
194-
[--disable_extract_zip_contents]
194+
[--disable-extract-zip-contents]
195195
[--annotation-statuses <comma separated list of annotation statuses to export>]
196196
197197
----------

src/superannotate/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,19 @@
312312
local_version = parse(__version__)
313313
if local_version.is_prerelease:
314314
logging.info(constances.PACKAGE_VERSION_INFO_MESSAGE.format(__version__))
315-
req = requests.get('https://pypi.python.org/pypi/superannotate/json')
315+
req = requests.get("https://pypi.python.org/pypi/superannotate/json")
316316
if req.ok:
317-
releases = req.json().get('releases', [])
318-
pip_version = parse('0')
317+
releases = req.json().get("releases", [])
318+
pip_version = parse("0")
319319
for release in releases:
320320
ver = parse(release)
321321
if not ver.is_prerelease or local_version.is_prerelease:
322322
pip_version = max(pip_version, ver)
323323
if pip_version.major > local_version.major:
324-
logging.warning(constances.PACKAGE_VERSION_MAJOR_UPGRADE.format(local_version, pip_version))
324+
logging.warning(
325+
constances.PACKAGE_VERSION_MAJOR_UPGRADE.format(local_version, pip_version)
326+
)
325327
elif pip_version > local_version:
326-
logging.warning(constances.PACKAGE_VERSION_UPGRADE.format(local_version, pip_version)
328+
logging.warning(
329+
constances.PACKAGE_VERSION_UPGRADE.format(local_version, pip_version)
327330
)

src/superannotate/lib/app/analytics/class_analytics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import pandas as pd
55
import plotly.express as px
6+
from lib.app.mixp.decorators import Trackable
67
from superannotate.lib.app.exceptions import AppException
7-
from superannotate.lib.app.mixp.decorators import Trackable
88
from superannotate.lib.core import DEPRICATED_DOCUMENT_VIDEO_MESSAGE
99

1010
from .common import aggregate_annotations_as_df

src/superannotate/lib/app/annotation_helpers.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
from superannotate.lib.app.exceptions import AppException
55

66

7-
def fill_in_missing(annotation_json):
7+
def fill_in_missing(annotation_json, image_name: str = ""):
88
for field in ["instances", "comments", "tags"]:
99
if field not in annotation_json:
1010
annotation_json[field] = []
1111
if "metadata" not in annotation_json:
12-
annotation_json["metadata"] = {}
12+
annotation_json["metadata"] = {"name": image_name}
1313

1414

15-
def _preprocess_annotation_json(annotation_json):
15+
def _preprocess_annotation_json(annotation_json, image_name: str = ""):
1616
path = None
1717
if not isinstance(annotation_json, dict) and annotation_json is not None:
1818
path = annotation_json
1919
annotation_json = json.load(open(annotation_json))
2020
elif annotation_json is None:
2121
annotation_json = {}
2222

23-
fill_in_missing(annotation_json)
23+
fill_in_missing(annotation_json, image_name)
2424

2525
return (annotation_json, path)
2626

@@ -60,7 +60,7 @@ def add_annotation_comment_to_json(
6060
"type": "comment",
6161
"x": comment_coords[0],
6262
"y": comment_coords[1],
63-
"correspondence": [{"text": comment_text, "id": comment_author}],
63+
"correspondence": [{"text": comment_text, "email": comment_author}],
6464
"resolved": resolved,
6565
}
6666
annotation_json["comments"].append(annotation)
@@ -74,6 +74,7 @@ def add_annotation_bbox_to_json(
7474
annotation_class_name,
7575
annotation_class_attributes=None,
7676
error=None,
77+
image_name: str = "",
7778
):
7879
"""Add a bounding box annotation to SuperAnnotate format annotation JSON
7980
@@ -94,7 +95,7 @@ def add_annotation_bbox_to_json(
9495
if len(bbox) != 4:
9596
raise AppException("Bounding boxes should have 4 float elements")
9697

97-
annotation_json, path = _preprocess_annotation_json(annotation_json)
98+
annotation_json, path = _preprocess_annotation_json(annotation_json, image_name)
9899

99100
annotation = {
100101
"type": "bbox",

src/superannotate/lib/app/input_converters/df_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pathlib import Path
33

44
import pandas as pd
5-
from superannotate.lib.app.mixp.decorators import Trackable
5+
from lib.app.mixp.decorators import Trackable
66

77

88
@Trackable

src/superannotate/lib/app/input_converters/dicom_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import numpy as np
44
import pydicom
5+
from lib.app.mixp.decorators import Trackable
56
from PIL import Image
6-
from superannotate.lib.app.mixp.decorators import Trackable
77

88

99
@Trackable

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,6 +2355,7 @@ def attach_image_urls_to_project(
23552355
raise AppException(use_case.response.errors)
23562356

23572357

2358+
@Trackable
23582359
@validate_arguments
23592360
def attach_video_urls_to_project(
23602361
project: Union[NotEmptyStr, dict],
@@ -2476,6 +2477,7 @@ def upload_annotations_from_folder_to_project(
24762477
folder_name=folder_name,
24772478
annotation_paths=annotation_paths, # noqa: E203
24782479
client_s3_bucket=from_s3_bucket,
2480+
folder_path=folder_path,
24792481
)
24802482
if response.errors:
24812483
raise AppException(response.errors)
@@ -3069,7 +3071,12 @@ def add_annotation_bbox_to_image(
30693071
"""
30703072
annotations = get_image_annotations(project, image_name)["annotation_json"]
30713073
annotations = add_annotation_bbox_to_json(
3072-
annotations, bbox, annotation_class_name, annotation_class_attributes, error,
3074+
annotations,
3075+
bbox,
3076+
annotation_class_name,
3077+
annotation_class_attributes,
3078+
error,
3079+
image_name,
30733080
)
30743081
upload_image_annotations(project, image_name, annotations, verbose=False)
30753082

@@ -3638,12 +3645,23 @@ def attach_document_urls_to_project(
36383645
def validate_annotations(
36393646
project_type: ProjectTypes, annotations_json: Union[NotEmptyStr, Path]
36403647
):
3648+
"""
3649+
Validates given annotation JSON.
3650+
:param project_type: project_type (str) – the project type Vector, Pixel, Video or Document
3651+
:type project_type: str
3652+
:param annotations_json: path to annotation JSON
3653+
:type annotations_json: Path-like (str or Path)
3654+
3655+
:return: The success of the validation
3656+
:rtype: bool
3657+
"""
36413658
with open(annotations_json) as file:
36423659
annotation_data = json.loads(file.read())
3643-
response = controller.validate_annotations(project_type, annotation_data)
3660+
response = controller.validate_annotations(project_type, annotation_data, allow_extra=False)
36443661
if response.errors:
36453662
raise AppException(response.errors)
3646-
if response.data:
3663+
is_valid, _ = response.data
3664+
if is_valid:
36473665
return True
36483666
print(response.report)
36493667
return False

src/superannotate/lib/app/mixp/decorators.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .config import TOKEN
99
from .utils import parsers
1010

11+
controller = Controller.get_instance()
1112
mp = Mixpanel(TOKEN)
1213

1314

@@ -25,18 +26,32 @@ def get_default(team_name, user_id, project_name=None):
2526

2627
class Trackable:
2728
TEAM_DATA = None
29+
INITIAL_EVENT = {"event_name": "SDK init", "properties": {}}
30+
INITIAL_LOGGED = False
2831

29-
def __init__(self, function):
32+
def __init__(self, function, initial=False):
3033
self.function = function
3134
self._success = False
35+
self._initial = initial
36+
if initial:
37+
self.track()
3238
functools.update_wrapper(self, function)
3339

40+
@property
41+
def team(self):
42+
return controller.get_team()
43+
3444
def track(self, *args, **kwargs):
3545
try:
36-
data = getattr(parsers, self.function.__name__)(*args, **kwargs)
46+
if self._initial:
47+
data = self.INITIAL_EVENT
48+
Trackable.INITIAL_LOGGED = True
49+
self._success = True
50+
else:
51+
data = getattr(parsers, self.function.__name__)(*args, **kwargs)
3752
event_name = data["event_name"]
3853
properties = data["properties"]
39-
team_data = self.__class__.TEAM_DATA.data
54+
team_data = self.team.data
4055
user_id = team_data.creator_id
4156
team_name = team_data.name
4257
properties["Success"] = self._success
@@ -55,16 +70,20 @@ def track(self, *args, **kwargs):
5570

5671
def __call__(self, *args, **kwargs):
5772
try:
58-
self.__class__.TEAM_DATA = Controller.get_instance().get_team()
59-
ret = self.function(*args, **kwargs)
73+
self.__class__.TEAM_DATA = controller.get_team()
74+
result = self.function(*args, **kwargs)
6075
self._success = True
6176
except Exception as e:
6277
self._success = False
6378
raise e
6479
else:
65-
return ret
80+
return result
6681
finally:
6782
try:
6883
self.track(*args, **kwargs)
6984
except Exception:
7085
pass
86+
87+
88+
if __name__ == "lib.app.mixp.decorators" and not Trackable.INITIAL_LOGGED:
89+
Trackable(None, initial=True)

src/superannotate/lib/app/mixp/utils/parsers.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,3 +1488,37 @@ def unassign_images(*args, **kwargs):
14881488
"event_name": "unassign_images",
14891489
"properties": {"Assign Folder": is_root, "Image Count": len(image_names)},
14901490
}
1491+
1492+
1493+
def attach_video_urls_to_project(*args, **kwargs):
1494+
project = kwargs.get("project", None)
1495+
if not project:
1496+
project = args[0]
1497+
return {
1498+
"event_name": "attach_video_urls_to_project",
1499+
"properties": {
1500+
"project_name": get_project_name(project),
1501+
"Annotation Status": bool(
1502+
args[2:3] or kwargs.get("annotation_status", None)
1503+
),
1504+
},
1505+
}
1506+
1507+
1508+
def attach_document_urls_to_project(*args, **kwargs):
1509+
project = kwargs.get("project", None)
1510+
if not project:
1511+
project = args[0]
1512+
return {
1513+
"event_name": "attach_document_urls_to_project",
1514+
"properties": {
1515+
"project_name": get_project_name(project),
1516+
"Annotation Status": bool(
1517+
args[2:3] or kwargs.get("annotation_status", None)
1518+
),
1519+
},
1520+
}
1521+
1522+
1523+
def delete_annotations(*args, **kwargs):
1524+
return {"event_name": "delete_annotations", "properties": {}}

src/superannotate/lib/core/__init__.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,21 @@
102102
)
103103
MOVE_PROJECT_LIMIT_ERROR_MESSAGE = "The number of items you want to move exceeds the limit of 500 000 items per project."
104104

105-
PACKAGE_VERSION_INFO_MESSAGE = "Development version {} of SuperAnnotate SDK is being used."
105+
PACKAGE_VERSION_INFO_MESSAGE = (
106+
"Development version {} of SuperAnnotate SDK is being used."
107+
)
106108

107-
PACKAGE_VERSION_MAJOR_UPGRADE = "There is a major upgrade of SuperAnnotate Python SDK available on PyPI. " \
108-
"We recommend upgrading. Run 'pip install --upgrade superannotate' to " \
109-
"upgrade from your version {} to {}."
109+
PACKAGE_VERSION_MAJOR_UPGRADE = (
110+
"There is a major upgrade of SuperAnnotate Python SDK available on PyPI. "
111+
"We recommend upgrading. Run 'pip install --upgrade superannotate' to "
112+
"upgrade from your version {} to {}."
113+
)
110114

111-
PACKAGE_VERSION_UPGRADE = "There is a newer version of SuperAnnotate Python SDK available on PyPI." \
112-
" Run 'pip install --upgrade superannotate' to" \
113-
" upgrade from your version {} to {}"
115+
PACKAGE_VERSION_UPGRADE = (
116+
"There is a newer version of SuperAnnotate Python SDK available on PyPI."
117+
" Run 'pip install --upgrade superannotate' to"
118+
" upgrade from your version {} to {}"
119+
)
114120
__alL__ = (
115121
ProjectType,
116122
UserRole,

0 commit comments

Comments
 (0)