Skip to content

Commit e2f29f3

Browse files
authored
Merge pull request #292 from superannotateai/456
import mixp
2 parents 70c5a64 + 78582b4 commit e2f29f3

File tree

9 files changed

+52
-23
lines changed

9 files changed

+52
-23
lines changed

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/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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,7 @@ def attach_image_urls_to_project(
23542354
return uploaded, failed_images, duplications
23552355
raise AppException(use_case.response.errors)
23562356

2357+
23572358
@Trackable
23582359
@validate_arguments
23592360
def attach_video_urls_to_project(

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,6 @@ def attach_document_urls_to_project(*args, **kwargs):
15191519
},
15201520
}
15211521

1522+
15221523
def delete_annotations(*args, **kwargs):
15231524
return {"event_name": "delete_annotations", "properties": {}}
1524-

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,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def set_annotation_json(self):
356356
constances.PIXEL_ANNOTATION_POSTFIX,
357357
constances.ANNOTATION_MASK_POSTFIX,
358358
),
359-
"rb"
359+
"rb",
360360
)
361361

362362
def _is_valid_json(self, json_data: dict):

0 commit comments

Comments
 (0)