Skip to content
Open
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
9 changes: 6 additions & 3 deletions src/cloud_insight_ai/cost_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import List, Dict, Any


def analyze_cost(cost_data: List[Dict[str, Any]]) -> Dict[str, Any]:
def analyze_cost(cost_data: List[Dict[str, Any]], threshold: float = 0):
"""
Analyze cost data and return summary.

Expand All @@ -34,6 +34,9 @@ def analyze_cost(cost_data: List[Dict[str, Any]]) -> Dict[str, Any]:
daily_costs = defaultdict(float)

for record in cost_data:
if not isinstance(record, dict):
continue # skip invalid entries

service = record.get('service', 'Unknown')
date = record.get('date', 'Unknown')
cost = float(record.get('cost', 0))
Expand Down Expand Up @@ -152,7 +155,7 @@ def _calculate_trends(self, service_daily):
first_cost = sorted_records[0]['cost']
last_cost = sorted_records[-1]['cost']

change_percent = ((last_cost - first_cost) / first_cost) * 100
change_percent = ((last_cost - first_cost) / first_cost) * 100 if first_cost != 0 else 0

if change_percent > 5:
direction = 'increasing'
Expand Down Expand Up @@ -260,4 +263,4 @@ def _generate_recommendations(self, trends, service_totals):
" • Cost trends are stable - continue monitoring for anomalies"
)

return "\n".join(recommendations)
return "\n".join(recommendations)