Merge pull request #250 from dod-ccpo/mock-reporting
Add mock reporting data
This commit is contained in:
commit
d01a59fc82
198
atst/domain/reports.py
Normal file
198
atst/domain/reports.py
Normal file
@ -0,0 +1,198 @@
|
||||
from itertools import groupby
|
||||
|
||||
|
||||
MONTHLY_SPEND_AARDVARK = {
|
||||
"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,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
CUMULATIVE_BUDGET_AARDVARK = {
|
||||
"10/2018": {"spend": 9857, "cumulative": 9857},
|
||||
"11/2018": {"spend": 7881, "cumulative": 17738},
|
||||
"12/2018": {"spend": 14010, "cumulative": 31748},
|
||||
"01/2019": {"spend": 43510, "cumulative": 75259},
|
||||
"02/2019": {"spend": 41725, "cumulative": 116984},
|
||||
"03/2019": {"spend": 41328, "cumulative": 158312},
|
||||
"04/2019": {"spend": 47491, "cumulative": 205803},
|
||||
"05/2019": {"spend": 45826, "cumulative": 251629},
|
||||
"06/2019": {"projected": 296511},
|
||||
"07/2019": {"projected": 341393},
|
||||
"08/2019": {"projected": 386274},
|
||||
"09/2019": {"projected": 431156},
|
||||
}
|
||||
|
||||
MONTHLY_SPEND_BELUGA = {
|
||||
"NP02": {
|
||||
"Integ": {"02/2019": 284, "03/2019": 1210},
|
||||
"PreProd": {"02/2019": 812, "03/2019": 1389},
|
||||
"Prod": {"02/2019": 3742, "03/2019": 4716},
|
||||
},
|
||||
"FM": {"Integ": {"03/2019": 1498}, "Prod": {"03/2019": 5686}},
|
||||
}
|
||||
|
||||
CUMULATIVE_BUDGET_BELUGA = {
|
||||
"02/2019": {"spend": 4838, "cumulative": 4838},
|
||||
"03/2019": {"spend": 14500, "cumulative": 19338},
|
||||
"04/2019": {"projected": 29007},
|
||||
"05/2019": {"projected": 38676},
|
||||
"06/2019": {"projected": 48345},
|
||||
"07/2019": {"projected": 58014},
|
||||
"08/2019": {"projected": 67683},
|
||||
"09/2019": {"projected": 77352},
|
||||
}
|
||||
|
||||
|
||||
class Reports:
|
||||
@classmethod
|
||||
def workspace_totals(cls, alternate):
|
||||
data = MONTHLY_SPEND_BELUGA if alternate else MONTHLY_SPEND_AARDVARK
|
||||
spent = sum(
|
||||
[
|
||||
spend
|
||||
for project in data.values()
|
||||
for env in project.values()
|
||||
for spend in env.values()
|
||||
]
|
||||
)
|
||||
budget = 70_000 if alternate else 500_000
|
||||
return {"budget": budget, "spent": spent}
|
||||
|
||||
@classmethod
|
||||
def monthly_totals(cls, alternate):
|
||||
data = MONTHLY_SPEND_BELUGA if alternate else MONTHLY_SPEND_AARDVARK
|
||||
project_totals = {}
|
||||
for project, environments in data.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": data,
|
||||
"projects": project_totals,
|
||||
"workspace": workspace_totals,
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
from datetime import date, timedelta
|
||||
|
||||
from flask import (
|
||||
Blueprint,
|
||||
render_template,
|
||||
@ -8,9 +10,10 @@ from flask import (
|
||||
)
|
||||
|
||||
from atst.domain.exceptions import UnauthorizedError
|
||||
from atst.domain.projects import Projects
|
||||
from atst.domain.reports import Reports
|
||||
from atst.domain.workspaces import Workspaces
|
||||
from atst.domain.workspace_users import WorkspaceUsers
|
||||
from atst.domain.projects import Projects
|
||||
from atst.forms.new_project import NewProjectForm
|
||||
from atst.forms.new_member import NewMemberForm
|
||||
from atst.forms.edit_member import EditMemberForm
|
||||
@ -66,7 +69,30 @@ def workspace_members(workspace_id):
|
||||
|
||||
@bp.route("/workspaces/<workspace_id>/reports")
|
||||
def workspace_reports(workspace_id):
|
||||
return render_template("workspace_reports.html", workspace_id=workspace_id)
|
||||
workspace = Workspaces.get(g.current_user, workspace_id)
|
||||
Authorization.check_workspace_permission(
|
||||
g.current_user,
|
||||
workspace,
|
||||
Permissions.VIEW_USAGE_DOLLARS,
|
||||
"view workspace reports",
|
||||
)
|
||||
|
||||
alternate_reports = http_request.args.get("alternate")
|
||||
today = date.today()
|
||||
month = http_request.args.get("month", today.month)
|
||||
year = http_request.args.get("year", today.year)
|
||||
current_month = date(int(year), int(month), 15)
|
||||
prev_month = current_month - timedelta(days=28)
|
||||
two_months_ago = prev_month - timedelta(days=28)
|
||||
|
||||
return render_template(
|
||||
"workspace_reports.html",
|
||||
workspace_totals=Reports.workspace_totals(alternate_reports),
|
||||
monthly_totals=Reports.monthly_totals(alternate_reports),
|
||||
current_month=current_month,
|
||||
prev_month=prev_month,
|
||||
two_months_ago=two_months_ago,
|
||||
)
|
||||
|
||||
|
||||
@bp.route("/workspaces/<workspace_id>/projects/new")
|
||||
|
@ -19,24 +19,27 @@
|
||||
<div class='row'>
|
||||
<h2 class='spend-summary__heading col'>Workspace Total Spend</h2>
|
||||
<dl class='spend-summary__budget'>
|
||||
{% set budget = workspace_totals['budget'] %}
|
||||
{% set spent = workspace_totals['spent'] %}
|
||||
{% set remaining = budget - spent %}
|
||||
<div>
|
||||
<dt>Budget </dt>
|
||||
<dd>$100,000,000</dd>
|
||||
<dd>{{ budget | dollars }}</dd>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<dt>Remaining</dt>
|
||||
<dd>$60,000,000</dd>
|
||||
<dd>{{ remaining | dollars }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<meter value='40000000' min='0' max='100000000' title='$40,000,000 Total spend to date'></meter>
|
||||
<meter value='{{ spent }}' min='0' max='{{ budget }}' title='{{ spent | dollars }} Total spend to date'></meter>
|
||||
|
||||
<dl class='spend-summary__spent'>
|
||||
<dt>Total spend to date</dt>
|
||||
<dd>$40,000,00</dd>
|
||||
<dd>{{ spent | dollars }}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
@ -67,7 +70,7 @@
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
<a href='/' class='icon-link'>
|
||||
<a href='#' class='icon-link'>
|
||||
Manage Task Order
|
||||
</a>
|
||||
</div>
|
||||
@ -86,110 +89,73 @@
|
||||
|
||||
</div>
|
||||
|
||||
{% set workspace_totals = monthly_totals['workspace'] %}
|
||||
{% set current_month_index = current_month.strftime('%m/%Y') %}
|
||||
{% set prev_month_index = prev_month.strftime('%m/%Y') %}
|
||||
{% set two_months_ago_index = two_months_ago.strftime('%m/%Y') %}
|
||||
|
||||
<div class='spend-table responsive-table-wrapper'>
|
||||
<div class='spend-table__header'>
|
||||
<h2 class='spend-table__title'>Total spend per month</h2>
|
||||
|
||||
<select name='month' id='month' class='spend-table__month-select'>
|
||||
<option value='06/2018'>June 2018</option>
|
||||
<option value='03/2019'>{{ current_month.strftime('%B %Y') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<th scope='col'><span class='usa-sr-only'>Spending scope</span></th>
|
||||
<th scope='col' class='table-cell--align-right previous-month'>April 2018</th>
|
||||
<th scope='col' class='table-cell--align-right previous-month'>May 2018</th>
|
||||
<th scope='col' class='table-cell--align-right current-month'>June 2018</th>
|
||||
<th scope='col' class='table-cell--align-right previous-month'>{{ two_months_ago.strftime('%B %Y') }}</th>
|
||||
<th scope='col' class='table-cell--align-right previous-month'>{{ prev_month.strftime('%B %Y') }}</th>
|
||||
<th scope='col' class='table-cell--align-right current-month'>{{ current_month.strftime('%B %Y') }}</th>
|
||||
<td class='current-month'></td>
|
||||
</thead>
|
||||
|
||||
<tbody class='spend-table__workspace'>
|
||||
<tr>
|
||||
<th scope='row'>Workspace Total</th>
|
||||
<td class='table-cell--align-right previous-month'>$58,000</td>
|
||||
<td class='table-cell--align-right previous-month'>$60,000</td>
|
||||
<td class='table-cell--align-right current-month'>$62,000</td>
|
||||
<td class='table-cell--align-right previous-month'>{{ workspace_totals.get(two_months_ago_index, 0) | dollars }}</td>
|
||||
<td class='table-cell--align-right previous-month'>{{ workspace_totals.get(prev_month_index, 0) | dollars }}</td>
|
||||
<td class='table-cell--align-right current-month'>{{ workspace_totals.get(current_month_index, 0) | dollars }}</td>
|
||||
<td class='table-cell--expand current-month meter-cell'>
|
||||
<meter value='62000' min='0' max='62000'></meter>
|
||||
<meter value='{{ workspace_totals.get(current_month_index, 0) }}' min='0' max='{{ workspace_totals.get(current_month_index, 0) }}'></meter>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
<tbody is='toggler' class='spend-table__project'>
|
||||
<template slot-scope='{ isVisible, toggle }'>
|
||||
<tr>
|
||||
<th scope='rowgroup'>
|
||||
<button v-on:click='toggle' class='icon-link icon-link--large spend-table__project__toggler'>
|
||||
<template v-if='isVisible'>{{ Icon('caret_down') }}</template>
|
||||
<template v-else>{{ Icon('caret_right') }}</template>
|
||||
Code.mil
|
||||
</button>
|
||||
</th>
|
||||
<td class='table-cell--align-right previous-month'>$29,000</td>
|
||||
<td class='table-cell--align-right previous-month'>$30,000</td>
|
||||
<td class='table-cell--align-right current-month'>$31,000</td>
|
||||
<td class='table-cell--expand current-month meter-cell'>
|
||||
<span class='spend-table__meter-value'>50%</span>
|
||||
<meter value='31000' min='0' max='62000'></meter>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr v-show='isVisible'>
|
||||
<th scope='rowgroup'><a href='/' class='icon-link spend-table__project__env'>{{ Icon('link') }} Production</a></th>
|
||||
<td class='table-cell--align-right previous-month'>$14,000</td>
|
||||
<td class='table-cell--align-right previous-month'>$15,000</td>
|
||||
<td class='table-cell--align-right current-month'>$16,000</td>
|
||||
<td class='table-cell--expand current-month'></td>
|
||||
</tr>
|
||||
|
||||
<tr v-show='isVisible'>
|
||||
<th scope='rowgroup'><a href='/' class='icon-link spend-table__project__env'>{{ Icon('link') }} Development</a></th>
|
||||
<td class='table-cell--align-right previous-month'>$12,000</td>
|
||||
<td class='table-cell--align-right previous-month'>$13,000</td>
|
||||
<td class='table-cell--align-right current-month'>$14,000</td>
|
||||
<td class='table-cell--expand current-month'></td>
|
||||
</tr>
|
||||
</template>
|
||||
</tbody>
|
||||
|
||||
<tbody is='toggler' class='spend-table__project'>
|
||||
<template slot-scope='{ isVisible, toggle }'>
|
||||
<tr>
|
||||
<th scope='rowgroup'>
|
||||
<button v-on:click='toggle' class='icon-link icon-link--large spend-table__project__toggler'>
|
||||
<template v-if='isVisible'>{{ Icon('caret_down') }}</template>
|
||||
<template v-else>{{ Icon('caret_right') }}</template>
|
||||
Digital Dojo
|
||||
</button>
|
||||
</th>
|
||||
<td class='table-cell--align-right previous-month'>$29,000</td>
|
||||
<td class='table-cell--align-right previous-month'>$30,000</td>
|
||||
<td class='table-cell--align-right current-month'>$31,000</td>
|
||||
<td class='table-cell--expand current-month meter-cell'>
|
||||
<span class='spend-table__meter-value'>50%</span>
|
||||
<meter value='31000' min='0' max='62000'></meter>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr v-show='isVisible'>
|
||||
<th scope='rowgroup'><a href='/' class='icon-link spend-table__project__env'>{{ Icon('link') }} Production</a></th>
|
||||
<td class='table-cell--align-right previous-month'>$14,000</td>
|
||||
<td class='table-cell--align-right previous-month'>$15,000</td>
|
||||
<td class='table-cell--align-right current-month'>$16,000</td>
|
||||
<td class='table-cell--expand current-month'></td>
|
||||
</tr>
|
||||
|
||||
<tr v-show='isVisible'>
|
||||
<th scope='rowgroup'><a href='/' class='icon-link spend-table__project__env'>{{ Icon('link') }} Development</a></th>
|
||||
<td class='table-cell--align-right previous-month'>$12,000</td>
|
||||
<td class='table-cell--align-right previous-month'>$13,000</td>
|
||||
<td class='table-cell--align-right current-month'>$14,000</td>
|
||||
<td class='table-cell--expand current-month'></td>
|
||||
</tr>
|
||||
</template>
|
||||
</tbody>
|
||||
{% for project_name, project_totals in monthly_totals['projects'].items() %}
|
||||
<tbody is='toggler' class='spend-table__project'>
|
||||
<template slot-scope='{ isVisible, toggle }'>
|
||||
<tr>
|
||||
<th scope='rowgroup'>
|
||||
<button v-on:click='toggle' class='icon-link icon-link--large spend-table__project__toggler'>
|
||||
<template v-if='isVisible'>{{ Icon('caret_down') }}</template>
|
||||
<template v-else>{{ Icon('caret_right') }}</template>
|
||||
{{ project_name }}
|
||||
</button>
|
||||
</th>
|
||||
<td class='table-cell--align-right previous-month'>{{ project_totals.get(two_months_ago_index, 0) | dollars }}</td>
|
||||
<td class='table-cell--align-right previous-month'>{{ project_totals.get(prev_month_index, 0) | dollars }}</td>
|
||||
<td class='table-cell--align-right current-month'>{{ project_totals.get(current_month_index, 0) | dollars }}</td>
|
||||
<td class='table-cell--expand current-month meter-cell'>
|
||||
<span class='spend-table__meter-value'>{{ (100 * (project_totals.get(current_month_index, 0) / workspace_totals.get(current_month_index, 1))) | round | int }}%</span>
|
||||
<meter value='{{ project_totals.get(current_month_index, 0) }}' min='0' max='{{ workspace_totals.get(current_month_index, 0) }}'></meter>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{% for env_name, env_totals in monthly_totals['environments'][project_name].items() %}
|
||||
<tr v-show='isVisible'>
|
||||
<th scope='rowgroup'><a href='#' class='icon-link spend-table__project__env'>{{ Icon('link') }} {{ env_name }}</a></th>
|
||||
<td class='table-cell--align-right previous-month'>{{ env_totals.get(two_months_ago_index, 0) | dollars }}</td>
|
||||
<td class='table-cell--align-right previous-month'>{{ env_totals.get(prev_month_index, 0) | dollars }}</td>
|
||||
<td class='table-cell--align-right current-month'>{{ env_totals.get(current_month_index, 0) | dollars }}</td>
|
||||
<td class='table-cell--expand current-month'></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</template>
|
||||
</tbody>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user