Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Bug 1017829 - Allow displaying only recent results in dashboard;r=dav…
Browse files Browse the repository at this point in the history
…ehunt
  • Loading branch information
wlach committed Aug 6, 2014
1 parent a3d06c6 commit ae5fe70
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 41 deletions.
19 changes: 18 additions & 1 deletion src/dashboard/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,25 @@
<script src="js/common.js"></script>
<script src="js/index.js"></script>

<script id="graph" type="text/html">
<script id="contentHeader" class="partial" type="text/html">
<h1>{{title}}</h1>
{{#showTimeRanges}}
<select id="time-range" type="text">
{{#timeRanges}}
<option id="time-range-{{range}}" value="{{range}}">{{label}}</option>
{{/timeRanges}}
</select>
{{/showTimeRanges}}
<hr/>
</script>

<script id="noGraph" type="text/html">
{{>contentHeader}}
<p class="lead">{{errorReason}}</p>
</script>

<script id="graph" type="text/html">
{{>contentHeader}}
<div id="graph-main">
<div id="graph-container"></div>
<div id="measure-form">
Expand Down
149 changes: 109 additions & 40 deletions src/dashboard/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,97 @@ function getResourceURL(path) {
return serverPrefix + path;
}

function updateContent(testInfo, deviceId, branchId, testId, measureId) {
function updateContent(testInfo, deviceId, branchId, testId, measureId, timeRange) {
$.getJSON(getResourceURL([deviceId, branchId, testId].join('/') + '.json'), function(dict) {
if (!dict || !dict['testdata']) {
$('#data-view').html("<p><b>No data for that device/test combination. :(</b></p>");
$('#data-view').html(ich.noGraph({
"title": testInfo.shortDesc,
"errorReason": "No data for that device/test combination. :("
}));
return;
}

var testData = dict['testdata'];
var timeRanges = [ { 'range': 7, 'label': '7 days' },
{ 'range': 30, 'label': '30 days' },
{ 'range': 60, 'label': '60 days' },
{ 'range': 90, 'label': '90 days' },
{ 'range': 0, 'label': 'All time' } ]

// filter the data according to time range (if we're using a time range)
timeRange = parseInt(timeRange);
if (timeRange !== 0) {
var minDate = (Date.now() / 1000.0) - (timeRange * 24 * 60 * 60);
var entriesToRemove = [];
var allProducts = Object.keys(testData);
allProducts.forEach(function(product) {
Object.keys(testData[product]).forEach(function(timestamp) {
if (parseInt(timestamp) < minDate) {
entriesToRemove.push({ 'product': product, 'timestamp': timestamp });
}
});
});
entriesToRemove.forEach(function(entry) {
delete testData[entry.product][entry.timestamp];
});
allProducts.map(function(product) {
if (Object.keys(testData[product]).length == 0) {
delete testData[product];
}
});
}

// figure out which measures could apply to this graph
var availableMeasureIds = [];
Object.keys(testData).forEach(function(product) {
Object.keys(testData[product]).forEach(function(timestamp) {
testData[product][timestamp].forEach(function(sample) {
var measureIds = getMeasureIdsInSample(sample, overallMeasures);
measureIds.forEach(function(measureId) {
if (jQuery.inArray(measureId, availableMeasureIds) === -1) {
availableMeasureIds.push(measureId);
}
if (Object.keys(testData).length === 0) {
// not enough data for this time range

$('#data-view').html(ich.noGraph({
'title': testInfo.shortDesc,
'errorReason': "No data in the last " + timeRange +
" days, try choosing a larger interval above to get old data.",
'timeRanges': timeRanges,
'showTimeRanges': true
}));
} else {

// figure out which measures could apply to this graph
var availableMeasureIds = [];
Object.keys(testData).forEach(function(product) {
Object.keys(testData[product]).forEach(function(timestamp) {
testData[product][timestamp].forEach(function(sample) {
var measureIds = getMeasureIdsInSample(sample, overallMeasures);
measureIds.forEach(function(measureId) {
if (jQuery.inArray(measureId, availableMeasureIds) === -1) {
availableMeasureIds.push(measureId);
}
});
});
});
});
});

$('#data-view').html(ich.graph({'title': testInfo.shortDesc,
'measureDescription': overallMeasures[measureId].longDesc,
'measures': measureDisplayList(availableMeasureIds, overallMeasures)
}));

// update graph
updateGraph(testInfo.shortDesc, testData, measureId);
$('#data-view').html(ich.graph({'title': testInfo.shortDesc,
'measureDescription': overallMeasures[measureId].longDesc,
'measures': measureDisplayList(availableMeasureIds, overallMeasures),
'timeRanges': timeRanges,
'showTimeRanges': true
}));

// update graph
updateGraph(testInfo.shortDesc, testData, measureId);

$('#measure-'+measureId).attr("selected", "true");
$('#measure').change(function() {
var newMeasureId = $(this).val();
window.location.hash = '/' + [ deviceId, branchId, testId,
newMeasureId, timeRange ].join('/');
});
}

$('#measure-'+measureId).attr("selected", "true");
$('#measure').change(function() {
var newMeasureId = $(this).val();
window.location.hash = '/' + [ deviceId, branchId, testId, newMeasureId ].join('/');
// update time range selector
$('#time-range-' + timeRange).attr("selected", "true");
$('#time-range').change(function() {
var newTimeRange = $(this).val();
window.location.hash = '/' + [ deviceId, branchId, testId,
measureId, newTimeRange ].join('/');
});

});
Expand Down Expand Up @@ -359,7 +414,7 @@ $(function() {
}
}

function updateDeviceChooser(preferredBranchId, preferredTest) {
function updateDeviceChooser(timeRange, preferredBranchId, preferredTest) {
$('#device-chooser').empty();

deviceIds.forEach(function(deviceId) {
Expand All @@ -375,21 +430,21 @@ $(function() {
var testId = getTestIdForDeviceAndBranch(deviceId, branchId, preferredTest);
var defaultMeasureId = device[branchId].tests[testId].defaultMeasureId;

var deviceURL = "#/" + [ deviceId, branchId, testId, defaultMeasureId ].join('/');
var deviceURL = "#/" + [ deviceId, branchId, testId, defaultMeasureId, timeRange ].join('/');
$('<a href="' + deviceURL + '" id="device-' + deviceId + '" deviceid= ' + deviceId + ' class="list-group-item">' + devices[deviceId].name+'</a></li>').appendTo(
$('#device-chooser'));
});
}

function updateBranchChooser(deviceId, preferredTest) {
function updateBranchChooser(timeRange, deviceId, preferredTest) {
$('#branch-chooser').empty();

var device = devices[deviceId];
device.branches.forEach(function(branchId) {
var testId = getTestIdForDeviceAndBranch(deviceId, branchId, preferredTest);
var defaultMeasureId = device[branchId].tests[testId].defaultMeasureId;

var url = "#/" + [ deviceId, branchId, testId, defaultMeasureId ].join('/');
var url = "#/" + [ deviceId, branchId, testId, defaultMeasureId, timeRange ].join('/');
$('<a href="' + url + '" id="branch-' + branchId + '" class="list-group-item">' + branchId +'</a></li>').appendTo(
$('#branch-chooser'));
});
Expand All @@ -400,15 +455,15 @@ $(function() {
var currentTestId = null;

var routes = {
'/:deviceId/:branchId/:testId/:measureId': {
on: function(deviceId, branchId, testId, measureId) {
'/:deviceId/:branchId/:testId/:measureId/:timeRange': {
on: function(deviceId, branchId, testId, measureId, timeRange) {
if (!devices[deviceId] || !devices[deviceId][branchId] || !devices[deviceId][branchId]['tests'][testId]) {
$('#data-view').html("<p><b>That device/branch/test/measure combination does not seem to exist. Maybe you're using an expired link? <a href=''>Reload page</a>?</b></p>");
$('#data-view').html("<p class='lead'>That device/branch/test/measure combination does not seem to exist. Maybe you're using an expired link? <a href=''>Reload page</a>?</p>");
return;
}

updateDeviceChooser(branchId, testId);
updateBranchChooser(deviceId, testId);
updateDeviceChooser(timeRange, branchId, testId);
updateBranchChooser(timeRange, deviceId, testId);

// update list of tests to be consistent with those of this
// particular device (in case it changed)
Expand All @@ -427,7 +482,7 @@ $(function() {
var defaultMeasureId = tests[testIdAttr].defaultMeasureId;
$(this).attr('href', '#/' +
[ deviceId, branchId, testIdAttr,
defaultMeasureId ].join('/'));
defaultMeasureId, timeRange ].join('/'));
}
});

Expand All @@ -438,7 +493,7 @@ $(function() {

var testInfo = tests[testId];
updateFooter();
updateContent(testInfo, deviceId, branchId, testId, measureId);
updateContent(testInfo, deviceId, branchId, testId, measureId, timeRange);
}
}
};
Expand All @@ -447,11 +502,25 @@ $(function() {
var defaultBranchId = devices[defaultDeviceId].branches[0];
var defaultTestId = Object.keys(devices[defaultDeviceId][defaultBranchId].tests)[0];
var defaultMeasureId = devices[defaultDeviceId][defaultBranchId].tests[defaultTestId].defaultMeasureId;

var router = Router(routes).init('/' + [ defaultDeviceId,
defaultBranchId,
defaultTestId,
defaultMeasureId ].join('/'));
var defaultTimeRange = 7;

var defaultRouteHash = '/' + [ defaultDeviceId,
defaultBranchId,
defaultTestId,
defaultMeasureId,
defaultTimeRange ].join('/');

var router = Router(routes).configure({
'notfound': function() {
$('#data-view').html(ich.noGraph({
"title": "Invalid URL",
"errorReason": "Invalid or expired route (probably due to a " +
"change in Eideticker). Try selecting a valid combination " +
"from the menu on the left."
}));
}
});
router.init(defaultRouteHash);
});
});
});

0 comments on commit ae5fe70

Please sign in to comment.