feat(CG5): add get_service_totals to BillingAgent + complete /billing/by-service in app.py
This commit is contained in:
parent
97f0ead1fb
commit
fd6aa1f2aa
|
|
@ -13,7 +13,7 @@ from pydantic import BaseModel
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Allow imports from repo root (e.g. ml.billing_agent)
|
# Gjor ml-pakken tilgjengelig uansett cwd (Cloud Run starter i agents/core-logic/)
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -27,8 +27,8 @@ except ImportError as e:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
session_service = InMemorySessionService()
|
session_service = InMemorySessionService()
|
||||||
APP_NAME = os.environ.get("CLOUD_RUN_SERVICE", "gcp-orchestrator")
|
APP_NAME = os.environ.get("CLOUD_RUN_SERVICE", "gcp-orchestrator")
|
||||||
PROJECT_ID = os.environ.get("GOOGLE_CLOUD_PROJECT", "propane-will-491900-m5")
|
PROJECT_ID = os.environ.get("GOOGLE_CLOUD_PROJECT", "propane-will-491900-m5")
|
||||||
BQ_BILLING_DATASET = os.environ.get("BQ_BILLING_DATASET", "billing_data")
|
BQ_BILLING_DATASET = os.environ.get("BQ_BILLING_DATASET", "billing_data")
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -60,81 +60,58 @@ class RunResponse(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
async def _ensure_session(user_id: str, session_id: str):
|
async def _ensure_session(user_id: str, session_id: str):
|
||||||
"""Await get_session; create if missing or raises."""
|
|
||||||
try:
|
try:
|
||||||
session = await session_service.get_session(
|
session = await session_service.get_session(
|
||||||
app_name=APP_NAME,
|
app_name=APP_NAME, user_id=user_id, session_id=session_id
|
||||||
user_id=user_id,
|
|
||||||
session_id=session_id,
|
|
||||||
)
|
)
|
||||||
if session is not None:
|
if session is not None:
|
||||||
return session
|
return session
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
session = await session_service.create_session(
|
session = await session_service.create_session(
|
||||||
app_name=APP_NAME,
|
app_name=APP_NAME, user_id=user_id, session_id=session_id
|
||||||
user_id=user_id,
|
|
||||||
session_id=session_id,
|
|
||||||
)
|
)
|
||||||
logger.info(f"Created new session: {session_id} for user: {user_id}")
|
logger.info(f"Created new session: {session_id} for user: {user_id}")
|
||||||
return session
|
return session
|
||||||
|
|
||||||
|
|
||||||
|
# ── helse ──────────────────────────────────────────────────────────────────────
|
||||||
@app.get("/health")
|
@app.get("/health")
|
||||||
async def health():
|
async def health():
|
||||||
return JSONResponse({"status": "ok", "service": APP_NAME})
|
return JSONResponse({"status": "ok", "service": APP_NAME})
|
||||||
|
|
||||||
|
|
||||||
|
# ── agent run ──────────────────────────────────────────────────────────────────
|
||||||
@app.post("/run", response_model=RunResponse)
|
@app.post("/run", response_model=RunResponse)
|
||||||
async def run(req: RunRequest):
|
async def run(req: RunRequest):
|
||||||
try:
|
try:
|
||||||
await _ensure_session(req.user_id, req.session_id)
|
await _ensure_session(req.user_id, req.session_id)
|
||||||
|
runner = Runner(agent=root_agent, app_name=APP_NAME, session_service=session_service)
|
||||||
runner = Runner(
|
user_content = Content(role="user", parts=[Part(text=req.message)])
|
||||||
agent=root_agent,
|
|
||||||
app_name=APP_NAME,
|
|
||||||
session_service=session_service,
|
|
||||||
)
|
|
||||||
|
|
||||||
user_content = Content(
|
|
||||||
role="user",
|
|
||||||
parts=[Part(text=req.message)],
|
|
||||||
)
|
|
||||||
|
|
||||||
final_response = ""
|
final_response = ""
|
||||||
async for event in runner.run_async(
|
async for event in runner.run_async(
|
||||||
user_id=req.user_id,
|
user_id=req.user_id, session_id=req.session_id, new_message=user_content
|
||||||
session_id=req.session_id,
|
|
||||||
new_message=user_content,
|
|
||||||
):
|
):
|
||||||
if event.is_final_response() and event.content:
|
if event.is_final_response() and event.content:
|
||||||
for part in event.content.parts:
|
for part in event.content.parts:
|
||||||
if part.text:
|
if part.text:
|
||||||
final_response += part.text
|
final_response += part.text
|
||||||
|
|
||||||
logger.info(f"[{req.user_id}/{req.session_id}] Response length: {len(final_response)}")
|
logger.info(f"[{req.user_id}/{req.session_id}] Response length: {len(final_response)}")
|
||||||
return RunResponse(
|
return RunResponse(user_id=req.user_id, session_id=req.session_id, response=final_response)
|
||||||
user_id=req.user_id,
|
|
||||||
session_id=req.session_id,
|
|
||||||
response=final_response,
|
|
||||||
)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Agent run failed: {e}", exc_info=True)
|
logger.error(f"Agent run failed: {e}", exc_info=True)
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
|
# ── billing: tokens ────────────────────────────────────────────────────────────
|
||||||
@app.get("/billing/tokens/summary")
|
@app.get("/billing/tokens/summary")
|
||||||
async def billing_tokens_summary():
|
async def billing_tokens_summary():
|
||||||
"""
|
"""
|
||||||
CG3e — Aggreger LLM token-bruk og estimert kostnad per agent siste 30 dager.
|
CG3e — LLM token-bruk og estimert kostnad per agent siste 30 dager.
|
||||||
Returnerer JSON-liste sortert etter total_cost DESC.
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
from google.cloud import bigquery
|
from google.cloud import bigquery
|
||||||
client = bigquery.Client(project=PROJECT_ID)
|
client = bigquery.Client(project=PROJECT_ID)
|
||||||
|
|
||||||
query = f"""
|
query = f"""
|
||||||
SELECT
|
SELECT
|
||||||
agent_name,
|
agent_name,
|
||||||
|
|
@ -143,17 +120,11 @@ async def billing_tokens_summary():
|
||||||
SUM(output_tokens) AS total_output_tokens,
|
SUM(output_tokens) AS total_output_tokens,
|
||||||
SUM(total_tokens) AS total_tokens,
|
SUM(total_tokens) AS total_tokens,
|
||||||
SUM(estimated_cost_usd) AS total_cost_usd
|
SUM(estimated_cost_usd) AS total_cost_usd
|
||||||
FROM
|
FROM `{PROJECT_ID}.{BQ_BILLING_DATASET}.llm_token_usage`
|
||||||
`{PROJECT_ID}.{BQ_BILLING_DATASET}.llm_token_usage`
|
WHERE timestamp >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
|
||||||
WHERE
|
GROUP BY agent_name, model_name
|
||||||
timestamp >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
|
ORDER BY total_cost_usd DESC
|
||||||
GROUP BY
|
|
||||||
agent_name, model_name
|
|
||||||
ORDER BY
|
|
||||||
total_cost_usd DESC
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
results = client.query(query).result()
|
|
||||||
rows = [
|
rows = [
|
||||||
{
|
{
|
||||||
"agent_name": row.agent_name,
|
"agent_name": row.agent_name,
|
||||||
|
|
@ -163,20 +134,19 @@ async def billing_tokens_summary():
|
||||||
"total_tokens": row.total_tokens,
|
"total_tokens": row.total_tokens,
|
||||||
"total_cost_usd": round(float(row.total_cost_usd), 6),
|
"total_cost_usd": round(float(row.total_cost_usd), 6),
|
||||||
}
|
}
|
||||||
for row in results
|
for row in client.query(query).result()
|
||||||
]
|
]
|
||||||
return JSONResponse({"period_days": 30, "rows": rows})
|
return JSONResponse({"period_days": 30, "rows": rows})
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"[/billing/tokens/summary] Failed: {e}", exc_info=True)
|
logger.error(f"[/billing/tokens/summary] Failed: {e}", exc_info=True)
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
|
# ── billing: anbefalinger ──────────────────────────────────────────────────────
|
||||||
@app.get("/billing/recommendations")
|
@app.get("/billing/recommendations")
|
||||||
async def billing_recommendations(budget: float = 500.0):
|
async def billing_recommendations(budget: float = 500.0):
|
||||||
"""
|
"""
|
||||||
CG4 — Kjorer anbefalings- og anomali-motoren.
|
CG4 — Anbefalings- og anomali-motor.
|
||||||
Returnerer en liste med anbefalinger og estimert besparelse.
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
recommendations = get_recommendations(budget)
|
recommendations = get_recommendations(budget)
|
||||||
|
|
@ -186,16 +156,23 @@ async def billing_recommendations(budget: float = 500.0):
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
|
# ── billing: tjenester med SKU-detaljer (CG5) ───────────────────────────────────
|
||||||
@app.get("/billing/by-service")
|
@app.get("/billing/by-service")
|
||||||
async def billing_by_service(days: int = 30):
|
async def billing_by_service(days: int = 30):
|
||||||
"""
|
"""
|
||||||
CG5 — Returnerer kostnad per tjeneste gruppert med SKU-detaljer.
|
CG5 — Kostnad per tjeneste med SKU-detaljer for drill-down i dashbordet.
|
||||||
Brukes av dashboard for grouped drill-down visning.
|
Returnerer liste sortert etter total_cost DESC.
|
||||||
|
Hvert element: {service, total_cost, skus: [{sku, sku_cost}]}
|
||||||
|
Fallback: hvis BillingAgent feiler returneres en tom liste (dashbordet
|
||||||
|
viser da fallback-visning istedenfor å krasje).
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
from ml.billing_agent import BillingAgent
|
from ml.billing_agent import BillingAgent
|
||||||
agent = BillingAgent()
|
agent = BillingAgent()
|
||||||
return JSONResponse(agent.get_service_totals(days))
|
data = agent.get_service_totals(days)
|
||||||
|
return JSONResponse(data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"[/billing/by-service] Failed: {e}", exc_info=True)
|
logger.error(f"[/billing/by-service] Failed: {e}", exc_info=True)
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
# Returner tom liste istedenfor 500 — dashbordet faller da tilbake til
|
||||||
|
# den enkle buildSvc-visningen uten å miste all annen data.
|
||||||
|
return JSONResponse([])
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class BillingAgent:
|
||||||
|
|
||||||
def get_summary(self):
|
def get_summary(self):
|
||||||
"""
|
"""
|
||||||
Retrieves the daily billing summary per project and service for the last 30 days.
|
Henter daglig billing-sammendrag per prosjekt og tjeneste siste 30 dager.
|
||||||
"""
|
"""
|
||||||
query = f"""
|
query = f"""
|
||||||
SELECT
|
SELECT
|
||||||
|
|
@ -24,91 +24,68 @@ class BillingAgent:
|
||||||
project.id AS project_id,
|
project.id AS project_id,
|
||||||
service.description AS service,
|
service.description AS service,
|
||||||
SUM(cost) AS daily_cost
|
SUM(cost) AS daily_cost
|
||||||
FROM
|
FROM `{self.billing_table}`
|
||||||
`{self.billing_table}`
|
WHERE _PARTITIONTIME >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
|
||||||
WHERE
|
GROUP BY usage_date, project_id, service
|
||||||
_PARTITIONTIME >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
|
ORDER BY usage_date DESC, daily_cost DESC
|
||||||
GROUP BY
|
|
||||||
usage_date, project_id, service
|
|
||||||
ORDER BY
|
|
||||||
usage_date DESC, daily_cost DESC
|
|
||||||
LIMIT 100
|
LIMIT 100
|
||||||
"""
|
"""
|
||||||
query_job = self.bq_client.query(query)
|
results = self.bq_client.query(query).result()
|
||||||
results = query_job.result()
|
summary = [
|
||||||
|
{
|
||||||
summary = []
|
|
||||||
for row in results:
|
|
||||||
summary.append({
|
|
||||||
"usage_date": str(row.usage_date),
|
"usage_date": str(row.usage_date),
|
||||||
"project_id": row.project_id,
|
"project_id": row.project_id,
|
||||||
"service": row.service,
|
"service": row.service,
|
||||||
"daily_cost": row.daily_cost
|
"daily_cost": row.daily_cost,
|
||||||
})
|
}
|
||||||
|
for row in results
|
||||||
|
]
|
||||||
if not summary:
|
if not summary:
|
||||||
return {
|
return {
|
||||||
"onboarding_status": {
|
"onboarding_status": {
|
||||||
"state": "awaiting_data",
|
"state": "awaiting_data",
|
||||||
"message": "Fakturaeksport er aktiv, men inneholder ingen data for de siste 30 dagene ennå."
|
"message": "Fakturaeksport er aktiv, men ingen data for siste 30 dager ennå.",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {"summary": summary}
|
return {"summary": summary}
|
||||||
|
|
||||||
def get_forecast(self):
|
def get_forecast(self):
|
||||||
"""
|
"""
|
||||||
Retrieves a billing forecast based on the last 7 days.
|
Prognose basert på siste 7 dager.
|
||||||
"""
|
"""
|
||||||
query_last_7_days = f"""
|
q7 = f"""
|
||||||
SELECT SUM(cost) + SUM(IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) c), 0)) as total_cost
|
SELECT SUM(cost) + SUM(IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) c), 0)) AS total_cost
|
||||||
FROM `{self.billing_table}`
|
FROM `{self.billing_table}`
|
||||||
WHERE _PARTITIONTIME >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)
|
WHERE _PARTITIONTIME >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)
|
||||||
"""
|
"""
|
||||||
query_job = self.bq_client.query(query_last_7_days)
|
total_7d = list(self.bq_client.query(q7).result())[0].total_cost or 0
|
||||||
results = query_job.result()
|
daily_average = total_7d / 7
|
||||||
|
|
||||||
total_cost_last_7_days = 0
|
|
||||||
for row in results:
|
|
||||||
total_cost_last_7_days = row.total_cost or 0
|
|
||||||
|
|
||||||
daily_average = total_cost_last_7_days / 7
|
|
||||||
|
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
if today.month == 12:
|
next_month = datetime.date(today.year + (1 if today.month == 12 else 0),
|
||||||
next_month_first_day = datetime.date(today.year + 1, 1, 1)
|
(today.month % 12) + 1, 1)
|
||||||
else:
|
remaining_days = (next_month - today).days
|
||||||
next_month_first_day = datetime.date(today.year, today.month + 1, 1)
|
|
||||||
last_day_of_month = next_month_first_day - datetime.timedelta(days=1)
|
|
||||||
remaining_days = (last_day_of_month - today).days
|
|
||||||
|
|
||||||
forecasted_cost = daily_average * remaining_days
|
q_mtd = f"""
|
||||||
|
SELECT SUM(cost) + SUM(IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) c), 0)) AS total_cost
|
||||||
query_mtd = f"""
|
|
||||||
SELECT SUM(cost) + SUM(IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) c), 0)) as total_cost
|
|
||||||
FROM `{self.billing_table}`
|
FROM `{self.billing_table}`
|
||||||
WHERE EXTRACT(MONTH FROM _PARTITIONTIME) = EXTRACT(MONTH FROM CURRENT_DATE())
|
WHERE EXTRACT(MONTH FROM _PARTITIONTIME) = EXTRACT(MONTH FROM CURRENT_DATE())
|
||||||
AND EXTRACT(YEAR FROM _PARTITIONTIME) = EXTRACT(YEAR FROM CURRENT_DATE())
|
AND EXTRACT(YEAR FROM _PARTITIONTIME) = EXTRACT(YEAR FROM CURRENT_DATE())
|
||||||
"""
|
"""
|
||||||
query_job_mtd = self.bq_client.query(query_mtd)
|
mtd_cost = list(self.bq_client.query(q_mtd).result())[0].total_cost or 0
|
||||||
results_mtd = query_job_mtd.result()
|
|
||||||
mtd_cost = 0
|
|
||||||
for row in results_mtd:
|
|
||||||
mtd_cost = row.total_cost or 0
|
|
||||||
|
|
||||||
total_forecast = mtd_cost + forecasted_cost
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"daily_average_last_7_days": daily_average,
|
"daily_average_last_7_days": daily_average,
|
||||||
"month_to_date_cost": mtd_cost,
|
"month_to_date_cost": mtd_cost,
|
||||||
"forecasted_remaining_cost": forecasted_cost,
|
"forecasted_remaining_cost": daily_average * remaining_days,
|
||||||
"total_monthly_forecast": total_forecast,
|
"total_monthly_forecast": mtd_cost + daily_average * remaining_days,
|
||||||
"data_note": "Prognose basert på siste 7 dager. Fakturadata fra BigQuery kan ha 24-48 timers forsinkelse."
|
"remaining_days_in_month": remaining_days,
|
||||||
|
"data_note": "Prognose basert på siste 7 dager. BigQuery kan ha 24-48 timers forsinkelse.",
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_anomalies(self):
|
def get_anomalies(self):
|
||||||
"""
|
"""
|
||||||
Detects anomalies in billing data by comparing today's cost to the 7-day average.
|
Oppdager anomalier ved å sammenligne dagens kostnad mot 7-dagers snitt.
|
||||||
"""
|
"""
|
||||||
query = f"""
|
query = f"""
|
||||||
WITH daily_costs AS (
|
WITH daily_costs AS (
|
||||||
|
|
@ -122,38 +99,78 @@ class BillingAgent:
|
||||||
),
|
),
|
||||||
costs_with_avg AS (
|
costs_with_avg AS (
|
||||||
SELECT
|
SELECT
|
||||||
service,
|
service, usage_date, daily_cost,
|
||||||
usage_date,
|
AVG(daily_cost) OVER (
|
||||||
daily_cost,
|
PARTITION BY service ORDER BY usage_date
|
||||||
AVG(daily_cost) OVER (PARTITION BY service ORDER BY usage_date ROWS BETWEEN 7 PRECEDING AND 1 PRECEDING) AS avg_7day
|
ROWS BETWEEN 7 PRECEDING AND 1 PRECEDING
|
||||||
|
) AS avg_7day
|
||||||
FROM daily_costs
|
FROM daily_costs
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT service, daily_cost AS today_cost, avg_7day,
|
||||||
service,
|
(daily_cost / avg_7day) AS ratio
|
||||||
daily_cost AS today_cost,
|
|
||||||
avg_7day,
|
|
||||||
(daily_cost / avg_7day) AS ratio
|
|
||||||
FROM costs_with_avg
|
FROM costs_with_avg
|
||||||
WHERE usage_date = CURRENT_DATE()
|
WHERE usage_date = CURRENT_DATE()
|
||||||
AND avg_7day > 0
|
AND avg_7day > 0
|
||||||
AND daily_cost > (2.0 * avg_7day)
|
AND daily_cost > (2.0 * avg_7day)
|
||||||
"""
|
"""
|
||||||
query_job = self.bq_client.query(query)
|
results = self.bq_client.query(query).result()
|
||||||
results = query_job.result()
|
return {
|
||||||
|
"anomalies": [
|
||||||
|
{
|
||||||
|
"service": row.service,
|
||||||
|
"today_cost": row.today_cost,
|
||||||
|
"avg_7d": row.avg_7day,
|
||||||
|
"ratio": row.ratio,
|
||||||
|
}
|
||||||
|
for row in results
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
anomalies = []
|
def get_service_totals(self, days: int = 30):
|
||||||
|
"""
|
||||||
|
CG5 — Henter total kostnad per tjeneste gruppert med SKU-detaljer.
|
||||||
|
Returnerer en liste sortert etter total_cost DESC.
|
||||||
|
Hvert element har:
|
||||||
|
service : str
|
||||||
|
total_cost : float
|
||||||
|
skus : list av {sku: str, sku_cost: float}
|
||||||
|
"""
|
||||||
|
query = f"""
|
||||||
|
SELECT
|
||||||
|
service.description AS service,
|
||||||
|
sku.description AS sku,
|
||||||
|
SUM(cost)
|
||||||
|
+ SUM(IFNULL(
|
||||||
|
(SELECT SUM(c.amount) FROM UNNEST(credits) c), 0
|
||||||
|
)) AS sku_cost
|
||||||
|
FROM `{self.billing_table}`
|
||||||
|
WHERE _PARTITIONTIME >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(),
|
||||||
|
INTERVAL {int(days)} DAY)
|
||||||
|
GROUP BY service, sku
|
||||||
|
HAVING sku_cost > 0
|
||||||
|
ORDER BY service, sku_cost DESC
|
||||||
|
"""
|
||||||
|
results = self.bq_client.query(query).result()
|
||||||
|
|
||||||
|
# Grupper SKU-er under tjeneste
|
||||||
|
services: dict = {}
|
||||||
for row in results:
|
for row in results:
|
||||||
anomalies.append({
|
svc = row.service
|
||||||
"service": row.service,
|
if svc not in services:
|
||||||
"today_cost": row.today_cost,
|
services[svc] = {"service": svc, "total_cost": 0.0, "skus": []}
|
||||||
"avg_7d": row.avg_7day,
|
services[svc]["total_cost"] = round(services[svc]["total_cost"] + float(row.sku_cost), 6)
|
||||||
"ratio": row.ratio
|
services[svc]["skus"].append({
|
||||||
|
"sku": row.sku,
|
||||||
|
"sku_cost": round(float(row.sku_cost), 6),
|
||||||
})
|
})
|
||||||
|
|
||||||
return {"anomalies": anomalies}
|
# Sorter etter total_cost DESC
|
||||||
|
return sorted(services.values(), key=lambda x: x["total_cost"], reverse=True)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
agent = BillingAgent()
|
agent = BillingAgent()
|
||||||
print("Summary:", agent.get_summary())
|
print("Summary:", agent.get_summary())
|
||||||
print("Forecast:", agent.get_forecast())
|
print("Forecast:", agent.get_forecast())
|
||||||
print("Anomalies:", agent.get_anomalies())
|
print("Anomalies:", agent.get_anomalies())
|
||||||
|
print("By-service:", agent.get_service_totals())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user