Implement client cost attribution
This commit is contained in:
parent
d2b9bc4b32
commit
33883e0977
15 changed files with 362 additions and 21 deletions
|
|
@ -6,6 +6,7 @@ from dataclasses import dataclass
|
|||
from datetime import date
|
||||
from pathlib import Path
|
||||
|
||||
from fin_hub.attribution import optional_attribution
|
||||
from fin_hub.ingest._csv import parse_amount, pick, read_csv_rows
|
||||
|
||||
|
||||
|
|
@ -19,6 +20,10 @@ class HostEuropeCostRow:
|
|||
incurred_on: date | None
|
||||
environment: str = "production"
|
||||
source: str = "hosteurope"
|
||||
client_id: str | None = None
|
||||
application_id: str | None = None
|
||||
app_instance_id: str | None = None
|
||||
cost_attribution_key: str | None = None
|
||||
|
||||
|
||||
def parse_hosteurope_csv(path: Path, *, default_currency: str = "EUR") -> list[HostEuropeCostRow]:
|
||||
|
|
@ -38,6 +43,11 @@ def parse_hosteurope_csv(path: Path, *, default_currency: str = "EUR") -> list[H
|
|||
continue
|
||||
currency = pick(row, "currency") or default_currency
|
||||
environment = pick(row, "environment", "env") or "production"
|
||||
attribution = optional_attribution(
|
||||
pick(row, "client_id", "client") or None,
|
||||
pick(row, "application_id", "app_id", "application") or None,
|
||||
pick(row, "app_instance_id", "instance_id", "instance") or None,
|
||||
)
|
||||
rows.append(
|
||||
HostEuropeCostRow(
|
||||
service_id=service_id,
|
||||
|
|
@ -47,6 +57,10 @@ def parse_hosteurope_csv(path: Path, *, default_currency: str = "EUR") -> list[H
|
|||
period_month=period[:7],
|
||||
incurred_on=incurred_on,
|
||||
environment=environment,
|
||||
client_id=attribution.client_id if attribution else None,
|
||||
application_id=attribution.application_id if attribution else None,
|
||||
app_instance_id=attribution.app_instance_id if attribution else None,
|
||||
cost_attribution_key=attribution.key if attribution else None,
|
||||
)
|
||||
)
|
||||
return rows
|
||||
return rows
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue