Skip to content

Commit

Permalink
Merge ed280d9 into 05ee6fc
Browse files Browse the repository at this point in the history
  • Loading branch information
cmheisel committed Dec 21, 2016
2 parents 05ee6fc + ed280d9 commit 6873682
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ clean: clean_pycs
rm -rf container/*.db

docs: reqs
cd docs && make html
./venv/bin/mkdocs build -s

up:
docker-compose rm -f --all
Expand All @@ -50,7 +50,7 @@ release: test_docker clean publish_docs
docker push $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_VERSION)
docker push $(DOCKER_IMAGE_NAME):latest

publish_docs:
publish_docs: docs
./venv/bin/mkdocs gh-deploy

.PHONY: test clean_pycs clean_db clean docs up clean_docker test_docker release
84 changes: 56 additions & 28 deletions dashboard/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging

from dateutil.relativedelta import relativedelta
from dateutil.parser import parse

from django.conf import settings
from django.core.cache import cache
Expand All @@ -12,6 +13,56 @@
from .services import sheets, jira, summaries, predictions


def _add_current_jira_summary(xtras, jira_filter_id, logger):
summary_data = jira.summarize_query(jira_filter_id)
logger.debug("Filter {} summarized".format(jira_filter_id))
if summary_data.get('errors', []):
xtras['jira_summary_errors'] = summary_data['errors']
logger.warn("Filter {} summary error".format(summary_data['errors']))
elif summary_data:
p = summaries.create(
filter_id=int(xtras['_jira_filter']),
incomplete=summary_data['incomplete'],
complete=summary_data['complete'],
total=summary_data['total'],
created_on=datetime.date.today(),
)
summaries.store(p)
xtras['jira_summary'] = p
logger.debug("Filter {} summary stored".format(p.filter_id))
return xtras


def _add_week_ago_summary(xtras, current_summary, logger):
week_ago = current_summary.created_on - relativedelta(days=7)
week_ago_summary = summaries.for_date(filter_id=current_summary.filter_id, date=week_ago)
xtras['week_ago_summary'] = week_ago_summary
logger.info("Filter {} week_ago summary retrieved".format(current_summary.filter_id))
return xtras


def _add_forecasts(xtras, summary, logger):
a_month_ago = summary.created_on - relativedelta(days=30)
try:
forecasts = predictions.for_project(filter_id=summary.filter_id, backlog_size=summary.incomplete, start_date=a_month_ago)
except ValueError as e:
forecasts = []
logger.warn("Filter {} predictions error: {}".format(summary.filter_id, str(e)))

xtras['predictions'] = [summary.created_on + relativedelta(days=int(f)) for f in forecasts]
logger.debug("Filter {} predictions created".format(summary.filter_id))
return xtras


def _add_target_date(xtras, target_date_string):
xtras['target_date'] = ""
try:
xtras['target_date'] = parse(target_date_string)
except (ValueError, AttributeError):
pass
return xtras


@job
def generate_dashboard():
logger = logging.getLogger("dashboard.jobs.generate_dashboard")
Expand All @@ -20,35 +71,12 @@ def generate_dashboard():
data = sheets.load_sheet(sheet_id)
logger.debug("Sheet loaded")
for row in data:
row.xtras = _add_target_date(row.xtras, row.xtras.get('_target_date'))
if row.xtras.get('_jira_filter'):
summary_data = jira.summarize_query(row.xtras['_jira_filter'])
logger.debug("Filter {} summarized".format(row.xtras['_jira_filter']))
if summary_data.get('errors', []):
row.xtras['jira_summary_errors'] = summary_data['errors']
logger.warn("Filter {} summary error".format(summary_data['errors']))
elif summary_data:
p = summaries.create(
filter_id=int(row.xtras['_jira_filter']),
incomplete=summary_data['incomplete'],
complete=summary_data['complete'],
total=summary_data['total'],
created_on=datetime.date.today(),
)
summaries.store(p)
row.xtras['jira_summary'] = p
logger.debug("Filter {} summary stored".format(p.filter_id))

week_ago = p.created_on - relativedelta(days=7)
week_ago_summary = summaries.for_date(filter_id=p.filter_id, date=week_ago)
row.xtras['week_ago_summary'] = week_ago_summary
logger.debug("Filter {} week_ago summary retrieved".format(p.filter_id))
try:
two_weeks_ago = p.created_on - relativedelta(days=14)
row.xtras['predictions'] = predictions.for_project(filter_id=p.filter_id, backlog_size=p.incomplete, start_date=two_weeks_ago)
except ValueError as e:
logger.warn("Filter {} predictions error: {}".format(p.filter_id, str(e)))
row.xtras['predictions'] = []
logger.debug("Filter {} predictions created".format(p.filter_id))
row.xtras = _add_current_jira_summary(row.xtras, row.xtras['_jira_filter'], logger)
if row.xtras.get('jira_summary'):
row.xtras = _add_week_ago_summary(row.xtras, row.xtras['jira_summary'], logger)
row.xtras = _add_forecasts(row.xtras, row.xtras['jira_summary'], logger)
cache.set('dashboard_data', data, None)
cache.set('dashboard_data_updated', datetime.datetime.now(get_default_timezone()), None)
logger.info("End")
Expand Down
30 changes: 22 additions & 8 deletions dashboard/templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
{% for key in data.0.keys %}
<th rowspan="2">{{ key }}</th>
{% endfor %}
<th data-orderable="false" data-search="false" rowspan="2">JIRA</th>
<th data-orderable="false" data-search="false" rowspan="2">Forecast</th>
<th data-orderable="true" data-search="false" rowspan="2">Target date</th>
<th data-orderable="true" data-search="false" rowspan="2">Forecast<sup>1</sup></th>
<th data-orderable="false" data-search="false" colspan="2">Today</th>
<th data-orderable="false" data-search="false" colspan="2">Last week</th>
<th data-orderable="false" data-search="false" rowspan="2">Filter</th>
</tr>
<tr>
<th>Complete</th>
Expand All @@ -29,20 +30,27 @@
</tr>

</thead>
<tfoot>
<tr>
<td colspan="{{ data.0.keys|length|add:"6" }}">
<sup>1</sup><strong>95%</strong> of 10,000 simulations <strong>completed this fast or faster</strong> based on up to the past <strong>30 days</strong> performance with the current number of tickets remaining.
</td>
</tr>
</tfoot>
<tbody>
{% for row in data %}
<tr>
{% for value in row.values %}
<td>{{ value }}</td>
{% endfor %}
<td>
{% if row.xtras.jira_summary %}
<a href="{{ JIRA_URL }}/secure/IssueNavigator.jspa?mode=hide&amp;requestId={{ row.xtras.jira_summary.filter_id }}" title="View JIRA filter"><span class="glyphicon glyphicon-filter"></span></a>
<td data-order="{{ row.xtras.target_date|date:"Y-m-d"}}">
{% if row.xtras.target_date %}
{{ row.xtras.target_date|date:"n/j" }}
{% endif %}
</td>
<td>
{% if row.xtras.jira_summary %}
<a href="{% url 'forecast' row.xtras.jira_summary.filter_id %}" title="View forecast"><span class="glyphicon glyphicon-calendar"></span></a>
<td data-order="{{ row.xtras.predictions.2|week_ending|date:"Y-m-d"}}">
{% if row.xtras.predictions %}
<a href="{% url 'forecast' row.xtras.jira_summary.filter_id %}" title="View forecast"><span class="glyphicon glyphicon-calendar"></span></a> {{ row.xtras.predictions.2|week_ending|date:"n/j" }}
{% endif %}
</td>
{% if row.xtras.jira_summary_errors %}
Expand All @@ -63,6 +71,12 @@
{% with current=row.xtras.week_ago_summary previous=None %}
{% progress_report current previous %}
{% endwith %}

<td>
{% if row.xtras.jira_summary %}
<a href="{{ JIRA_URL }}/secure/IssueNavigator.jspa?mode=hide&amp;requestId={{ row.xtras.jira_summary.filter_id }}" title="View JIRA filter"><span class="glyphicon glyphicon-filter"></span></a>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
Expand Down

0 comments on commit 6873682

Please sign in to comment.