Skip to content

Commit 06910be

Browse files
Keep each site's comparison and timeline defaults after the merge
1 parent 03f3b2c commit 06910be

9 files changed

Lines changed: 104 additions & 14 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ The main customization for the homepage is to display either the reports
219219
* `NORMALIZATION`: Defines whether normalization should be enabled as default
220220
in the Comparison view.
221221
* `CHART_ORIENTATION`: horizontal or vertical
222+
* `COMP_ENVIRONMENTS_DEFAULT`: `all` (the default) checks every environment;
223+
`default` checks only `DEF_ENVIRONMENT`, or the first environment.
222224
* `COMP_EXECUTABLES`: per default all executables will be checked. When there
223225
are a large number of tags or executables, it is better to only select a few
224226
so that the plots are not too cluttered.

‎codespeed/settings.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
# undeseriable.
5151

5252
TIMELINE_GRID_PAGING = 4 # Number of benchmarks to be send in one grid request
53+
54+
TIMELINE_GRID_REVISIONS = None # Number of revisions plotted per benchmark in the
55+
# timeline grid. None keeps the count selected in
56+
# the "Show the last" dropdown.
5357
# May be adjusted to improve the performance of the timeline grid view.
5458
# If a large number of benchmarks is in the system,
5559
# and the database is not fast, it can take a long time
@@ -69,6 +73,10 @@
6973
CHART_ORIENTATION = 'vertical' # 'vertical' or 'horizontal can be chosen as
7074
# default chart orientation
7175

76+
COMP_ENVIRONMENTS_DEFAULT = 'all' # Environments checked by default on the comparison
77+
# page: 'all', or 'default' for DEF_ENVIRONMENT only
78+
# (falling back to the first environment)
79+
7280
COMP_EXECUTABLES = None # Which executable + revision should be checked as default
7381
# Given as a list of tuples containing the
7482
# name of an executable + commitid of a revision

‎codespeed/static/js/comparison.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,10 @@ function init(defaults) {
482482
updateBaselineDropdown();
483483
refreshContent();
484484
});
485+
$("#environment .checkall, #environment .uncheckall").click(function() {
486+
updateBaselineDropdown();
487+
refreshContent();
488+
});
485489

486490
$.ajaxSetup ({
487491
cache: false

‎codespeed/static/js/timeline.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,10 @@ function render(data) {
554554
config.nextBenchmarks = data.nextBenchmarks;
555555
$.getJSON("json/", config, render);
556556
}
557-
$("#revisions").val(15).attr("disabled", true);
557+
if (defaults.grid_revisions) {
558+
$("#revisions").val(defaults.grid_revisions);
559+
}
560+
$("#revisions").attr("disabled", true);
558561
$("#equidistant").attr("disabled", true);
559562
for (var i = 0; i < data.timelines.length; i++) {
560563
var tl = data.timelines[i];

‎codespeed/templates/codespeed/comparison.html‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515

1616
{% block body %}
1717
<div id="sidebar">
18-
<div class="sidebox">
18+
<div id="environment" class="sidebox">
1919
<div class="boxhead"><h2>Environments</h2></div>
2020
<div class="boxbody">
21-
<ul>{% for env in enviros %}
21+
<ul><a href="#" class="togglefold">Environments</a> <span class="checklinks">(<a href="#" class="checkall">All</a>, <a href="#" class="uncheckall">None</a>)</span>
22+
{% for env in enviros %}
2223
<li title="{{ env.os }}, {{ env.cpu }}">
23-
<input id="env_{{ env.id }}" type="checkbox" name="environments" value="{{ env.id }}" />
24+
<input id="env_{{ env.id }}" type="checkbox" name="environments" value="{{ env.id }}"{% if env in checkedenviros %} checked{% endif %} />
2425
<label for="env_{{ env.id }}">{{ env }}</label>
2526
</li>{% endfor %}
2627
</ul>
@@ -93,10 +94,6 @@
9394
<script type="text/javascript" src="{% static 'js/comparison.js' %}"></script>
9495

9596
<script type="text/javascript">
96-
var checkboxes = document.getElementsByTagName('environments');
97-
for (c in checkboxes) {
98-
c.checked = false;
99-
}
10097
$(function() {
10198
Comparison.init({
10299
chart_type: "{{ selectedchart }}",

‎codespeed/templates/codespeed/timeline.html‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</ul>{% endif %}
6868
{% regroup benchmarks by get_source_display as benchmark_groups %}
6969
{% for group in benchmark_groups %}
70-
<ul><a href="#" class="togglefold">{{ group.grouper }}</a>
70+
<ul>{% if benchmark_groups|length > 1 %}<a href="#" class="togglefold">{{ group.grouper }}</a>{% endif %}
7171
{% for bench in group.list|dictsort:"name" %}
7272
<li title="{{ bench.description }}">
7373
<input id="benchmark_{{ bench.id }}" type="radio" name="benchmark" value="{{ bench.ident }}" />
@@ -120,6 +120,7 @@
120120
$(function() {
121121
Timeline.init({
122122
revisions: {{ defaultlast }},
123+
grid_revisions: {{ grid_revisions|default_if_none:"null" }},
123124
baseline: "{{ defaultbaseline }}",
124125
executables: [{% for exe in checkedexecutables %}{{ exe.id }}, {% endfor %}],
125126
branches: [{% for b in branch_list %}"{{ branch }}", {% endfor %}],

‎codespeed/tests/test_views.py‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,67 @@ def test_gettimelinedata(self):
455455
responsedata['timelines'][0]['branches']['master']['1:1'][1],
456456
[u'2011/04/13 17:04:22 +0000', 2000.0, 1.11111, u'2', u'', u'master', u''])
457457

458+
def test_no_source_fold_with_one_source(self):
459+
"""A single source shows a flat benchmark list and no fold header"""
460+
response = self.client.get(reverse('timeline'))
461+
self.assertEqual(response.status_code, 200)
462+
self.assertIsNone(response.context['grid_revisions'])
463+
self.assertNotContains(response, 'class="togglefold">Legacy</a>')
464+
self.assertContains(response, 'grid_revisions: null')
465+
466+
def test_source_fold_with_several_sources(self):
467+
Benchmark.objects.create(name='float', source='pyperformance')
468+
response = self.client.get(reverse('timeline'))
469+
self.assertContains(response, 'class="togglefold">Legacy</a>')
470+
self.assertContains(response, 'class="togglefold">PyPerformance</a>')
471+
472+
@override_settings(TIMELINE_GRID_REVISIONS=25)
473+
def test_grid_revisions_setting(self):
474+
response = self.client.get(reverse('timeline'))
475+
self.assertEqual(response.context['grid_revisions'], 25)
476+
self.assertIn(25, response.context['lastrevisions'])
477+
self.assertContains(response, 'grid_revisions: 25')
478+
479+
480+
class TestComparison(TestCase):
481+
fixtures = ["timeline_tests.json"]
482+
483+
def setUp(self):
484+
self.path = reverse('comparison')
485+
self.dual = Environment.objects.get(name='Dual Core')
486+
self.quad = Environment.objects.create(name='Quad Core')
487+
488+
def checked_env_names(self, response):
489+
return sorted(e.name for e in response.context['checkedenviros'])
490+
491+
def test_all_environments_checked_by_default(self):
492+
response = self.client.get(self.path)
493+
self.assertEqual(response.status_code, 200)
494+
self.assertEqual(self.checked_env_names(response),
495+
['Dual Core', 'Quad Core'])
496+
497+
@override_settings(COMP_ENVIRONMENTS_DEFAULT='default',
498+
DEF_ENVIRONMENT='Quad Core')
499+
def test_only_default_environment_checked(self):
500+
response = self.client.get(self.path)
501+
self.assertEqual(self.checked_env_names(response), ['Quad Core'])
502+
# Permalinks still select several environments
503+
response = self.client.get(
504+
self.path, {'env': '%d,%d' % (self.dual.id, self.quad.id)})
505+
self.assertEqual(self.checked_env_names(response),
506+
['Dual Core', 'Quad Core'])
507+
508+
def test_benchmarks_grouped_by_units_with_one_source(self):
509+
response = self.client.get(self.path)
510+
self.assertEqual(list(response.context['benchmarks']), ['Time'])
511+
self.assertContains(response, 'class="togglefold">Time</a>')
512+
513+
def test_benchmarks_grouped_by_source_with_several_sources(self):
514+
Benchmark.objects.create(name='float', source='pyperformance')
515+
response = self.client.get(self.path)
516+
self.assertEqual(list(response.context['benchmarks']),
517+
['Legacy', 'PyPerformance'])
518+
458519

459520
@override_settings(ALLOW_ANONYMOUS_POST=True)
460521
class TestReports(TestCase):

‎codespeed/views.py‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,10 @@ def comparison(request):
326326
enviros = Environment.objects.all()
327327
if not enviros:
328328
return no_environment_error(request)
329-
checkedenviros = get_default_environment(enviros, data)
329+
checkedenviros = get_default_environment(enviros, data, multi=True)
330+
if 'env' not in data and \
331+
get_setting('COMP_ENVIRONMENTS_DEFAULT', 'all') == 'default':
332+
checkedenviros = get_default_environment(enviros, data)
330333

331334
if not len(Project.objects.filter(track=True)):
332335
return no_default_project_error(request)
@@ -395,13 +398,18 @@ def comparison(request):
395398

396399
benchmarks = {}
397400
bench_units = {}
398-
for source_val, source_label in Benchmark.S_TYPES:
401+
sources = [(val, label) for val, label in Benchmark.S_TYPES
402+
if Benchmark.objects.filter(source=val).exists()]
403+
# Sidebar groups: by source when there are several, else by units title
404+
group_by_source = len(sources) > 1
405+
for source_val, source_label in sources:
399406
qs = Benchmark.objects.filter(source=source_val)
400-
if not qs.exists():
401-
continue
402-
benchmarks[source_label] = qs
407+
if group_by_source:
408+
benchmarks[source_label] = qs
403409
for unit in qs.values_list('units_title', flat=True).distinct():
404410
unit_qs = qs.filter(units_title=unit)
411+
if not group_by_source:
412+
benchmarks[unit] = unit_qs
405413
units = unit_qs[0].units
406414
lessisbetter = (unit_qs[0].lessisbetter and
407415
' (less is better)' or ' (more is better)')
@@ -806,6 +814,9 @@ def timeline(request):
806814
for proj in Project.objects.filter(track=True):
807815
executables[proj] = Executable.objects.filter(project=proj)
808816
use_median_bands = hasattr(settings, 'USE_MEDIAN_BANDS') and settings.USE_MEDIAN_BANDS
817+
grid_revisions = get_setting('TIMELINE_GRID_REVISIONS', None)
818+
if grid_revisions and grid_revisions not in lastrevisions:
819+
lastrevisions = sorted(lastrevisions + [grid_revisions])
809820
if isinstance(defaultbenchmark, Benchmark):
810821
defaultbenchmark_value = defaultbenchmark.ident()
811822
else:
@@ -821,6 +832,7 @@ def timeline(request):
821832
'defaultenvironments': defaultenvironments,
822833
'lastrevisions': lastrevisions,
823834
'defaultlast': defaultlast,
835+
'grid_revisions': grid_revisions,
824836
'executables': executables,
825837
'benchmarks': benchmarks,
826838
'environments': enviros,

‎speed_pypy/settings.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@
100100
DEF_ENVIRONMENT = 'benchmarker2'
101101
CHART_ORIENTATION = 'horizontal'
102102
DEF_BENCHMARK = 'grid'
103+
TIMELINE_GRID_REVISIONS = 15
104+
COMP_ENVIRONMENTS_DEFAULT = 'default'
103105

104106

105107
from .local_settings import *

0 commit comments

Comments
 (0)