Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add methods to get and clear notifications on workspace & project levels #17

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aryaxai/common/xai_uris.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# User
GET_WORKSPACES_URI = f"{API_VERSION}/users/workspaces"
CREATE_WORKSPACE_URI = f"{API_VERSION}/users/create_workspace"
GET_NOTIFICATIONS_URI = f"{API_VERSION}/users/notifications"
CLEAR_NOTIFICATIONS_URI = f"{API_VERSION}/users/clear-notifications"

# Workspace
UPDATE_WORKSPACE_URI = f"{API_VERSION}/users/workspace_config_update"
Expand Down
31 changes: 31 additions & 0 deletions aryaxai/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
ALL_DATA_FILE_URI,
AVAILABLE_TAGS_URI,
CASE_INFO_URI,
CLEAR_NOTIFICATIONS_URI,
CREATE_TRIGGER_URI,
DATA_DRFIT_DIAGNOSIS_URI,
DELETE_CASE_URI,
Expand All @@ -48,6 +49,7 @@
GET_LABELS_URI,
GET_MODEL_PERFORMANCE_URI,
GET_MODELS_URI,
GET_NOTIFICATIONS_URI,
GET_PROJECT_CONFIG,
MODEL_PARAMETERS_URI,
MODEL_SUMMARY_URI,
Expand Down Expand Up @@ -1625,6 +1627,35 @@ def delete_cases(
raise Exception(res["details"])

return res["details"]

def get_notifications(self) -> pd.DataFrame:
"""get user project notifications

:return: DataFrame
"""
url = f"{GET_NOTIFICATIONS_URI}?project_name={self.project_name}"

res = self.__api_client.get(url)

if not res["success"]:
raise Exception("Error while getting project notifications.")

return pd.DataFrame(res["details"])

def clear_notifications(self) -> str:
"""clear user project notifications

:raises Exception: _description_
:return: str
"""
url = f"{CLEAR_NOTIFICATIONS_URI}?project_name={self.project_name}"

res = self.__api_client.post(url)

if not res['success']:
raise Exception('Error while clearing project notifications.')

return res['details']

def __print__(self) -> str:
return f"Project(user_project_name='{self.user_project_name}', created_by='{self.created_by}')"
Expand Down
32 changes: 32 additions & 0 deletions aryaxai/core/workspace.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pandas as pd
from pydantic import BaseModel
from typing import List
from aryaxai.client.client import APIClient
Expand All @@ -6,6 +7,8 @@
CREATE_PROJECT_URI,
GET_WORKSPACES_URI,
UPDATE_WORKSPACE_URI,
GET_NOTIFICATIONS_URI,
CLEAR_NOTIFICATIONS_URI
)
from aryaxai.core.project import Project

Expand Down Expand Up @@ -158,6 +161,35 @@ def create_project(self, project_name: str) -> Project:
project = Project(api_client=self.__api_client, **res["details"])

return project

def get_notifications(self) -> pd.DataFrame:
"""get user workspace notifications

:return: DataFrame
"""
url = f"{GET_NOTIFICATIONS_URI}?workspace_name={self.workspace_name}"

res = self.__api_client.get(url)

if not res["success"]:
raise Exception("Error while getting workspace notifications.")

return pd.DataFrame(res["details"])

def clear_notifications(self) -> str:
"""clear user workspace notifications

:raises Exception: _description_
:return: str
"""
url = f"{CLEAR_NOTIFICATIONS_URI}?workspace_name={self.workspace_name}"

res = self.__api_client.post(url)

if not res['success']:
raise Exception('Error while clearing workspace notifications.')

return res['details']

def __print__(self) -> str:
return f"Workspace(user_workspace_name='{self.user_workspace_name}', created_by='{self.created_by}', created_at='{self.created_at}')"
Expand Down
28 changes: 27 additions & 1 deletion aryaxai/core/xai.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import pandas as pd
from pydantic import BaseModel
from aryaxai.client.client import APIClient
from aryaxai.common.environment import Environment

from aryaxai.common.xai_uris import CREATE_WORKSPACE_URI, LOGIN_URI, GET_WORKSPACES_URI
from aryaxai.common.xai_uris import CLEAR_NOTIFICATIONS_URI, CREATE_WORKSPACE_URI, GET_NOTIFICATIONS_URI, LOGIN_URI, GET_WORKSPACES_URI
import getpass
from typing import List

Expand Down Expand Up @@ -97,3 +98,28 @@ def create_workspace(self, workspace_name: str) -> Workspace:
workspace = Workspace(api_client=self.__api_client, **res["workspace_details"])

return workspace

def get_notifications(self) -> pd.DataFrame:
"""get user notifications

:return: DataFrame
"""
res = self.__api_client.get(GET_NOTIFICATIONS_URI)

if not res["success"]:
raise Exception("Error while getting user notifications.")

return pd.DataFrame(res["details"])

def clear_notifications(self) -> str:
"""clear user notifications

:raises Exception: _description_
:return: str
"""
res = self.__api_client.post(CLEAR_NOTIFICATIONS_URI)

if not res['success']:
raise Exception('Error while clearing user notifications.')

return res['details']