From b2c1f7a82de516eda6f9c61087f5c613f08fe208 Mon Sep 17 00:00:00 2001 From: ImMin5 Date: Wed, 20 Sep 2023 17:16:02 +0900 Subject: [PATCH] feat: fix start dateformat (#29) Signed-off-by: ImMin5 --- src/cloudforet/cost_analysis/conf/cost_conf.py | 1 + src/cloudforet/cost_analysis/manager/cost_manager.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cloudforet/cost_analysis/conf/cost_conf.py b/src/cloudforet/cost_analysis/conf/cost_conf.py index a01ef18..919c4dc 100644 --- a/src/cloudforet/cost_analysis/conf/cost_conf.py +++ b/src/cloudforet/cost_analysis/conf/cost_conf.py @@ -37,6 +37,7 @@ 'global': 'Global', 'unknown': 'Unknown', 'unassigned': 'Unassigned', + 'intercontinental': 'Intercontinental', 'ap east': 'eastasia', 'ca central': 'canadacentral', 'ca east': 'canadaeast', diff --git a/src/cloudforet/cost_analysis/manager/cost_manager.py b/src/cloudforet/cost_analysis/manager/cost_manager.py index c21b998..853a705 100644 --- a/src/cloudforet/cost_analysis/manager/cost_manager.py +++ b/src/cloudforet/cost_analysis/manager/cost_manager.py @@ -23,7 +23,7 @@ def get_data(self, options, secret_data, schema, task_options): collect_scope = task_options['collect_scope'] account_agreement_type = task_options.get('account_agreement_type') customer_tenants = self._get_customer_tenant_id(task_options, collect_scope) - start = self._convert_date_format_to_utc(task_options['start']) + start = self._add_first_day_of_month(task_options['start']) end = datetime.utcnow().replace(tzinfo=timezone.utc) monthly_time_period = self._make_monthly_time_period(start, end) @@ -66,7 +66,7 @@ class QueryResult Class combined_results = self._combine_rows_and_columns_from_results(results.get('properties').get('rows'), results.get('properties').get('columns')) for cb_result in combined_results: - billed_date = self._set_billed_at(cb_result.get('UsageDate', end)) + billed_date = self._set_billed_date(cb_result.get('UsageDate', end)) if not billed_date: continue @@ -159,7 +159,7 @@ def _combine_make_data(self, costs_data, results): combined_results = self._combine_rows_and_columns_from_results(results.get('properties').get('rows'), results.get('properties').get('columns')) for cb_result in combined_results: - billed_date = self._set_billed_at(cb_result.get('UsageDate')) + billed_date = self._set_billed_date(cb_result.get('UsageDate')) if not billed_date: continue @@ -277,7 +277,7 @@ def _convert_str_to_float_format(num_str: str): return format(float(num_str), 'f') @staticmethod - def _set_billed_at(start): + def _set_billed_date(start): try: if isinstance(start, int): start = str(start) @@ -305,6 +305,10 @@ def _check_prev_and_current_result(prev_result, cur_result): return True + @staticmethod + def _add_first_day_of_month(start_month): + return datetime.strptime(start_month, "%Y-%m").replace(day=1) + @staticmethod def _convert_date_format_to_utc(date_format: str): return datetime.strptime(date_format, '%Y-%m-%d').replace(tzinfo=timezone.utc)