You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by ij...@apache.org on 2014/07/02 17:04:46 UTC

svn commit: r1607389 - in /jena/Experimental/jena-fuseki2/src/main/webapp: css/fui.css js/app/models/dataset.js js/app/services/ping-service.js js/app/templates/dataset-info.tpl js/app/views/dataset-info.js js/app/views/file-upload.js

Author: ijd
Date: Wed Jul  2 15:04:46 2014
New Revision: 1607389

URL: http://svn.apache.org/r1607389
Log:
Added operation to count the number of triples in the dataset, trigger by user action

Modified:
    jena/Experimental/jena-fuseki2/src/main/webapp/css/fui.css
    jena/Experimental/jena-fuseki2/src/main/webapp/js/app/models/dataset.js
    jena/Experimental/jena-fuseki2/src/main/webapp/js/app/services/ping-service.js
    jena/Experimental/jena-fuseki2/src/main/webapp/js/app/templates/dataset-info.tpl
    jena/Experimental/jena-fuseki2/src/main/webapp/js/app/views/dataset-info.js
    jena/Experimental/jena-fuseki2/src/main/webapp/js/app/views/file-upload.js

Modified: jena/Experimental/jena-fuseki2/src/main/webapp/css/fui.css
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-fuseki2/src/main/webapp/css/fui.css?rev=1607389&r1=1607388&r2=1607389&view=diff
==============================================================================
--- jena/Experimental/jena-fuseki2/src/main/webapp/css/fui.css (original)
+++ jena/Experimental/jena-fuseki2/src/main/webapp/css/fui.css Wed Jul  2 15:04:46 2014
@@ -159,3 +159,19 @@ a.navbar-brand img {
 .dl-horizontal dd {
   margin-left: 220px
 }
+
+dt span.heading, dd span.heading {
+  font-weight: bold;
+  background-color: #eee;
+  padding: 3px 8px;
+}
+
+dt span.heading {
+  padding-right: 2px;
+}
+dd span.heading {
+  padding-left: 2px;
+}
+dt.font-weight-normal {
+  font-weight: normal;
+}

Modified: jena/Experimental/jena-fuseki2/src/main/webapp/js/app/models/dataset.js
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-fuseki2/src/main/webapp/js/app/models/dataset.js?rev=1607389&r1=1607388&r2=1607389&view=diff
==============================================================================
--- jena/Experimental/jena-fuseki2/src/main/webapp/js/app/models/dataset.js (original)
+++ jena/Experimental/jena-fuseki2/src/main/webapp/js/app/models/dataset.js Wed Jul  2 15:04:46 2014
@@ -19,7 +19,13 @@ define(
     var Dataset = Backbone.Model.extend( {
       initialize: function( datasetDescription, baseURL, mgmtURL ) {
         this.set( datasetDescription );
-        this.set( {baseURL: baseURL, mgmtURL: mgmtURL} );
+        this.set( {
+                    baseURL: baseURL,
+                    mgmtURL: mgmtURL,
+                    counts: {},
+                    countPerformed: false,
+                    counting: false
+                  } );
       },
 
       baseURL: function() {
@@ -46,6 +52,14 @@ define(
         return this.get( "ds.services" );
       },
 
+      countPerformed: function() {
+        return this.get( "countPerformed" );
+      },
+
+      counts: function() {
+        return this.get( "counts" );
+      },
+
       serviceTypes: function() {
         return _.map( this.services(), function( s ) {return s["srv.type"];} );
       },
@@ -99,6 +113,11 @@ define(
         return this.endpointURL( "Query" ) ;
       },
 
+      /** Return the sparql query URL for this dataset, if it has one, or null */
+      quadsURL: function() {
+        return this.endpointURL( "Quads" ) ;
+      },
+
       /** Return the sparql update URL for this dataset, if it has one, or null */
       updateURL: function() {
         return this.endpointURL( "Update" ) ;
@@ -111,7 +130,8 @@ define(
 
       /** Return the sparql upload URL for this dataset, if it has one, or null */
       uploadURL: function( graphName ) {
-        return sprintf( "%s?graph=%s", this.graphStoreProtocolURL(), graphName );
+//        return sprintf( "%s?graph=%s", this.graphStoreProtocolURL(), graphName );
+        return sprintf( "%s%s", this.graphStoreProtocolURL(), (graphName === "default" ? "" : ("?graph=" + graphName) ));
       },
 
       /** Perform the action to delete the dataset. Returns the Ajax deferred object */
@@ -139,6 +159,37 @@ define(
       /** Request the statistics for this dataset, and return the promise object for the callback */
       statistics: function() {
         return $.getJSON( this.statisticsURL() );
+      },
+
+      /** Perform a count query to determine the size of the dataset. Changes the size property when done,
+       * but also returns the JQuery promise object used to monitor the query response */
+      count: function() {
+        var self = this;
+        var query1 = sprintf( "select (count(*) as ?count) {?s ?p ?o}" );
+        var query2 = sprintf( "select ?g (count(*) as ?count) {graph ?g {?s ?p ?o}} group by ?g" );
+
+        self.set( "counting", true );
+
+        var updateCount = function( model, result, graph ) {
+          var n = parseInt( result.count.value );
+          var counts = _.extend( {}, model.get( "counts" ) );
+          counts[graph] = n;
+          model.set( "counts", counts );
+        };
+
+        $.getJSON( sprintf( "%s?query=%s", self.queryURL(), query1 ) )
+         .done( function( data ) {
+           updateCount( self, data.results.bindings[0], "default graph" );
+
+           $.getJSON( sprintf( "%s?query=%s", self.queryURL(), query2 ) )
+            .done( function( data ) {
+              _.each( data.results.bindings, function( binding ) {
+                updateCount( self, binding, binding.g.value );
+              } );
+            } );
+
+           self.set( {countPerformed: true, counting: false} );
+         } );
       }
 
     } );

Modified: jena/Experimental/jena-fuseki2/src/main/webapp/js/app/services/ping-service.js
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-fuseki2/src/main/webapp/js/app/services/ping-service.js?rev=1607389&r1=1607388&r2=1607389&view=diff
==============================================================================
--- jena/Experimental/jena-fuseki2/src/main/webapp/js/app/services/ping-service.js (original)
+++ jena/Experimental/jena-fuseki2/src/main/webapp/js/app/services/ping-service.js Wed Jul  2 15:04:46 2014
@@ -6,7 +6,7 @@ define( ['jquery', 'underscore', 'sprint
   function( $, _, sprintf ) {
 
     var PING_URL = "$/ping"
-    var DEFAULT_PING_TIME = 5000;
+    var DEFAULT_PING_TIME = 500000;  // TODO slowed down during debugging phase
     var _startTime = 0;
 
     var onBeforeSend = function() {

Modified: jena/Experimental/jena-fuseki2/src/main/webapp/js/app/templates/dataset-info.tpl
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-fuseki2/src/main/webapp/js/app/templates/dataset-info.tpl?rev=1607389&r1=1607388&r2=1607389&view=diff
==============================================================================
--- jena/Experimental/jena-fuseki2/src/main/webapp/js/app/templates/dataset-info.tpl (original)
+++ jena/Experimental/jena-fuseki2/src/main/webapp/js/app/templates/dataset-info.tpl Wed Jul  2 15:04:46 2014
@@ -18,6 +18,26 @@
 <h3>Statistics</h3>
 <div id="statistics"></div>
 
+<h3>Dataset size</h3>
+<p>
+<strong>Warning</strong> this may be slow and impose a heavy load on large datasets:
+<a href="#" class="action count-graphs btn btn-primary">Count triples in all datasets graphs</a>
+</p>
+<% if (countPerformed()) { %>
+<dl class="dl-horizontal">
+  <dt><span class="heading">graph name</span></dt><dd><span class="heading">number of triples</span></dd>
+  <% _.each( counts(), function( n, g ) { %>
+    <dt class="font-weight-normal">
+      <%= g %>:
+    </dt>
+    <dd>
+      <%= n %>
+    </dd>
+  <% } ); %>
+</dl>
+
+<% } %>
+
 <h3>Ongoing operations</h3>
 
 <p><em>TBD. Will list any long-lasting operations that are ongoing or recently completed,

Modified: jena/Experimental/jena-fuseki2/src/main/webapp/js/app/views/dataset-info.js
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-fuseki2/src/main/webapp/js/app/views/dataset-info.js?rev=1607389&r1=1607388&r2=1607389&view=diff
==============================================================================
--- jena/Experimental/jena-fuseki2/src/main/webapp/js/app/views/dataset-info.js (original)
+++ jena/Experimental/jena-fuseki2/src/main/webapp/js/app/views/dataset-info.js Wed Jul  2 15:04:46 2014
@@ -12,7 +12,7 @@ define(
     var DatasetInfo = Backbone.Marionette.ItemView.extend( {
 
       initialize: function() {
-//        _.bindAll( this, "onShowTab" );
+        _.bindAll( this, "onModelChanged", "onCountGraphs" );
 
         var dataset = this.dataset();
 
@@ -22,17 +22,21 @@ define(
                      var model = new DatasetStatsModel( dataset, data );
                      new DatasetStatsView( {model: model} ).render();
                    } );
+
+        this.model.on( "change", this.onModelChanged );
       },
 
       template: _.template( DatasetInfoTpl ),
 
       ui: {
-        stats: "#statistics"
+        stats: "#statistics",
+        count: ".count-graphs"
       },
 
       el: "#info .with-dataset",
 
       events: {
+        "click .count-graphs": "onCountGraphs"
       },
 
       templateHelpers: {
@@ -45,10 +49,21 @@ define(
       /** Alias for the model */
       dataset: function() {
         return this.model;
-      }
+      },
 
       // event handlers
 
+      onModelChanged: function() {
+        if (!this.model.counting) {
+          this.render();
+        }
+      },
+
+      onCountGraphs: function( e ) {
+        e.preventDefault();
+        this.model.count();
+      }
+
     });
 
 

Modified: jena/Experimental/jena-fuseki2/src/main/webapp/js/app/views/file-upload.js
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-fuseki2/src/main/webapp/js/app/views/file-upload.js?rev=1607389&r1=1607388&r2=1607389&view=diff
==============================================================================
--- jena/Experimental/jena-fuseki2/src/main/webapp/js/app/views/file-upload.js (original)
+++ jena/Experimental/jena-fuseki2/src/main/webapp/js/app/views/file-upload.js Wed Jul  2 15:04:46 2014
@@ -46,7 +46,7 @@ define(
       onRender: function() {
         // initialise the file upload widget
         this.ui.fileUpload.fileupload( {
-          dataType: 'json',
+//          dataType: 'json',
           add: this.onUploadAdd,
           progress: this.onProgress
         } );