Skip to content

Commit

Permalink
Merge pull request #67 from ImMin5/master
Browse files Browse the repository at this point in the history
Add delete dataframe data code after finish
  • Loading branch information
ImMin5 authored Jul 2, 2024
2 parents 5d06e70 + 8c7297a commit 6224336
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def get_cost_data(self, blobs: list, options: dict) -> list:
offset = _PAGE_SIZE * page_num
yield costs_data[offset : offset + _PAGE_SIZE]

del df

def list_by_billing_account(self):
billing_account_name = self.billing_account_id
return self.billing_client.billing_subscriptions.list_by_billing_account(
Expand Down
63 changes: 32 additions & 31 deletions src/cloudforet/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, *args, **kwargs):
)

def get_linked_accounts(
self, options: dict, secret_data: dict, domain_id: str, schema
self, options: dict, secret_data: dict, domain_id: str, schema
) -> list:
self.azure_cm_connector.create_session(options, secret_data, schema)
billing_account_info = self.azure_cm_connector.get_billing_account()
Expand All @@ -51,7 +51,7 @@ def get_linked_accounts(
return accounts_info

def get_data(
self, options: dict, secret_data: dict, schema, task_options: dict
self, options: dict, secret_data: dict, schema, task_options: dict
) -> list:
self.azure_cm_connector.create_session(options, secret_data, schema)
self._check_task_options(task_options)
Expand Down Expand Up @@ -102,12 +102,12 @@ def get_data(
yield []

def _make_cost_data(
self,
results: list,
end: datetime,
options: dict,
tenant_id: str = None,
agreement_type: str = None,
self,
results: list,
end: datetime,
options: dict,
tenant_id: str = None,
agreement_type: str = None,
) -> list:
"""Source Data Model"""

Expand Down Expand Up @@ -139,12 +139,12 @@ def _make_cost_data(
return costs_data

def _make_data_info(
self,
result: dict,
billed_date: str,
options: dict,
tenant_id: str = None,
agreement_type: str = None,
self,
result: dict,
billed_date: str,
options: dict,
tenant_id: str = None,
agreement_type: str = None,
):
additional_info: dict = self._get_additional_info(result, options, tenant_id)
cost: float = self._get_cost_from_result_with_options(result, options)
Expand All @@ -158,6 +158,7 @@ def _make_data_info(
tags: dict = self._convert_tags_str_to_dict(result.get("tags"))

aggregate_data = self._get_aggregate_data(result, options)

# Set Network Traffic Cost at Additional Info
additional_info: dict = self._set_network_traffic_cost(
additional_info, product, usage_type
Expand Down Expand Up @@ -211,8 +212,8 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non
additional_info["Benefit Name"] = benefit_name

if (
result.get("pricingmodel") == "Reservation"
and result["metercategory"] == ""
result.get("pricingmodel") == "Reservation"
and result["metercategory"] == ""
):
result["metercategory"] = self._set_product_from_benefit_name(
benefit_name
Expand All @@ -223,14 +224,14 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non
if result.get("metersubcategory") != "" and result.get("metersubcategory"):
additional_info["Meter SubCategory"] = result.get("metersubcategory")
if (
result.get("pricingmodel") == "OnDemand"
and result.get("metercategory") == ""
result.get("pricingmodel") == "OnDemand"
and result.get("metercategory") == ""
):
result["metercategory"] = result.get("metercategory")

if result.get("customername") is None:
if result.get("invoicesectionname") != "" and result.get(
"invoicesectionname"
"invoicesectionname"
):
additional_info["Department Name"] = result.get("invoicesectionname")
elif result.get("departmentname") != "" and result.get("departmentname"):
Expand All @@ -239,15 +240,15 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non
if result.get("accountname") != "" and result.get("accountname"):
additional_info["Enrollment Account Name"] = result["accountname"]
elif result.get("enrollmentaccountname") != "" and result.get(
"enrollmentaccountname"
"enrollmentaccountname"
):
additional_info["Enrollment Account Name"] = result["enrollmentaccountname"]

collect_resource_id = options.get("collect_resource_id", False)
if (
collect_resource_id
and result.get("resourceid") != ""
and result.get("resourceid")
collect_resource_id
and result.get("resourceid") != ""
and result.get("resourceid")
):
additional_info["Resource Id"] = result["resourceid"]
additional_info["Resource Name"] = result["resourceid"].split("/")[-1]
Expand Down Expand Up @@ -331,10 +332,10 @@ def _get_tenant_ids(task_options: dict, collect_scope: str) -> list:

@staticmethod
def _make_scope(
secret_data: dict,
task_options: dict,
collect_scope: str,
customer_tenant_id: str = None,
secret_data: dict,
task_options: dict,
collect_scope: str,
customer_tenant_id: str = None,
):
if collect_scope == "subscription_id":
subscription_id = task_options["subscription_id"]
Expand Down Expand Up @@ -435,7 +436,7 @@ def _convert_date_format_to_utc(date_format: str) -> datetime:
return datetime.strptime(date_format, "%Y-%m-%d").replace(tzinfo=timezone.utc)

def _make_monthly_time_period(
self, start_date: datetime, end_date: datetime
self, start_date: datetime, end_date: datetime
) -> list:
monthly_time_period = []
current_date = end_date
Expand Down Expand Up @@ -465,7 +466,7 @@ def _make_monthly_time_period(

@staticmethod
def _get_linked_customer_tenants(
secret_data: dict, billing_accounts_info: list
secret_data: dict, billing_accounts_info: list
) -> list:
customer_tenants = secret_data.get("customer_tenants", [])
if not customer_tenants:
Expand All @@ -478,7 +479,7 @@ def _get_linked_customer_tenants(

@staticmethod
def _make_accounts_info_from_customer_tenants(
billing_accounts_info: list, customer_tenants: list
billing_accounts_info: list, customer_tenants: list
) -> list:
accounts_info = []
for billing_account_info in billing_accounts_info:
Expand Down Expand Up @@ -516,7 +517,7 @@ def _exclude_cost_data_with_options(result: dict, options: dict) -> bool:

@staticmethod
def _set_network_traffic_cost(
additional_info: dict, product: str, usage_type: str
additional_info: dict, product: str, usage_type: str
) -> dict:
if product in ["Bandwidth", "Content Delivery Network"]:
additional_info["Usage Type Details"] = usage_type
Expand Down

0 comments on commit 6224336

Please sign in to comment.