Skip to content

Commit

Permalink
Billing small fixes (#601)
Browse files Browse the repository at this point in the history
* Added gcp-projects API to billing, new Billing CostByTime page

* Updated StackedAreaByDateChart with more custom properties.

* First version of Bar and Dount charts.

* Upgrading babel / vulnerability.
  • Loading branch information
milo-hyben authored Nov 3, 2023
1 parent 1705d7b commit ee8b231
Show file tree
Hide file tree
Showing 13 changed files with 578 additions and 73 deletions.
11 changes: 1 addition & 10 deletions api/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,4 @@
from api.routes.web import router as web_router
from api.routes.enum import router as enum_router
from api.routes.sequencing_groups import router as sequencing_groups_router

billing_envs = [
'SM_GCP_BQ_AGGREG_VIEW',
'SM_GCP_BQ_AGGREG_RAW',
'SM_GCP_BQ_AGGREG_EXT_VIEW',
'SM_GCP_BQ_BUDGET_VIEW',
]

if all([os.environ.get(env) for env in billing_envs]):
from api.routes.billing import router as billing_router
from api.routes.billing import router as billing_router
7 changes: 6 additions & 1 deletion api/utils/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ def get_invoice_month_range(convert_month: date) -> tuple[date, date]:
# Grab the first day of invoice month then subtract INVOICE_DAY_DIFF days
start_day = first_day + timedelta(days=-INVOICE_DAY_DIFF)

if convert_month.month == 12:
next_month = first_day.replace(month=1, year=convert_month.year + 1)
else:
next_month = first_day.replace(month=convert_month.month + 1)

# Grab the last day of invoice month then add INVOICE_DAY_DIFF days
last_day = (
first_day.replace(month=(convert_month.month % 12) + 1)
next_month
+ timedelta(days=-1)
+ timedelta(days=INVOICE_DAY_DIFF)
)
Expand Down
2 changes: 1 addition & 1 deletion db/python/layers/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ async def get_running_cost(
results.append(
BillingCostBudgetRecord.from_json(
{
'field': f'All {field.value}s',
'field': f'{BillingColumn.generate_all_title(field)}',
'total_monthly': (
total_monthly['C']['ALL'] + total_monthly['S']['ALL']
),
Expand Down
9 changes: 9 additions & 0 deletions models/models/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ def extended_cols(cls) -> list[str]:
'sequencing_group',
]

@staticmethod
def generate_all_title(record) -> str:
"""Generate Column as All Title
"""
if record == BillingColumn.PROJECT:
return 'All GCP Projects'

return f'All {record.title()}s'


class BillingTotalCostQueryModel(SMBase):
"""
Expand Down
176 changes: 127 additions & 49 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions web/src/pages/billing/Billing.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
.field-selector-dropdown {
width: 80% !important;
}

.donut-chart {
margin-top: 20px;
}
Loading

0 comments on commit ee8b231

Please sign in to comment.