From 5383e83c04a2e05ae058e185b7cb4eb93c791f21 Mon Sep 17 00:00:00 2001 From: seolmin Date: Tue, 17 Dec 2024 20:24:53 +0900 Subject: [PATCH] feat: add sort_keys options when creating and loading PIVOT table Signed-off-by: seolmin --- .../data_table_manager/data_transformation_manager.py | 4 ++++ src/spaceone/dashboard/model/private_data_table/database.py | 2 ++ src/spaceone/dashboard/model/private_data_table/response.py | 1 + src/spaceone/dashboard/model/public_data_table/database.py | 2 ++ src/spaceone/dashboard/model/public_data_table/response.py | 1 + .../dashboard/service/private_data_table_service.py | 6 ++++++ src/spaceone/dashboard/service/public_data_table_service.py | 6 ++++++ 7 files changed, 22 insertions(+) diff --git a/src/spaceone/dashboard/manager/data_table_manager/data_transformation_manager.py b/src/spaceone/dashboard/manager/data_table_manager/data_transformation_manager.py index 79c8647..1174d51 100755 --- a/src/spaceone/dashboard/manager/data_table_manager/data_transformation_manager.py +++ b/src/spaceone/dashboard/manager/data_table_manager/data_transformation_manager.py @@ -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]: @@ -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) @@ -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( diff --git a/src/spaceone/dashboard/model/private_data_table/database.py b/src/spaceone/dashboard/model/private_data_table/database.py index a4ca176..f99c078 100644 --- a/src/spaceone/dashboard/model/private_data_table/database.py +++ b/src/spaceone/dashboard/model/private_data_table/database.py @@ -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( @@ -36,6 +37,7 @@ class PrivateDataTable(MongoModel): "tags", "labels_info", "data_info", + "sort_keys", ], "minimal_fields": [ "data_table_id", diff --git a/src/spaceone/dashboard/model/private_data_table/response.py b/src/spaceone/dashboard/model/private_data_table/response.py index e49707c..c0bcb4e 100644 --- a/src/spaceone/dashboard/model/private_data_table/response.py +++ b/src/spaceone/dashboard/model/private_data_table/response.py @@ -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 diff --git a/src/spaceone/dashboard/model/public_data_table/database.py b/src/spaceone/dashboard/model/public_data_table/database.py index 3cd51eb..30221bb 100644 --- a/src/spaceone/dashboard/model/public_data_table/database.py +++ b/src/spaceone/dashboard/model/public_data_table/database.py @@ -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( @@ -37,6 +38,7 @@ class PublicDataTable(MongoModel): "tags", "labels_info", "data_info", + "sort_keys", "project_id", "workspace_id", ], diff --git a/src/spaceone/dashboard/model/public_data_table/response.py b/src/spaceone/dashboard/model/public_data_table/response.py index 3d8117c..f9a6b4e 100644 --- a/src/spaceone/dashboard/model/public_data_table/response.py +++ b/src/spaceone/dashboard/model/public_data_table/response.py @@ -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 diff --git a/src/spaceone/dashboard/service/private_data_table_service.py b/src/spaceone/dashboard/service/private_data_table_service.py index c5bfc37..4e37fb9 100644 --- a/src/spaceone/dashboard/service/private_data_table_service.py +++ b/src/spaceone/dashboard/service/private_data_table_service.py @@ -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 ) @@ -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 diff --git a/src/spaceone/dashboard/service/public_data_table_service.py b/src/spaceone/dashboard/service/public_data_table_service.py index 0feb3b4..ed6a75f 100644 --- a/src/spaceone/dashboard/service/public_data_table_service.py +++ b/src/spaceone/dashboard/service/public_data_table_service.py @@ -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 ) @@ -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