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 for file #14

Merged
merged 1 commit into from
Oct 31, 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
1 change: 1 addition & 0 deletions aryaxai/common/xai_uris.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
UPLOAD_DATA_FILE_URI = f"{API_VERSION}/project/uploadfile_with_info"
UPLOAD_DATA_FILE_INFO_URI = f"{API_VERSION}/project/get_Uploaded_file_info"
DELETE_DATA_FILE_URI = f"{API_VERSION}/project/delete_data"
ALL_DATA_FILE_URI = f"{API_VERSION}/project/get_all_uploaded_files"
UPLOAD_DATA_URI = f"{API_VERSION}/project/upload_data"
UPLOAD_DATA_WITH_CHECK_URI = f"{API_VERSION}/project/upload_data_with_check"
GET_DATA_SUMMARY_URI = f"{API_VERSION}/project/data_summary"
Expand Down
87 changes: 84 additions & 3 deletions aryaxai/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import pandas as pd

from aryaxai.common.xai_uris import (
ALL_DATA_FILE_URI,
AVAILABLE_TAGS_URI,
CASE_INFO_URI,
CREATE_TRIGGER_URI,
Expand Down Expand Up @@ -212,17 +213,97 @@ def get_labels(self, feature_name: str) -> List[str]:

return res["labels"]

def delete_file(self, path: str) -> str:
def files(self) -> pd.DataFrame:
"""Lists all files uploaded by user

:return: user uploaded files dataframe
"""
files = self.__api_client.get(
f"{ALL_DATA_FILE_URI}?project_name={self.project_name}"
)

if not files.get("details"):
raise Exception("Please upload files first")

files_df = (
pd.DataFrame(files["details"])
.drop(["metadata", "project_name", "version"], axis=1)
.rename(columns={"filepath": "file_name"})
)

files_df["file_name"] = files_df["file_name"].apply(
lambda file_path: file_path.split("/")[-1]
)

return files_df

def file_summary(self, file_name: str) -> pd.DataFrame:
"""File Summary

:param file_name: user uploaded file name
:return: file summary dataframe
"""
files = self.__api_client.get(
f"{ALL_DATA_FILE_URI}?project_name={self.project_name}"
)

if not files.get("details"):
raise Exception("Please upload files first")

file_data = next(
filter(
lambda file: file["filepath"].split("/")[-1] == file_name,
files["details"],
),
None,
)

if not file_data:
raise Exception("File Not Found, please pass valid file name")

file_metadata = {
"file_size_mb": file_data["metadata"]["file_size_mb"],
"columns": file_data["metadata"]["columns"],
"rows": file_data["metadata"]["rows"],
}

print(file_metadata)

file_summary_df = pd.DataFrame(file_data["metadata"]["details"])

return file_summary_df

def delete_file(self, file_name: str) -> str:
"""deletes file for the project

:param path: uploaded file path
:param file_name: uploaded file name
:return: response
"""
files = self.__api_client.get(
f"{ALL_DATA_FILE_URI}?project_name={self.project_name}"
)

if not files.get("details"):
raise Exception("Please upload files first")

file_data = next(
filter(
lambda file: file["filepath"] == file_name
or file["filepath"].split("/")[-1] == file_name,
files["details"],
),
None,
)

if not file_data:
raise Exception("File Not Found, please pass valid file name")

payload = {
"project_name": self.project_name,
"workspace_name": self.workspace_name,
"path": path,
"path": file_data["filepath"],
}

res = self.__api_client.post(DELETE_DATA_FILE_URI, payload)
return res.get("details")

Expand Down