Skip to content

Commit

Permalink
Add RSS feed for reports
Browse files Browse the repository at this point in the history
  • Loading branch information
tobami committed Jan 17, 2011
1 parent 10ed8d2 commit e052778
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 44 deletions.
12 changes: 12 additions & 0 deletions speedcenter/codespeed/feeds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.contrib.syndication.feeds import Feed
from codespeed.models import Report
from codespeed import settings


class LatestEntries(Feed):
title = settings.website_name
link = "/changes/"
description = "Last benchmark runs"

def items(self):
return Report.objects.order_by('-revision')[:10]
76 changes: 41 additions & 35 deletions speedcenter/codespeed/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Revision(models.Model):
date = models.DateTimeField(null=True)
message = models.TextField(blank=True)
author = models.CharField(max_length=30, blank=True)

def get_short_commitid(self):
return self.commitid[:10]

Expand Down Expand Up @@ -100,7 +100,7 @@ class Report(models.Model):
revision = models.ForeignKey(Revision)
environment = models.ForeignKey(Environment)
executable = models.ForeignKey(Executable)
summary = models.CharField(max_length=30, default="none")
summary = models.CharField(max_length=30, blank=True)
colorcode = models.CharField(max_length=10, default="none")
_tablecache = models.TextField(blank=True)

Expand Down Expand Up @@ -168,41 +168,43 @@ def save(self, *args, **kwargs):
max_trend_ben = row['bench_name']
max_trend_color = color
# Reinitialize
self.summary = "none"
self.summary = ""
self.colorcode = "none"

if abs(max_trend) > trend_threshold:

# Save summary in order of priority
# Average change
if average_change_color != "none":
#Substitute plus/minus with up/down
direction = max_trend >= 0 and "+" or ""
self.summary = "%s trend %s%.1f%%" % (
max_trend_ben, direction, round(max_trend, 1))
self.colorcode = max_trend_color
if abs(average_trend) > trend_threshold:
if average_trend_color == "red" or self.colorcode != "red":
#Substitute plus/minus with up/down
direction = average_trend >= 0 and "+" or ""
self.summary = "Average %s trend %s%.1f%%" % (
average_trend_units.lower(), direction, round(average_trend, 1))
self.colorcode = average_trend_color
if abs(max_change) > change_threshold:
if max_change_color == "red" or self.colorcode != "red":
#Substitute plus/minus with up/down
direction = max_change >= 0 and "+" or ""
self.summary = "%s %s%.1f%%" % (
max_change_ben, direction, round(max_change, 1))
self.colorcode = max_change_color
if abs(average_change) > change_threshold:
if average_change_color == "red" or self.colorcode != "red":
#Substitute plus/minus with up/down
direction = average_change >= 0 and "+" or ""
self.summary = "Average %s %s%.1f%%" % (
average_change_units.lower(),
direction,
round(abs(average_change), 1))
self.colorcode = average_change_color
if "trend" in self.summary and self.colorcode == "red":
# trend break is only a warning
self.colorcode = "yellow"
direction = average_change >= 0 and "+" or "-"
self.summary = "Average %s %s%.1f%%" % (
average_change_units.lower(),
direction,
round(abs(average_change), 1))
self.colorcode = average_change_color
# Single benchmark change
if max_change_color != "none" and self.colorcode != "red":
#Substitute plus/minus with up/down
direction = max_change >= 0 and "+" or "-"
self.summary = "%s %s%.1f%%" % (
max_change_ben, direction, round(abs(max_change), 1))
self.colorcode = max_change_color

# Average trend
if average_trend_color != "none" and self.colorcode == "none":
#Substitute plus/minus with up/down
direction = average_trend >= 0 and "+" or ""
self.summary = "Average %s trend %s%.1f%%" % (
average_trend_units.lower(), direction, round(average_trend, 1))
self.colorcode = average_trend_color == "red"\
and "yellow" or average_trend_color
# Single benchmark trend
if max_trend_color != "none" and self.colorcode != "red":
if self.colorcode == "none" or (self.colorcode == "green" and "trend" not in self.summary):
direction = max_trend >= 0 and "+" or ""
self.summary = "%s trend %s%.1f%%" % (
max_trend_ben, direction, round(max_trend, 1))
self.colorcode = max_trend_color == "red"\
and "yellow" or max_trend_color

super(Report, self).save(*args, **kwargs)

Expand Down Expand Up @@ -375,6 +377,10 @@ def get_changes_table(self, trend_depth=10, force_save=False):
self._save_tablecache(tablelist)
return tablelist

def get_absolute_url(self):
return "/changes/?rev=%s&exe=%s&env=%s" % (
self.revision.commitid, self.executable.id, self.environment.name)

def _save_tablecache(self, data):
self._tablecache = json.dumps(data)

Expand Down
4 changes: 3 additions & 1 deletion speedcenter/codespeed/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
## General default options ##
website_name = "MySpeedSite"

def_environment = None #Name of the environment which should be selected as default


Expand All @@ -15,7 +17,7 @@

# Threshold that determines when a performance change
# over a number of revisions is significant
trend_threshold = 4.0
trend_threshold = 5.0

# Changes view options ##
def_executable = None # Executable that should be chosen as default in the changes view
Expand Down
10 changes: 8 additions & 2 deletions speedcenter/codespeed/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template, redirect_to
from django.views.generic.simple import direct_to_template
from codespeed.feeds import LatestEntries

feeds = { 'latest': LatestEntries }


urlpatterns = patterns('',
(r'^$', direct_to_template, {'template': 'home.html'}),
(r'^about/$', direct_to_template, {'template': 'about.html'}),
# RSS for reports
(r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}),
)

urlpatterns += patterns('codespeed.views',
Expand Down
2 changes: 1 addition & 1 deletion speedcenter/codespeed/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def reports(request):
if request.method != 'GET': return HttpResponseNotAllowed('GET')

return render_to_response('codespeed/reports.html', {
'reports': Report.objects.all().order_by('-revision')[:10],
'reports': Report.objects.order_by('-revision')[:10],
})

def displaylogs(request):
Expand Down
11 changes: 8 additions & 3 deletions speedcenter/media/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ div#presentation div#comparison p {
background: url(/media/images/comparison.png) no-repeat;
}

div#presentation div#reports { margin-top: 0.8em; }

/* Navigation elements */
div#sidebar {
width: 13.7em;
Expand Down Expand Up @@ -275,6 +277,9 @@ table.tablesorter, table.info, table.revision, table.reports {
border-width: 2px;
}*/
table.reports caption { font-size: 110%; }
table.reports caption a { color: black; }
table.reports caption a img {
border: 0; vertical-align: middle; height: 14px; margin-bottom: 1px; }
table.reports td { padding: 0.4em; }
table.reports td span { opacity: 0.4; }

Expand Down Expand Up @@ -327,11 +332,11 @@ table.tablesorter thead tr .headerSortDown, table.tablesorter thead tr .headerSo

table.tablesorter tbody td.text {text-align: left; width: 8.5em; }

table.tablesorter tbody tr td.status-red { background-color: #FF5640; }
table.tablesorter tbody tr td.status-red, td.status-red { background-color: #FF5640; }
.reports tr.status-red td.summary { color: #FF5640; font-weight: bold; }
table.tablesorter tbody tr td.status-green { background-color: #9FD54D; }
table.tablesorter tbody tr td.status-green, td.status-green { background-color: #9FD54D; }
tr.status-green td.summary { color: #9FD54D; font-weight: bold; }
table.tablesorter tbody tr td.status-yellow { background-color: #FFD843; }
table.tablesorter tbody tr td.status-yellow, td.status-yellow { background-color: #FFD843; }
tr.status-yellow td.summary { color: #FFD843; font-weight: bold; }

table.tablesorter tbody tr.highlight td, tr.highlight td {
Expand Down
Binary file added speedcenter/media/images/rss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions speedcenter/templates/codespeed/reports.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{% if reports|length %}
<table class="reports">
<caption>Latest runs</caption>
<caption>Latest runs <a href="/feeds/latest/"><img src="media/images/rss.png" /></a></caption>
<tbody>
{% for report in reports %} <tr class="status-{{ report.colorcode }}">
<td><label title="lessisbetter" style="display:none;">rev={{ report.revision.commitid }}&exe= {{ report.executable.id }}&env={{ report.environment.name }}</label>{{ report.revision }}</td><td>{{ report.executable }}@{{ report.environment}}</td>
<td class="summary">{% ifequal report.summary "none" %}<span class="nochanges">no significant changes</span>{% else %}{{ report.summary }}{% endifequal %}</td>
<td class="summary">{% ifequal report.summary "" %}<span class="nochanges">no significant changes</span>{% else %}{{ report.summary }}{% endifequal %}</td>
</tr>{% endfor %}
</tbody>
</table>
Expand Down
8 changes: 8 additions & 0 deletions speedcenter/templates/feeds/latest_description.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% ifequal obj.colorcode "red" %}Performance regressed: {% else %}
{% ifequal obj.colorcode "green" %}Performance improved: {% else %}
{% ifequal obj.colorcode "yellow" %}Trend regressed: {% else %}
No significant changes.
{% endifequal %}
{% endifequal %}
{% endifequal %}
{{ obj.summary }}
1 change: 1 addition & 0 deletions speedcenter/templates/feeds/latest_title.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ obj.revision }} {{ obj.executable }}@{{ obj.environment}}

0 comments on commit e052778

Please sign in to comment.