Skip to content
Permalink
Browse files
Add timer.
  • Loading branch information
RubenVerborgh committed Aug 18, 2016
1 parent 3602cf9 commit 4b9f1eed77d768fb6d538e5b98a70272b879ed9a
Showing with 25 additions and 5 deletions.
  1. +1 −0 index.html
  2. +17 −4 ldf-client-jquery.js
  3. +7 −1 ldf-client.css
@@ -51,6 +51,7 @@ <h1>Query Linked Data on the Web</h1>
<li>
<button class="start">Execute query</button>
<button class="stop" style="display:none">Stop execution</button>
<span class="timing"></span>
</li>

<li>
@@ -58,6 +58,7 @@
$element = this.element,
$stop = this.$stop = $('.stop', $element),
$start = this.$start = $('.start', $element),
$timing = this.$timing = $('.timing', $element),
$query = this.$query = $('.queryText', $element),
$queries = this.$queries = $('.query', $element),
$log = $('.log', $element),
@@ -241,20 +242,19 @@
= new ldf.FragmentsClient(datasources, config);

// Create the iterator to solve the query
var resultsIterator;
var resultsIterator, resultCount = 0;
try { resultsIterator = new ldf.SparqlIterator(this.$query.val(), config); }
catch (error) { return this._stopExecution(error); }
this._resultsIterator = resultsIterator;
resultsIterator.on('end', $.proxy(this._stopExecution, this));
resultsIterator.on('data', function () { resultCount++ });
resultsIterator.on('end', $.proxy(this._stopExecution, this));
resultsIterator.on('error', $.proxy(this._stopExecution, this));

// Read the iterator's results, and write them depending on the query type
switch (resultsIterator.queryType) {
// For SELECT queries, write a JSON array representation of the rows
case 'SELECT':
var resultCount = 0;
resultsIterator.on('data', function (row) {
resultCount++;
resultsScroller.addContent([lastRow = row]);
});
resultsIterator.on('end', function () {
@@ -279,6 +279,18 @@
default:
writeResult(resultsIterator.queryType + ' queries are unsupported.');
}

// Update result timer
var $timing = this.$timing, startTime = new Date();
function updateTiming() {
$timing.text(resultCount.toLocaleString() + ' result' +
(resultCount === 1 ? '' : 's') + ' in ' +
((new Date() - startTime) / 1000).toFixed(1) + 's');
}
updateTiming();
resultsIterator.on('end', updateTiming);
this._timingUpdater && clearInterval(this._timingUpdater);
this._timingUpdater = setInterval(updateTiming, 100);
},

// Stops query execution
@@ -293,6 +305,7 @@
error && error.message && this._writeResult(error.message);
this._writeResult.flush();
this._writeLog.flush();
clearInterval(this._timingUpdater);
},

// Shows the details panel
@@ -51,7 +51,7 @@ button:active {
}
input {
padding: 1px 5px;
font-size: .9em;
font-size: 10pt;
}
label:after {
content: ":";
@@ -107,6 +107,12 @@ select {
width: 430px;
}

.timing {
float: right;
font-size: 10pt;
padding: .7em 0;
}

.chosen {
float: right;
}

0 comments on commit 4b9f1ee

Please sign in to comment.