Skip to content

Commit f3c3686

Browse files
committed
Mixpanel fix
1 parent a36b443 commit f3c3686

File tree

7 files changed

+22
-1012
lines changed

7 files changed

+22
-1012
lines changed

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

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,16 @@ def __init__(self, token: str = None, config_path: str = None):
3737
_toke, _host, _ssl_verify = self._retrieve_configs(
3838
constants.CONFIG_PATH
3939
)
40-
self._token, self._host = _host, _token
40+
self._token, self._host = _token, _host
4141
self.controller = Controller(_token, _host, _ssl_verify, version)
42-
43-
def __new__(cls, *args, **kwargs):
44-
obj = super().__new__(cls)
45-
cls.REGISTRY.append(obj)
46-
return obj
42+
BaseInterfaceFacade.REGISTRY.append(self)
4743

4844
@staticmethod
4945
def _retrieve_configs(path) -> Tuple[str, str, str]:
5046
config_path = os.path.expanduser(str(path))
5147
if not Path(config_path).is_file() or not os.access(config_path, os.R_OK):
5248
raise AppException(
5349
f"SuperAnnotate config file {str(config_path)} not found."
54-
f" Please provide correct config file location to sa.init(<path>) or use "
55-
f"CLI's superannotate init to generate default location config file."
5650
)
5751
config_repo = ConfigRepository(config_path)
5852
return (
@@ -72,11 +66,12 @@ def token(self):
7266

7367
class Tracker:
7468
def get_mp_instance(self) -> Mixpanel:
75-
if self.client:
76-
if self.client.host == constants.BACKEND_URL:
77-
return Mixpanel("ca95ed96f80e8ec3be791e2d3097cf51")
78-
else:
79-
return Mixpanel("e741d4863e7e05b1a45833d01865ef0d")
69+
client = self.get_client()
70+
mp_token = "ca95ed96f80e8ec3be791e2d3097cf51"
71+
if client:
72+
if client.host != constants.BACKEND_URL:
73+
mp_token = "e741d4863e7e05b1a45833d01865ef0d"
74+
return Mixpanel(mp_token)
8075

8176
@staticmethod
8277
def get_default_payload(team_name, user_id):
@@ -92,16 +87,16 @@ def __init__(self, function):
9287
self._client = None
9388
functools.update_wrapper(self, function)
9489

95-
@property
96-
def client(self):
90+
def get_client(self):
9791
if not self._client:
9892
if BaseInterfaceFacade.REGISTRY:
9993
self._client = BaseInterfaceFacade.REGISTRY[-1]
10094
else:
10195
from lib.app.interface.sdk_interface import SAClient
10296

10397
self._client = SAClient()
104-
return self._client
98+
elif hasattr(self._client, "controller"):
99+
return self._client
105100

106101
@staticmethod
107102
def extract_arguments(function, *args, **kwargs) -> dict:
@@ -138,12 +133,14 @@ def _track(self, user_id: str, event_name: str, data: dict):
138133
self.get_mp_instance().track(user_id, event_name, data)
139134

140135
def _track_method(self, args, kwargs, success: bool):
136+
client = self.get_client()
137+
if not client:
138+
return
141139
function_name = self.function.__name__ if self.function else ""
142140
arguments = self.extract_arguments(self.function, *args, **kwargs)
143141
event_name, properties = self.default_parser(function_name, arguments)
144-
145-
user_id = self.client.controller.team_data.creator_id
146-
team_name = self.client.controller.team_data.name
142+
user_id = client.controller.team_data.creator_id
143+
team_name = client.controller.team_data.name
147144

148145
properties["Success"] = success
149146
default = self.get_default_payload(team_name=team_name, user_id=user_id)
@@ -177,7 +174,9 @@ def __call__(self, *args, **kwargs):
177174
class TrackableMeta(type):
178175
def __new__(mcs, name, bases, attrs):
179176
for attr_name, attr_value in attrs.items():
180-
if isinstance(attr_value, FunctionType):
177+
if isinstance(
178+
attr_value, FunctionType
179+
) and not attr_value.__name__.startswith("_"):
181180
attrs[attr_name] = Tracker(validate_arguments(attr_value))
182181
tmp = super().__new__(mcs, name, bases, attrs)
183182
return tmp

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

Whitespace-only changes.

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

Whitespace-only changes.

0 commit comments

Comments
 (0)