Add mock monthly reporting data

This commit is contained in:
Patrick Smith 2018-09-05 15:59:57 -04:00
parent f33a7b4a9f
commit a9d705daac
3 changed files with 200 additions and 86 deletions

View File

@ -1,9 +1,160 @@
class Reports: from itertools import groupby
@classmethod
def workspace_totals(cls, workspace): MONTHLY_SPEND = {
return { "LC04": {
'budget': 100_000_000, "Integ": {
'spent': 40_000_000, "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):
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,
}

View File

@ -76,6 +76,7 @@ def workspace_reports(workspace_id):
return render_template( return render_template(
"workspace_reports.html", "workspace_reports.html",
workspace_totals=Reports.workspace_totals(workspace), workspace_totals=Reports.workspace_totals(workspace),
monthly_totals=Reports.monthly_totals(workspace),
) )

View File

@ -94,31 +94,36 @@
<h2 class='spend-table__title'>Total spend per month</h2> <h2 class='spend-table__title'>Total spend per month</h2>
<select name='month' id='month' class='spend-table__month-select'> <select name='month' id='month' class='spend-table__month-select'>
<option value='06/2018'>June 2018</option> <option value='05/2019'>May 2019</option>
</select> </select>
</div> </div>
<table> <table>
<thead> <thead>
<th scope='col'><span class='usa-sr-only'>Spending scope</span></th> <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'>March 2019</th>
<th scope='col' class='table-cell--align-right previous-month'>May 2018</th> <th scope='col' class='table-cell--align-right previous-month'>April 2019</th>
<th scope='col' class='table-cell--align-right current-month'>June 2018</th> <th scope='col' class='table-cell--align-right current-month'>May 2019</th>
<td class='current-month'></td> <td class='current-month'></td>
</thead> </thead>
{% set workspace_totals = monthly_totals['workspace'] %}
{% set current_month = '05/2019' %}
{% set prev_month = '04/2019' %}
{% set two_months_ago = '03/2019' %}
<tbody class='spend-table__workspace'> <tbody class='spend-table__workspace'>
<tr> <tr>
<th scope='row'>Workspace Total</th> <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'>{{ workspace_totals[two_months_ago] | dollars }}</td>
<td class='table-cell--align-right previous-month'>$60,000</td> <td class='table-cell--align-right previous-month'>{{ workspace_totals[prev_month] | dollars }}</td>
<td class='table-cell--align-right current-month'>$62,000</td> <td class='table-cell--align-right current-month'>{{ workspace_totals[current_month] | dollars }}</td>
<td class='table-cell--expand current-month meter-cell'> <td class='table-cell--expand current-month meter-cell'>
<meter value='62000' min='0' max='62000'></meter> <meter value='{{ workspace_totals[current_month] }}' min='0' max='{{ workspace_totals[current_month] }}'></meter>
</td> </td>
</tr> </tr>
</tbody> </tbody>
{% for project_name, project_totals in monthly_totals['projects'].items() %}
<tbody is='toggler' class='spend-table__project'> <tbody is='toggler' class='spend-table__project'>
<template slot-scope='{ isVisible, toggle }'> <template slot-scope='{ isVisible, toggle }'>
<tr> <tr>
@ -126,73 +131,30 @@
<button v-on:click='toggle' class='icon-link icon-link--large spend-table__project__toggler'> <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-if='isVisible'>{{ Icon('caret_down') }}</template>
<template v-else>{{ Icon('caret_right') }}</template> <template v-else>{{ Icon('caret_right') }}</template>
Code.mil {{ project_name }}
</button> </button>
</th> </th>
<td class='table-cell--align-right previous-month'>$29,000</td> <td class='table-cell--align-right previous-month'>{{ project_totals.get(two_months_ago, 0) | dollars }}</td>
<td class='table-cell--align-right previous-month'>$30,000</td> <td class='table-cell--align-right previous-month'>{{ project_totals.get(prev_month, 0) | dollars }}</td>
<td class='table-cell--align-right current-month'>$31,000</td> <td class='table-cell--align-right current-month'>{{ project_totals.get(current_month, 0) | dollars }}</td>
<td class='table-cell--expand current-month meter-cell'> <td class='table-cell--expand current-month meter-cell'>
<span class='spend-table__meter-value'>50%</span> <span class='spend-table__meter-value'>{{ (100 * (project_totals.get(current_month) / workspace_totals[current_month])) | round | int }}%</span>
<meter value='31000' min='0' max='62000'></meter> <meter value='{{ project_totals[current_month] }}' min='0' max='{{ workspace_totals[current_month] }}'></meter>
</td> </td>
</tr> </tr>
{% for env_name, env_totals in monthly_totals['environments'][project_name].items() %}
<tr v-show='isVisible'> <tr v-show='isVisible'>
<th scope='rowgroup'><a href='/' class='icon-link spend-table__project__env'>{{ Icon('link') }} Production</a></th> <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'>$14,000</td> <td class='table-cell--align-right previous-month'>{{ env_totals.get(two_months_ago, 0) | dollars }}</td>
<td class='table-cell--align-right previous-month'>$15,000</td> <td class='table-cell--align-right previous-month'>{{ env_totals.get(prev_month, 0) | dollars }}</td>
<td class='table-cell--align-right current-month'>$16,000</td> <td class='table-cell--align-right current-month'>{{ env_totals.get(current_month, 0) | dollars }}</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> <td class='table-cell--expand current-month'></td>
</tr> </tr>
{% endfor %}
</template> </template>
</tbody> </tbody>
{% endfor %}
<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>
</table> </table>
</div> </div>