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 sort_keys options when creating and loading PIVOT table #129

Merged
merged 1 commit into from
Dec 17, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(
self.data_table_vos = self._get_data_table_from_options(operator, options)
self.data_keys = []
self.label_keys = []
self.sort_keys = []
self.total_series = None

def get_data_and_labels_info(self) -> Tuple[dict, dict]:
Expand Down Expand Up @@ -421,6 +422,7 @@ def pivot_data_table(
function = self.options.get("function", "sum")

raw_df = self._get_data_table(origin_vo, granularity, start, end, vars)

self._check_columns(raw_df, labels, column, data)
fill_value = self._set_fill_value_from_df(raw_df, data)

Expand All @@ -429,6 +431,8 @@ def pivot_data_table(
)

pivot_table = self._sort_and_filter_pivot_table(pivot_table)
self.sort_keys = list(pivot_table.columns)

self.df = pivot_table

def add_labels_data_table(
Expand Down
2 changes: 2 additions & 0 deletions src/spaceone/dashboard/model/private_data_table/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class PrivateDataTable(MongoModel):
tags = DictField(default=None)
labels_info = DictField(default=None)
data_info = DictField(default=None)
sort_keys = ListField(default=None)
dashboard_id = StringField(max_length=40)
widget_id = StringField(max_length=40)
resource_group = StringField(
Expand All @@ -36,6 +37,7 @@ class PrivateDataTable(MongoModel):
"tags",
"labels_info",
"data_info",
"sort_keys",
],
"minimal_fields": [
"data_table_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class PrivateDataTableResponse(BaseModel):
tags: Union[dict, None] = None
labels_info: Union[dict, None] = None
data_info: Union[dict, None] = None
sort_keys: Union[List[str], None] = None
error_message: Union[str, None] = None
dashboard_id: Union[str, None] = None
widget_id: Union[str, None] = None
Expand Down
2 changes: 2 additions & 0 deletions src/spaceone/dashboard/model/public_data_table/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class PublicDataTable(MongoModel):
tags = DictField(default=None)
labels_info = DictField(default=None)
data_info = DictField(default=None)
sort_keys = ListField(default=None)
dashboard_id = StringField(max_length=40)
widget_id = StringField(max_length=40)
resource_group = StringField(
Expand All @@ -37,6 +38,7 @@ class PublicDataTable(MongoModel):
"tags",
"labels_info",
"data_info",
"sort_keys",
"project_id",
"workspace_id",
],
Expand Down
1 change: 1 addition & 0 deletions src/spaceone/dashboard/model/public_data_table/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class PublicDataTableResponse(BaseModel):
tags: Union[dict, None] = None
labels_info: Union[dict, None] = None
data_info: Union[dict, None] = None
sort_keys: Union[List[str], None] = None
error_message: Union[str, None] = None
dashboard_id: Union[str, None] = None
widget_id: Union[str, None] = None
Expand Down
6 changes: 6 additions & 0 deletions src/spaceone/dashboard/service/private_data_table_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ def transform_data_table(self, params_dict: dict) -> dict:
params_dict["state"] = dt_mgr.state
params_dict["error_message"] = dt_mgr.error_message

if operator == "PIVOT":
params_dict["sort_keys"] = dt_mgr.sort_keys

pri_data_table_vo = self.pri_data_table_mgr.create_private_data_table(
params_dict
)
Expand Down Expand Up @@ -299,6 +302,9 @@ def update(
operator: operator_options,
}

if operator == "PIVOT":
params_dict["sort_keys"] = dt_mgr.sort_keys

# Get dt_mgr state and error_message
params_dict["state"] = dt_mgr.state
params_dict["error_message"] = dt_mgr.error_message
Expand Down
6 changes: 6 additions & 0 deletions src/spaceone/dashboard/service/public_data_table_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ def transform_data_table(self, params_dict: dict) -> dict:
params_dict["state"] = dt_mgr.state
params_dict["error_message"] = dt_mgr.error_message

if operator == "PIVOT":
params_dict["sort_keys"] = dt_mgr.sort_keys

pub_data_table_vo = self.pub_data_table_mgr.create_public_data_table(
params_dict
)
Expand Down Expand Up @@ -316,6 +319,9 @@ def update(
operator: operator_options,
}

if operator == "PIVOT":
params_dict["sort_keys"] = dt_mgr.sort_keys

# Get dt_mgr state and error_message
params_dict["state"] = dt_mgr.state
params_dict["error_message"] = dt_mgr.error_message
Expand Down
Loading