Skip to content

Commit af69e1d

Browse files
committed
added statistics to start page
1 parent 6e91c1d commit af69e1d

5 files changed

Lines changed: 191 additions & 0 deletions

File tree

src/main/java/de/unirostock/sems/cbarchive/web/QuotaManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ public void run() {
272272
if( Fields.QUOTA_ARCHIVE_LIMIT != Fields.QUOTA_UNLIMITED )
273273
stats.setAverageArchiveCountQuota( stats.getAverageArchiveCount() / (double) Fields.QUOTA_ARCHIVE_LIMIT );
274274

275+
stats.setMaxStatsAge( Fields.MAX_STATS_AGE );
276+
275277
// tranfer the results to the main class
276278
quotaManager.workspaceCache = cache;
277279
quotaManager.totalSize = totalSize;

src/main/java/de/unirostock/sems/cbarchive/web/dataholder/StatisticData.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public class StatisticData implements Serializable, Cloneable {
4040
/** relative usage of archives per workspace quota (0.0 - 1.0) */
4141
private double userArchiveCountQuota = IGNORE_DOUBLE;
4242

43+
// server stuff
44+
private long maxStatsAge = IGNORE_LONG;
45+
4346
/** Timestamp of generation */
4447
private Date generated = new Date();
4548

@@ -140,6 +143,14 @@ public long getTotalArchiveCount() {
140143
public void setTotalArchiveCount(long totalArchiveCount) {
141144
this.totalArchiveCount = totalArchiveCount;
142145
}
146+
147+
public long getMaxStatsAge() {
148+
return maxStatsAge;
149+
}
150+
151+
public void setMaxStatsAge(long maxStatsAge) {
152+
this.maxStatsAge = maxStatsAge;
153+
}
143154

144155
@Override
145156
public StatisticData clone() {
@@ -157,6 +168,7 @@ public StatisticData clone() {
157168
clone.totalArchiveCount = totalArchiveCount;
158169
clone.userWorkspaceSizeQuota = userWorkspaceSizeQuota;
159170

171+
clone.maxStatsAge = maxStatsAge;
160172
clone.generated = new Date(generated.getTime());
161173

162174
return clone;

src/main/webapp/WEB-INF/Index.jsp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,114 @@
137137
This is a web based interface to read, create, modify, and share CombineArchives. <br />
138138
<strong>We are not responsible for any loss of data.</strong>
139139
</p>
140+
141+
<div class="stats-div"></div>
140142
</div>
141143
<!-- **** -->
144+
<div id="template-stats">
145+
<h2>Statistics</h2>
146+
<div class="stats-par">
147+
148+
{{# if( stats.generated != undefined ) { }}
149+
<div class="stats-line stat-generated">
150+
<div class="attribute-name">timestamp:</div>
151+
<div class="attribute-detail">{{# print( new XDate(stats.generated).toLocaleString() ); }}</div>
152+
<div class="clearer"></div>
153+
</div>
154+
{{# } }}
155+
156+
{{# if( stats.averageArchiveCount != undefined ) { }}
157+
<div class="stats-line stat-averageArchiveCount">
158+
<div class="attribute-name">average archives per workspace:</div>
159+
<div class="attribute-detail">{{# print( Math.round(stats.averageArchiveCount*100)/100 ); }}</div>
160+
<div class="clearer"></div>
161+
</div>
162+
{{# } }}
163+
164+
{{# if( stats.averageArchiveCountQuota != undefined ) { }}
165+
<div class="stats-line stat-averageArchiveCountQuota">
166+
<div class="attribute-name">average usage of 'archives per workspace' quota:</div>
167+
<div class="attribute-detail">{{# print( Math.round(stats.averageArchiveCountQuota*10000)/100 ); }}%</div>
168+
<div class="clearer"></div>
169+
</div>
170+
{{# } }}
171+
172+
{{# if( stats.averageWorkspaceAge != undefined ) { }}
173+
<div class="stats-line stat-averageWorkspaceAge">
174+
<div class="attribute-name">average age of workspace:</div>
175+
<div class="attribute-detail">{{# print( Math.round(stats.averageWorkspaceAge*100)/100 ); }} sec</div>
176+
<div class="clearer"></div>
177+
</div>
178+
{{# } }}
179+
180+
{{# if( stats.averageWorkspaceSize != undefined ) { }}
181+
<div class="stats-line stat-averageWorkspaceSize">
182+
<div class="attribute-name">average size per workspace:</div>
183+
<div class="attribute-detail">{{# print( bytesToSize(Math.round(stats.averageWorkspaceSize*100)/100) ); }}</div>
184+
<div class="clearer"></div>
185+
</div>
186+
{{# } }}
187+
188+
{{# if( stats.averageWorkspaceSizeQuota != undefined ) { }}
189+
<div class="stats-line stat-averageWorkspaceSizeQuota">
190+
<div class="attribute-name">average usage of 'size per workspace' quota:</div>
191+
<div class="attribute-detail">{{# print( Math.round(stats.averageWorkspaceSizeQuota*10000)/100 ); }}%</div>
192+
<div class="clearer"></div>
193+
</div>
194+
{{# } }}
195+
196+
{{# if( stats.totalArchiveCount != undefined ) { }}
197+
<div class="stats-line stat-totalArchiveCount">
198+
<div class="attribute-name">total number of hosted archives:</div>
199+
<div class="attribute-detail">{{# print(stats.totalArchiveCount); }}</div>
200+
<div class="clearer"></div>
201+
</div>
202+
{{# } }}
203+
204+
{{# if( stats.totalSize != undefined ) { }}
205+
<div class="stats-line stat-totalSize">
206+
<div class="attribute-name">total size of all hosted archives:</div>
207+
<div class="attribute-detail">{{# print( bytesToSize(stats.totalSize) ); }}</div>
208+
<div class="clearer"></div>
209+
</div>
210+
{{# } }}
211+
212+
{{# if( stats.totalSizeQuota != undefined ) { }}
213+
<div class="stats-line stat-totalSizeQuota">
214+
<div class="attribute-name">usage of 'total size' quota:</div>
215+
<div class="attribute-detail">{{# print( Math.round(stats.totalSizeQuota*10000)/100 ); }}%</div>
216+
<div class="clearer"></div>
217+
</div>
218+
{{# } }}
219+
220+
{{# if( stats.totalWorkspaceCount != undefined ) { }}
221+
<div class="stats-line stat-totalWorkspaceCount">
222+
<div class="attribute-name">total number of hosted workspaces:</div>
223+
<div class="attribute-detail">{{# print(stats.totalWorkspaceCount); }}</div>
224+
<div class="clearer"></div>
225+
</div>
226+
{{# } }}
227+
228+
{{# if( stats.userArchiveCountQuota != undefined ) { }}
229+
<div class="stats-line stat-userArchiveCountQuota">
230+
<div class="attribute-name">usage of 'archives per workspace' quota:</div>
231+
<div class="attribute-detail">{{# print( Math.round(stats.userArchiveCountQuota*10000)/100 ); }}%</div>
232+
<div class="clearer"></div>
233+
</div>
234+
{{# } }}
235+
236+
{{# if( stats.userWorkspaceSizeQuota != undefined ) { }}
237+
<div class="stats-line stat-userWorkspaceSizeQuota">
238+
<div class="attribute-name">usage of 'workspace size' quota:</div>
239+
<div class="attribute-detail">{{# print( Math.round(stats.userWorkspaceSizeQuota*10000)/100 ); }}%</div>
240+
<div class="clearer"></div>
241+
</div>
242+
{{# } }}
243+
244+
<div class="clearer"></div>
245+
</div>
246+
</div>
247+
<!-- **** -->
142248
<div id="template-create">
143249
<h2>MetaData</h2>
144250
<p>

src/main/webapp/res/css/css.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,17 @@ ul.start-history-list > li.current-workspace {
312312
/* list-style-image: url("listarrow.png"); */
313313
}
314314

315+
/* -------- Stats View -------- */
316+
.stats-line .attribute-name {
317+
width: calc(65% - 5px);
318+
}
319+
.stats-line .attribute-detail {
320+
width: calc(35% - 5px);
321+
}
322+
.stats-par {
323+
margin-bottom: 1.1em;
324+
}
325+
315326
/* -------- Archive View -------- */
316327

317328
a.jstree-anchor > i.jstree-icon {

src/main/webapp/res/js/models.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ var ArchiveEntryCollection = Backbone.Collection.extend({
140140
}
141141
});
142142

143+
var StatsModel = Backbone.Model.extend({
144+
urlRoot: RestRoot + "stats",
145+
defaults: {
146+
"generated": 0
147+
}
148+
});
149+
143150
// views
144151
var NavigationView = Backbone.View.extend({
145152

@@ -1874,10 +1881,59 @@ var CreateView = Backbone.View.extend({
18741881

18751882
});
18761883

1884+
var StatsView = Backbone.View.extend({
1885+
1886+
el: null,
1887+
model: null,
1888+
1889+
initialize: function() {
1890+
this.template = templateCache["template-stats"];
1891+
this.model = new StatsModel();
1892+
this.fetch();
1893+
1894+
// var self = this;
1895+
//setInterval( function() { self.fetch(); }, 10000 );
1896+
},
1897+
render: function() {
1898+
1899+
var json = { "stats": this.model.toJSON() };
1900+
this.$el.html( this.template(json) );
1901+
1902+
// show if not already is shown
1903+
if( this.$el.is(":visible") == false )
1904+
this.$el.fadeIn();
1905+
},
1906+
fetch: function() {
1907+
1908+
if( this.model == null )
1909+
return;
1910+
1911+
var self = this;
1912+
this.model.fetch({
1913+
success: function(model, response, options) {
1914+
self.render();
1915+
setTimeout( function() { self.fetch(); }, model.has("maxStatsAge") ? (model.get("maxStatsAge")+5) * 1000 : 30000 );
1916+
},
1917+
error: function(model, response, options) {
1918+
self.$el.fadeOut();
1919+
if( response.responseJSON !== undefined && response.responseJSON.status == "error" )
1920+
console.log("Error while fetching stats: " + response.responseJSON.errors);
1921+
else
1922+
console.log("Error while fetching stats!");
1923+
}
1924+
});
1925+
1926+
},
1927+
1928+
events: {
1929+
}
1930+
});
1931+
18771932
var StartView = Backbone.View.extend({
18781933

18791934
el: "#start-page",
18801935
collection: null,
1936+
statsView: null,
18811937

18821938
initialize: function() {
18831939
this.template = templateCache["template-start"];
@@ -1889,6 +1945,10 @@ var StartView = Backbone.View.extend({
18891945

18901946
var json = { "history": this.collection.toJSON(), "current": current.toJSON(), "baseUrl": this.getBaseUrl() };
18911947
this.$el.html( this.template(json) );
1948+
1949+
this.statsView = new StatsView({
1950+
el: this.$el.find(".stats-div")
1951+
});
18921952
},
18931953
fetch: function() {
18941954

0 commit comments

Comments
 (0)