diff --git a/atst/domain/reports.py b/atst/domain/reports.py index 1d14e006..8ac261a2 100644 --- a/atst/domain/reports.py +++ b/atst/domain/reports.py @@ -1,9 +1,160 @@ -class Reports: +from itertools import groupby + +MONTHLY_SPEND = { + "LC04": { + "Integ": { + "10/2018": 284, + "11/2018": 1210, + "12/2018": 1430, + "01/2019": 1366, + "02/2019": 1169, + "03/2019": 991, + "04/2019": 978, + "05/2019": 737, + }, + "PreProd": { + "10/2018": 812, + "11/2018": 1389, + "12/2018": 1425, + "01/2019": 1306, + "02/2019": 1112, + "03/2019": 936, + "04/2019": 921, + "05/2019": 694, + }, + "Prod": { + "10/2018": 1742, + "11/2018": 1716, + "12/2018": 1866, + "01/2019": 1809, + "02/2019": 1839, + "03/2019": 1633, + "04/2019": 1654, + "05/2019": 1103, + }, + }, + "SF18": { + "Integ": { + "12/2018": 1498, + "01/2019": 1400, + "02/2019": 1394, + "03/2019": 1171, + "04/2019": 1200, + "05/2019": 963, + }, + "PreProd": { + "12/2018": 1780, + "01/2019": 1667, + "02/2019": 1703, + "03/2019": 1474, + "04/2019": 1441, + "05/2019": 933, + }, + "Prod": { + "12/2018": 1686, + "01/2019": 1779, + "02/2019": 1792, + "03/2019": 1570, + "04/2019": 1539, + "05/2019": 986, + }, + }, + "Canton": { + "Prod": { + "01/2019": 28699, + "02/2019": 26766, + "03/2019": 22619, + "04/2019": 24090, + "05/2019": 16719, + } + }, + "BD04": { + "Integ": {}, + "PreProd": { + "10/2018": 7019, + "11/2018": 3004, + "12/2018": 2691, + "01/2019": 2901, + "02/2019": 3463, + "03/2019": 3314, + "04/2019": 3432, + "05/2019": 723, + }, + }, + "SCV18": {"Dev": {"05/2019": 9797}}, + "Crown": { + "CR Portal Dev": { + "11/2018": 208, + "12/2018": 457, + "01/2019": 671, + "02/2019": 136, + "03/2019": 1524, + "04/2019": 2077, + "05/2019": 1858, + }, + "CR Staging": { + "11/2018": 208, + "12/2018": 457, + "01/2019": 671, + "02/2019": 136, + "03/2019": 1524, + "04/2019": 2077, + "05/2019": 1858, + }, + "CR Portal Test 1": {"03/2019": 806, "04/2019": 1966, "05/2019": 2597}, + "Jewels Prod": {"03/2019": 806, "04/2019": 1966, "05/2019": 2597}, + "Jewels Dev": { + "11/2018": 145, + "12/2018": 719, + "01/2019": 1243, + "02/2019": 2214, + "03/2019": 2959, + "04/2019": 4151, + "05/2019": 4260, + }, + }, +} + + +class Reports: @classmethod def workspace_totals(cls, workspace): - return { - 'budget': 100_000_000, - 'spent': 40_000_000, - } + spent = sum( + [ + spend + for project in MONTHLY_SPEND.values() + for env in project.values() + for spend in env.values() + ] + ) + return {"budget": 500_000, "spent": spent} + @classmethod + def monthly_totals(cls, workspace): + project_totals = {} + for project, environments in MONTHLY_SPEND.items(): + project_spend = [ + (month, spend) + for env in environments.values() + for month, spend in env.items() + ] + project_totals[project] = { + month: sum([spend[1] for spend in spends]) + for month, spends in groupby(sorted(project_spend), lambda x: x[0]) + } + + monthly_spend = [ + (month, spend) + for project in project_totals.values() + for month, spend in project.items() + ] + workspace_totals = {} + for month, spends in groupby(sorted(monthly_spend), lambda m: m[0]): + workspace_totals[month] = sum([spend[1] for spend in spends]) + + return { + "environments": MONTHLY_SPEND, + "projects": project_totals, + "workspace": workspace_totals, + } diff --git a/atst/routes/workspaces.py b/atst/routes/workspaces.py index 60ab4a67..ebb9375e 100644 --- a/atst/routes/workspaces.py +++ b/atst/routes/workspaces.py @@ -76,6 +76,7 @@ def workspace_reports(workspace_id): return render_template( "workspace_reports.html", workspace_totals=Reports.workspace_totals(workspace), + monthly_totals=Reports.monthly_totals(workspace), ) diff --git a/templates/workspace_reports.html b/templates/workspace_reports.html index f5469514..f5a70877 100644 --- a/templates/workspace_reports.html +++ b/templates/workspace_reports.html @@ -94,105 +94,67 @@
Spending scope | -April 2018 | -May 2018 | -June 2018 | +March 2019 | +April 2019 | +May 2019 | + {% set workspace_totals = monthly_totals['workspace'] %} + {% set current_month = '05/2019' %} + {% set prev_month = '04/2019' %} + {% set two_months_ago = '03/2019' %} |
---|---|---|---|---|---|---|---|
Workspace Total | -$58,000 | -$60,000 | -$62,000 | +{{ workspace_totals[two_months_ago] | dollars }} | +{{ workspace_totals[prev_month] | dollars }} | +{{ workspace_totals[current_month] | dollars }} |
- |
- - | -$29,000 | -$30,000 | -$31,000 | -
- 50%
- |
- |||
{{ Icon('link') }} Production | -$14,000 | -$15,000 | -$16,000 | -- | |||
{{ Icon('link') }} Development | -$12,000 | -$13,000 | -$14,000 | -- | |||
- - | -$29,000 | -$30,000 | -$31,000 | -
- 50%
- |
- |||
{{ Icon('link') }} Production | -$14,000 | -$15,000 | -$16,000 | -- | |||
{{ Icon('link') }} Development | -$12,000 | -$13,000 | -$14,000 | -- | |||
+ + | +{{ project_totals.get(two_months_ago, 0) | dollars }} | +{{ project_totals.get(prev_month, 0) | dollars }} | +{{ project_totals.get(current_month, 0) | dollars }} | +
+ {{ (100 * (project_totals.get(current_month) / workspace_totals[current_month])) | round | int }}%
+ |
+ |||
{{ Icon('link') }} {{ env_name }} | +{{ env_totals.get(two_months_ago, 0) | dollars }} | +{{ env_totals.get(prev_month, 0) | dollars }} | +{{ env_totals.get(current_month, 0) | dollars }} | ++ |