mock report data for predetermined workspace names
This commit is contained in:
parent
faf8e3b519
commit
4e75927b52
@ -151,9 +151,10 @@ REPORT_FIXTURE_MAP = {
|
|||||||
"cumulative": CUMULATIVE_BUDGET_BELUGA,
|
"cumulative": CUMULATIVE_BUDGET_BELUGA,
|
||||||
"monthly": MONTHLY_SPEND_BELUGA,
|
"monthly": MONTHLY_SPEND_BELUGA,
|
||||||
"budget": 70_000,
|
"budget": 70_000,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _sum_monthly_spend(data):
|
def _sum_monthly_spend(data):
|
||||||
return sum(
|
return sum(
|
||||||
[
|
[
|
||||||
@ -164,26 +165,8 @@ def _sum_monthly_spend(data):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
class Reports:
|
|
||||||
@classmethod
|
|
||||||
def workspace_totals(cls, workspace):
|
|
||||||
if workspace.name in REPORT_FIXTURE_MAP.keys():
|
|
||||||
budget = REPORT_FIXTURE_MAP[workspace.name]["budget"]
|
|
||||||
spent = _sum_monthly_spend(REPORT_FIXTURE_MAP[workspace.name]["monthly"])
|
|
||||||
elif workspace.request and workspace.request.task_order:
|
|
||||||
ws_to = workspace.request.task_order
|
|
||||||
budget = ws_to.budget
|
|
||||||
spent = 0
|
|
||||||
else:
|
|
||||||
budget = 0
|
|
||||||
spent = 0
|
|
||||||
|
|
||||||
# spent will be derived from CSP data
|
def _derive_project_totals(data):
|
||||||
return {"budget": budget, "spent": spent}
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def monthly_totals(cls, alternate):
|
|
||||||
data = MONTHLY_SPEND_BELUGA if alternate else MONTHLY_SPEND_AARDVARK
|
|
||||||
project_totals = {}
|
project_totals = {}
|
||||||
for project, environments in data.items():
|
for project, environments in data.items():
|
||||||
project_spend = [
|
project_spend = [
|
||||||
@ -196,6 +179,10 @@ class Reports:
|
|||||||
for month, spends in groupby(sorted(project_spend), lambda x: x[0])
|
for month, spends in groupby(sorted(project_spend), lambda x: x[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return project_totals
|
||||||
|
|
||||||
|
|
||||||
|
def _derive_workspace_totals(project_totals):
|
||||||
monthly_spend = [
|
monthly_spend = [
|
||||||
(month, spend)
|
(month, spend)
|
||||||
for project in project_totals.values()
|
for project in project_totals.values()
|
||||||
@ -205,6 +192,37 @@ class Reports:
|
|||||||
for month, spends in groupby(sorted(monthly_spend), lambda m: m[0]):
|
for month, spends in groupby(sorted(monthly_spend), lambda m: m[0]):
|
||||||
workspace_totals[month] = sum([spend[1] for spend in spends])
|
workspace_totals[month] = sum([spend[1] for spend in spends])
|
||||||
|
|
||||||
|
return workspace_totals
|
||||||
|
|
||||||
|
|
||||||
|
class Reports:
|
||||||
|
@classmethod
|
||||||
|
def workspace_totals(cls, workspace):
|
||||||
|
if workspace.name in REPORT_FIXTURE_MAP:
|
||||||
|
budget = REPORT_FIXTURE_MAP[workspace.name]["budget"]
|
||||||
|
spent = _sum_monthly_spend(REPORT_FIXTURE_MAP[workspace.name]["monthly"])
|
||||||
|
elif workspace.request and workspace.request.task_order:
|
||||||
|
ws_to = workspace.request.task_order
|
||||||
|
budget = ws_to.budget
|
||||||
|
# spent will be derived from CSP data
|
||||||
|
spent = 0
|
||||||
|
else:
|
||||||
|
budget = 0
|
||||||
|
spent = 0
|
||||||
|
|
||||||
|
return {"budget": budget, "spent": spent}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def monthly_totals(cls, workspace):
|
||||||
|
if workspace.name in REPORT_FIXTURE_MAP:
|
||||||
|
data = REPORT_FIXTURE_MAP[workspace.name]["monthly"]
|
||||||
|
project_totals = _derive_project_totals(data)
|
||||||
|
workspace_totals = _derive_workspace_totals(project_totals)
|
||||||
|
else:
|
||||||
|
data = {}
|
||||||
|
project_totals = {}
|
||||||
|
workspace_totals = {}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"environments": data,
|
"environments": data,
|
||||||
"projects": project_totals,
|
"projects": project_totals,
|
||||||
@ -212,9 +230,10 @@ class Reports:
|
|||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def cumulative_budget(cls, alternate):
|
def cumulative_budget(cls, workspace):
|
||||||
return {
|
if workspace.name in REPORT_FIXTURE_MAP:
|
||||||
"months": CUMULATIVE_BUDGET_BELUGA
|
months = REPORT_FIXTURE_MAP[workspace.name]["cumulative"]
|
||||||
if alternate
|
else:
|
||||||
else CUMULATIVE_BUDGET_AARDVARK
|
months = {}
|
||||||
}
|
|
||||||
|
return {"months": months}
|
||||||
|
@ -98,7 +98,6 @@ def workspace_reports(workspace_id):
|
|||||||
"view workspace reports",
|
"view workspace reports",
|
||||||
)
|
)
|
||||||
|
|
||||||
alternate_reports = http_request.args.get("alternate")
|
|
||||||
today = date.today()
|
today = date.today()
|
||||||
month = http_request.args.get("month", today.month)
|
month = http_request.args.get("month", today.month)
|
||||||
year = http_request.args.get("year", today.year)
|
year = http_request.args.get("year", today.year)
|
||||||
@ -113,9 +112,9 @@ def workspace_reports(workspace_id):
|
|||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"workspaces/reports/index.html",
|
"workspaces/reports/index.html",
|
||||||
cumulative_budget=Reports.cumulative_budget(alternate_reports),
|
cumulative_budget=Reports.cumulative_budget(workspace),
|
||||||
workspace_totals=Reports.workspace_totals(workspace),
|
workspace_totals=Reports.workspace_totals(workspace),
|
||||||
monthly_totals=Reports.monthly_totals(alternate_reports),
|
monthly_totals=Reports.monthly_totals(workspace),
|
||||||
current_month=current_month,
|
current_month=current_month,
|
||||||
prev_month=prev_month,
|
prev_month=prev_month,
|
||||||
two_months_ago=two_months_ago,
|
two_months_ago=two_months_ago,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user