Skip to content

Commit

Permalink
Add sourcetype column to indicate whether a cost is shared
Browse files Browse the repository at this point in the history
  • Loading branch information
manics committed Jun 13, 2024
1 parent 3600c98 commit be06bf5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 42 deletions.
14 changes: 12 additions & 2 deletions aws_project_costs/project_costs.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import json
from enum import Enum
from operator import itemgetter

import pandas as pd

PROJECT_TAG = "Proj"


class CostSourceType(Enum):
PROJECT_SPECIFIC = "project"
SHARED = "shared"


def _get_account_cfg(config, accountname):
for acc in config["accounts"]:
if acc["name"].lower() == accountname.lower():
Expand Down Expand Up @@ -43,6 +49,7 @@ def _project_specific_account(start, description, project_name, costs_dict):
project_name,
description,
costs_tag,
CostSourceType.PROJECT_SPECIFIC.value,
item["COST"],
)
)
Expand Down Expand Up @@ -76,6 +83,7 @@ def _shared_account(
project_name,
description,
costs_tag,
CostSourceType.PROJECT_SPECIFIC.value,
item["COST"],
)
)
Expand All @@ -90,6 +98,7 @@ def _shared_account(
project_name,
description,
costs_tag,
CostSourceType.SHARED.value,
cost_per_share * projects_in_group[project_name],
)
)
Expand Down Expand Up @@ -137,7 +146,7 @@ def allocate_costs(*, accountname, config, start, df):
else:
raise ValueError(f"Invalid billing-type {billing_type}")

# [(start, project name, account, source, cost)]
# [(start, project name, account, source, source type, cost)]
return rows


Expand Down Expand Up @@ -169,7 +178,8 @@ def analyse_costs_csv(config, costs_csv_filename, output_csv_filename=None):

if output_csv_filename:
out = pd.DataFrame(
itemised_rows, columns=["start", "projectname", "account", "tag", "cost"]
itemised_rows,
columns=["start", "projectname", "account", "tag", "sourcetype", "cost"],
)
out.to_csv(output_csv_filename, index=False)
else:
Expand Down
80 changes: 40 additions & 40 deletions example/output.csv
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
start,projectname,account,tag,cost
2024-01-01,Internal - development,aws-auth [shared],Proj$,4.264684
2024-01-01,Internal - training,aws-auth [shared],Proj$,4.264684
2024-01-01,No shared costs,aws-auth [shared],Proj$,0.0
2024-01-01,No shared costs,aws-auth [shared],Proj$project-noshared,0.33
2024-01-01,Project A,aws-auth [shared],Proj$,4.264684
2024-01-01,Project A,aws-auth [shared],Proj$project-001,21.24323
2024-01-01,Project B,aws-auth [shared],Proj$,4.264684
2024-01-01,Project B,aws-auth [shared],Proj$project-002,0.1231
2024-01-01,Project B,aws-auth [shared],Proj$project-003,9.32
2024-01-01,SPECIAL-OPS,aws-auth [shared],Proj$,4.264684
2024-01-01,SPECIAL-OPS,aws-auth [shared],Proj$project-004,9.3
2024-01-01,No shared costs,aws-monitoring [shared],Proj$,0.0
2024-01-01,SPECIAL-OPS,aws-monitoring [shared],Proj$,444.66772
2024-01-01,Internal - development,aws-development [project-specific],Proj$,1002.1
2024-01-01,Internal - development,aws-development [project-specific],Proj$a,501.05
2024-01-01,Internal - development,aws-development [project-specific],Proj$b,250.5025
2024-01-01,SPECIAL-OPS,aws-special-ops [project-specific],Proj$,2324.22201
2024-01-01,SPECIAL-OPS,aws-special-ops-dev [project-specific],Proj$,101.1111
2024-01-01,SPECIAL-OPS,aws-special-ops-dev [project-specific],Proj$project-001,0.02
2024-01-01,Internal - training,aws-training [project-specific],Proj$project-001,45.2
2024-01-01,Internal - training,aws-training [project-specific],Proj$project-004,66.66
2024-01-01,Internal - development,aws-production-1 [shared],Proj$shared,1.0
2024-01-01,Internal - training,aws-production-1 [shared],Proj$shared,1.0
2024-01-01,Project A,aws-production-1 [shared],Proj$project-001,888.22
2024-01-01,Project A,aws-production-1 [shared],Proj$shared,1.0
2024-01-01,Project B,aws-production-1 [shared],Proj$project-002,55.668
2024-01-01,Project B,aws-production-1 [shared],Proj$shared,1.0
2024-01-01,SPECIAL-OPS,aws-production-1 [shared],Proj$shared,1.0
2024-01-01,Internal - development,aws-production-2 [shared],Proj$,5.1
2024-01-01,Internal - training,aws-production-2 [shared],Proj$,5.1
2024-01-01,Project A,aws-production-2 [shared],Proj$,5.1
2024-01-01,Project B,aws-production-2 [shared],Proj$,5.1
2024-01-01,Project B,aws-production-2 [shared],Proj$project-003,0.111
2024-01-01,SPECIAL-OPS,aws-production-2 [shared],Proj$,5.1
2024-01-01,SPECIAL-OPS,aws-production-2 [shared],Proj$project-004,545.3009
2024-01-01,Complicated Project Name / 🐣 / 🐧,aws-complicated-project [project-specific],Proj$,992.55
2024-01-01,Complicated Project Name / 🐣 / 🐧,aws-complicated-project [project-specific],Proj$chick,101.0001
2024-01-01,Complicated Project Name / 🐣 / 🐧,aws-complicated-project [project-specific],Proj$duck,213.44
2024-01-01,Complicated Project Name / 🐣 / 🐧,aws-complicated-project [project-specific],Proj$penguin,4321.10303
start,projectname,account,tag,sourcetype,cost
2024-01-01,Internal - development,aws-auth [shared],Proj$,shared,4.264684
2024-01-01,Internal - training,aws-auth [shared],Proj$,shared,4.264684
2024-01-01,No shared costs,aws-auth [shared],Proj$,shared,0.0
2024-01-01,No shared costs,aws-auth [shared],Proj$project-noshared,project,0.33
2024-01-01,Project A,aws-auth [shared],Proj$,shared,4.264684
2024-01-01,Project A,aws-auth [shared],Proj$project-001,project,21.24323
2024-01-01,Project B,aws-auth [shared],Proj$,shared,4.264684
2024-01-01,Project B,aws-auth [shared],Proj$project-002,project,0.1231
2024-01-01,Project B,aws-auth [shared],Proj$project-003,project,9.32
2024-01-01,SPECIAL-OPS,aws-auth [shared],Proj$,shared,4.264684
2024-01-01,SPECIAL-OPS,aws-auth [shared],Proj$project-004,project,9.3
2024-01-01,No shared costs,aws-monitoring [shared],Proj$,shared,0.0
2024-01-01,SPECIAL-OPS,aws-monitoring [shared],Proj$,shared,444.66772
2024-01-01,Internal - development,aws-development [project-specific],Proj$,project,1002.1
2024-01-01,Internal - development,aws-development [project-specific],Proj$a,project,501.05
2024-01-01,Internal - development,aws-development [project-specific],Proj$b,project,250.5025
2024-01-01,SPECIAL-OPS,aws-special-ops [project-specific],Proj$,project,2324.22201
2024-01-01,SPECIAL-OPS,aws-special-ops-dev [project-specific],Proj$,project,101.1111
2024-01-01,SPECIAL-OPS,aws-special-ops-dev [project-specific],Proj$project-001,project,0.02
2024-01-01,Internal - training,aws-training [project-specific],Proj$project-001,project,45.2
2024-01-01,Internal - training,aws-training [project-specific],Proj$project-004,project,66.66
2024-01-01,Internal - development,aws-production-1 [shared],Proj$shared,shared,1.0
2024-01-01,Internal - training,aws-production-1 [shared],Proj$shared,shared,1.0
2024-01-01,Project A,aws-production-1 [shared],Proj$project-001,project,888.22
2024-01-01,Project A,aws-production-1 [shared],Proj$shared,shared,1.0
2024-01-01,Project B,aws-production-1 [shared],Proj$project-002,project,55.668
2024-01-01,Project B,aws-production-1 [shared],Proj$shared,shared,1.0
2024-01-01,SPECIAL-OPS,aws-production-1 [shared],Proj$shared,shared,1.0
2024-01-01,Internal - development,aws-production-2 [shared],Proj$,shared,5.1
2024-01-01,Internal - training,aws-production-2 [shared],Proj$,shared,5.1
2024-01-01,Project A,aws-production-2 [shared],Proj$,shared,5.1
2024-01-01,Project B,aws-production-2 [shared],Proj$,shared,5.1
2024-01-01,Project B,aws-production-2 [shared],Proj$project-003,project,0.111
2024-01-01,SPECIAL-OPS,aws-production-2 [shared],Proj$,shared,5.1
2024-01-01,SPECIAL-OPS,aws-production-2 [shared],Proj$project-004,project,545.3009
2024-01-01,Complicated Project Name / 🐣 / 🐧,aws-complicated-project [project-specific],Proj$,project,992.55
2024-01-01,Complicated Project Name / 🐣 / 🐧,aws-complicated-project [project-specific],Proj$chick,project,101.0001
2024-01-01,Complicated Project Name / 🐣 / 🐧,aws-complicated-project [project-specific],Proj$duck,project,213.44
2024-01-01,Complicated Project Name / 🐣 / 🐧,aws-complicated-project [project-specific],Proj$penguin,project,4321.10303

0 comments on commit be06bf5

Please sign in to comment.