Skip to content

Commit

Permalink
Fix(#27) Open up plots on clicking on test result link
Browse files Browse the repository at this point in the history
  • Loading branch information
tonythomas01 committed Jul 15, 2018
1 parent 5cf7386 commit 8d6beb9
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 25 deletions.
5 changes: 3 additions & 2 deletions dashboard/core/bots/authentication_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from dashboard.core.bots.models import Bot



class BotAuthentication(authentication.BaseAuthentication):
"""Bot authentication view, used to authenticate data sending bots via API"""
"""
Bot authentication view, used to authenticate data sending bots via API
"""

def authenticate(self, request):
bot_name = request.POST.get('bot_id')
Expand Down
24 changes: 14 additions & 10 deletions dashboard/core/bots/reports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
from dashboard.core.metric_units.models import MetricUnit




AGGREGATION_CHOICES = (
('None', 'None'),
('Total', 'Total'),
Expand All @@ -20,10 +18,11 @@


class BotReportDataManger(models.Manager):
def create_report(self, bot, browser, browser_version, root_test,
test_path, test_version, aggregation, metric_unit,
metric_unit_prefixed, mean_value, stddev, delta,
is_improvement,prev_result,timestamp=None):
def create_report(
self, bot, browser, browser_version, root_test,
test_path, test_version, aggregation, metric_unit,
metric_unit_prefixed, mean_value, stddev, delta,
is_improvement,prev_result,timestamp=None):
bot_report_data = self.create(
bot=bot, browser=browser, browser_version=browser_version,
root_test=root_test, test_path=test_path,
Expand Down Expand Up @@ -84,12 +83,17 @@ def save(self, *args, **kwargs):
super(BotReportData, self).save(*args, **kwargs)

def __unicode__(self):
return self.bot.name + ":" + str(self.browser) \
+ ":" + self.test_version + ":" +\
self.test_path + ":" + str(self.mean_value)
return '{0}:{1}:{2}:{3}:{4}'.format(
self.bot.name, self.browser, self.test_version, self.test_path,
self.mean_value)

def __str__(self):
return '{0}:{1}:{2}:{3}:{4}'.format(
self.bot.name, self.browser, self.test_version, self.test_path,
self.mean_value)

class Meta:
unique_together = (
'bot', 'browser', 'browser_version', 'root_test', 'test_path',
'test_version', 'metric_unit', 'aggregation',
)
)
37 changes: 35 additions & 2 deletions dashboard/core/bots/reports/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import base64
import json

from rest_framework import serializers

from dashboard.core.bots.reports.models import BotReportData
Expand Down Expand Up @@ -38,6 +41,7 @@ class Meta:
class BotReportDataSerializer(serializers.ModelSerializer):
prev_results = serializers.SerializerMethodField()
metric_unit = MetricUnitSerializer()
plot_link = serializers.SerializerMethodField()

def get_prev_results(self, obj):
if not obj.prev_result:
Expand All @@ -49,14 +53,43 @@ def get_prev_results(self, obj):
"mean_value": obj.prev_result.mean_value,
"browser_version": obj.prev_result.browser_version,
"stddev": obj.prev_result.stddev,
"metric_unit_prefixed": obj.prev_result.metric_unit_prefixed
"metric_unit_prefixed": obj.prev_result.metric_unit_prefixed,
}

def get_plot_link(self, obj):
"""
The plot link is a base64 encoded pointer to a plot on graphs/ page
:return: link to plot
"""
plot_data = [
{
'browser': obj.browser.id,
'bot': obj.bot.name,
'root_test': obj.root_test.id,
'subtest': obj.test_path,
'seq': 0,
'start': float(obj.timestamp.strftime('%s'))*1000,
'plots': []
}
]
if obj.prev_result:
plot_data[0].update(
{
'start': float(obj.prev_result.timestamp.strftime(
'%s'))*1000,
'end': float(obj.timestamp.strftime('%s'))*1000,
}
)
return'/dash/graph/#!/{0}'.format(
base64.b64encode(json.dumps(plot_data).encode()).decode()
)


class Meta:
model = BotReportData
fields = (
'id', 'bot', 'browser', 'browser_version', 'root_test',
'test_path', 'test_version', 'metric_unit',
'metric_unit_prefixed', 'mean_value', 'stddev', 'delta',
'prev_results'
'prev_results', 'plot_link',
)
4 changes: 2 additions & 2 deletions dashboard/core/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Test(models.Model):
enabled = models.BooleanField(default=False)

def __str__(self):
return self.name
return self.id

def __unicode__(self):
return self.id
return self.id
18 changes: 9 additions & 9 deletions dashboard/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@
</td>
<td>
<a ng-if="data.test_version==data.prev_results.test_version" popover-trigger="'mouseenter'"
uib-popover-template="testDetailsPopover.templateUrl" popover-title="test details of both revisions (unchanged)">{{ data.test_path }}
</a>
uib-popover-template="testDetailsPopover.templateUrl"
popover-title="test details of both revisions (unchanged)"
href="{{ data.plot_link }}">{{ data.test_path }}</a>
<a ng-if="data.test_version != data.prev_results.test_version" popover-title="test: {{ data.root_test }}"
uib-popover="Warning: The test version changed in between the revisions." popover-trigger="'mouseenter'">{{ data.test_path }}
</a>
uib-popover="Warning: The test version changed in between the revisions." popover-trigger="'mouseenter'"
href="{{ data.plot_link }}">{{ data.test_path }}</a>
</td>
<td style="text-align: center">
<span ng-if="data.prev_results.mean_value" popover-trigger="'mouseenter'"
Expand Down Expand Up @@ -167,12 +168,11 @@
</td>
<td>
<a ng-if="data.test_version==data.prev_results.test_version" popover-trigger="'mouseenter'"
uib-popover-template="testDetailsPopover.templateUrl" popover-title="test details of both revisions (unchanged)">{{ data.test_path }}
</a>
uib-popover-template="testDetailsPopover.templateUrl" popover-title="test details of both revisions (unchanged)"
href="{{ data.plot_link }}">{{ data.test_path }}</a>
<a ng-if="data.test_version != data.prev_results.test_version" popover-title="test: {{ data.root_test }}"
uib-popover="Warning: The test version changed in between the revisions." popover-trigger="'mouseenter'">{{ data.test_path }}
</a>

uib-popover="Warning: The test version changed in between the revisions." popover-trigger="'mouseenter'"
href="{{ data.plot_link }}">{{ data.test_path }}</a>
</td>
<td style="text-align: center">
<span ng-if="data.prev_results.mean_value" popover-trigger="'mouseenter'"
Expand Down

0 comments on commit 8d6beb9

Please # to comment.