Skip to content

Commit

Permalink
Merge pull request #30 from cloudforet-io/feature-azure-billing
Browse files Browse the repository at this point in the history
Fix start date format
  • Loading branch information
ImMin5 authored Sep 20, 2023
2 parents cecae02 + b2c1f7a commit 4328c75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/cloudforet/cost_analysis/conf/cost_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
'global': 'Global',
'unknown': 'Unknown',
'unassigned': 'Unassigned',
'intercontinental': 'Intercontinental',
'ap east': 'eastasia',
'ca central': 'canadacentral',
'ca east': 'canadaeast',
Expand Down
12 changes: 8 additions & 4 deletions src/cloudforet/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4328c75

Please sign in to comment.