Skip to content

Modify main cost as PayAsYouGo #71

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

Merged
merged 1 commit into from
Jul 9, 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
23 changes: 12 additions & 11 deletions src/cloudforet/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,10 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non
return additional_info

def _get_cost_from_result_with_options(self, result: dict, options: dict) -> float:
cost = self._convert_str_to_float_format(
result.get("costinbillingcurrency", 0.0)
)
if options.get("pay_as_you_go", False):
cost = self.get_pay_as_you_go_cost(result, cost)

cost = self.get_pay_as_you_go_cost(result)
return cost

def get_pay_as_you_go_cost(self, result: dict, cost: float = 0.0) -> float:
def get_pay_as_you_go_cost(self, result: dict) -> float:
if "paygcostinbillingcurrency" in result:
cost_pay_as_you_go = result.get("paygcostinbillingcurrency", 0.0)
elif "paygprice" in result:
Expand All @@ -300,15 +295,21 @@ def get_pay_as_you_go_cost(self, result: dict, cost: float = 0.0) -> float:
exchange_rate = result.get("exchangeratepricingtobilling", 1.0) or 1.0
cost_pay_as_you_go = pay_g_price * usage_quantity * exchange_rate
else:
cost_pay_as_you_go = cost
cost_pay_as_you_go = 0.0

return cost_pay_as_you_go

def _get_aggregate_data(self, result: dict, options: dict) -> dict:
aggregate_data = {}

if not options.get("pay_as_you_go", False):
pay_as_you_go_cost = self.get_pay_as_you_go_cost(result)
aggregate_data.update({"PayAsYouGo": pay_as_you_go_cost})
if options.get("cost_metric") == "AmortizedCost":
aggregate_data["Amortized Cost"] = self._convert_str_to_float_format(
result.get("amortizedcostinbillingcurrency", 0.0)
)
else:
aggregate_data["Actual Cost"] = self._convert_str_to_float_format(
result.get("costinbillingcurrency", 0.0)
)

return aggregate_data

Expand Down
24 changes: 8 additions & 16 deletions src/cloudforet/cost_analysis/manager/data_source_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,21 @@ def init_response(options):
if currency := options.get("currency"):
plugin_metadata.currency = currency

if options.get("pay_as_you_go"):
plugin_metadata.cost_info = {
"name": "PayAsYouGo",
"unit": options.get("currency", "KRW"),
}
elif options.get("cost_metric") == "AmortizedCost":
plugin_metadata.cost_info = {
plugin_metadata.cost_info = {
"name": "PayAsYouGo",
"unit": options.get("currency", "KRW"),
}

if options.get("cost_metric") == "AmortizedCost":
plugin_metadata.data_info["Amortized Cost"] = {
"name": "Amortized Cost",
"unit": options.get("currency", "KRW"),
}
plugin_metadata.data_info["PayAsYouGo"] = {
"name": "PayAsYouGo",
"unit": options.get("currency", "KRW"),
}
else:
plugin_metadata.cost_info = {
plugin_metadata.data_info["Actual Cost"] = {
"name": "Actual Cost",
"unit": options.get("currency", "KRW"),
}
plugin_metadata.data_info["PayAsYouGo"] = {
"name": "PayAsYouGo",
"unit": options.get("currency", "KRW"),
}

if options.get("use_account_routing"):
plugin_metadata.use_account_routing = True
Expand Down
Loading