Skip to content

Commit 16f5dbf

Browse files
committed
updated ui for stats
1 parent b598371 commit 16f5dbf

3 files changed

Lines changed: 44 additions & 58 deletions

File tree

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.Serializable;
44
import java.util.Date;
55

6+
import com.fasterxml.jackson.annotation.JsonIgnore;
67
import com.fasterxml.jackson.annotation.JsonInclude;
78
import com.fasterxml.jackson.annotation.JsonInclude.Include;
89

@@ -43,11 +44,26 @@ public class StatisticData implements Serializable, Cloneable {
4344
// server stuff
4445
private long maxStatsAge = IGNORE_LONG;
4546

47+
// internal stuff
48+
/** if set to true, all stats are returned */
49+
@JsonIgnore
50+
private boolean fullStats = false;
51+
4652
/** Timestamp of generation */
4753
private Date generated = new Date();
4854

4955
public StatisticData() {}
56+
57+
@JsonIgnore
58+
public boolean isFullStats() {
59+
return fullStats;
60+
}
5061

62+
@JsonIgnore
63+
public void setFullStats(boolean fullStats) {
64+
this.fullStats = fullStats;
65+
}
66+
5167
public long getTotalWorkspaceCount() {
5268
return totalWorkspaceCount;
5369
}
@@ -81,31 +97,31 @@ public void setAverageArchiveCount(double averageArchiveCount) {
8197
}
8298

8399
public double getAverageWorkspaceAge() {
84-
return averageWorkspaceAge;
100+
return fullStats ? averageWorkspaceAge : IGNORE_DOUBLE ;
85101
}
86102

87103
public void setAverageWorkspaceAge(double averageWorkspaceAge) {
88104
this.averageWorkspaceAge = averageWorkspaceAge;
89105
}
90106

91107
public double getTotalSizeQuota() {
92-
return totalSizeQuota;
108+
return fullStats ? totalSizeQuota : IGNORE_DOUBLE ;
93109
}
94110

95111
public void setTotalSizeQuota(double totalSizeQuota) {
96112
this.totalSizeQuota = totalSizeQuota;
97113
}
98114

99115
public double getAverageWorkspaceSizeQuota() {
100-
return averageWorkspaceSizeQuota;
116+
return fullStats ? averageWorkspaceSizeQuota : IGNORE_DOUBLE ;
101117
}
102118

103119
public void setAverageWorkspaceSizeQuota(double averageWorkspaceSizeQuota) {
104120
this.averageWorkspaceSizeQuota = averageWorkspaceSizeQuota;
105121
}
106122

107123
public double getAverageArchiveCountQuota() {
108-
return averageArchiveCountQuota;
124+
return fullStats ? averageArchiveCountQuota : IGNORE_DOUBLE ;
109125
}
110126

111127
public void setAverageArchiveCountQuota(double averageArchiveCountQuota) {

src/main/java/de/unirostock/sems/cbarchive/web/rest/RestApi.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import javax.ws.rs.Path;
4444
import javax.ws.rs.PathParam;
4545
import javax.ws.rs.Produces;
46+
import javax.ws.rs.QueryParam;
4647
import javax.ws.rs.core.MediaType;
4748
import javax.ws.rs.core.NewCookie;
4849
import javax.ws.rs.core.Response;
@@ -177,17 +178,27 @@ public Response storeSettings( @CookieParam(Fields.COOKIE_PATH) String userPath,
177178
@GET
178179
@Path("/stats")
179180
@Produces( MediaType.APPLICATION_JSON )
180-
public Response getStats( @CookieParam(Fields.COOKIE_PATH) String userPath ) {
181+
public Response getStats( @CookieParam(Fields.COOKIE_PATH) String userPath, @QueryParam("secret") String secret ) {
181182
// user stuff
182183
UserManager user = null;
183184
try {
184-
user = new UserManager( userPath );
185+
if( userPath != null && !userPath.isEmpty() )
186+
user = new UserManager( userPath );
185187
} catch (IOException e) {
186188
LOGGER.error(e, "Cannot create user");
187189
return buildErrorResponse(500, null, "user not creatable!", e.getMessage() );
188190
}
189191

190-
StatisticData stats = QuotaManager.getInstance().getUserStats(user);
192+
StatisticData stats = null;
193+
if( user != null )
194+
stats = QuotaManager.getInstance().getUserStats(user);
195+
else
196+
stats = QuotaManager.getInstance().getStats();
197+
198+
// if secret is corret -> enable full stats
199+
if( secret != null && Fields.STATS_SECRET != null && secret.equals(Fields.STATS_SECRET) )
200+
stats.setFullStats(true);
201+
191202
return buildResponse(200, user).entity(stats).build();
192203
}
193204

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

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -158,44 +158,27 @@
158158
<div class="clearer"></div>
159159
</div>
160160
{{# } }}
161-
162-
{{# if( stats.averageArchiveCount != undefined && !isNaN(stats.averageArchiveCount) ) { }}
163-
<div class="stats-line stat-averageArchiveCount">
164-
<div class="attribute-name">average archives per workspace:</div>
165-
<div class="attribute-detail">{{# print( Math.round(stats.averageArchiveCount*100)/100 ); }}</div>
166-
<div class="clearer"></div>
167-
</div>
168-
{{# } }}
169161

170-
{{# if( stats.averageArchiveCountQuota != undefined && !isNaN(stats.averageArchiveCountQuota) ) { }}
171-
<div class="stats-line stat-averageArchiveCountQuota">
172-
<div class="attribute-name">average usage of 'archives per workspace' quota:</div>
173-
<div class="attribute-detail">{{# print( Math.round(stats.averageArchiveCountQuota*10000)/100 ); }}%</div>
174-
<div class="clearer"></div>
175-
</div>
176-
{{# } }}
177-
178-
{{# if( stats.averageWorkspaceAge != undefined && !isNaN(stats.averageWorkspaceAge) ) { }}
179-
{{# var avgAge = stats.averageWorkspaceAge/3600; }}
180-
<div class="stats-line stat-averageWorkspaceAge">
181-
<div class="attribute-name">average age of workspace:</div>
182-
<div class="attribute-detail">{{# print( Math.round(avgAge*100)/100 ); }}h</div>
162+
{{# if( stats.totalWorkspaceCount != undefined && !isNaN(stats.totalWorkspaceCount) ) { }}
163+
<div class="stats-line stat-totalWorkspaceCount">
164+
<div class="attribute-name">total number of hosted workspaces:</div>
165+
<div class="attribute-detail">{{# print(stats.totalWorkspaceCount); }}</div>
183166
<div class="clearer"></div>
184167
</div>
185168
{{# } }}
186169

187170
{{# if( stats.averageWorkspaceSize != undefined && !isNaN(stats.averageWorkspaceSize) ) { }}
188171
<div class="stats-line stat-averageWorkspaceSize">
189-
<div class="attribute-name">average size per workspace:</div>
172+
<div class="attribute-name">average size of a workspace:</div>
190173
<div class="attribute-detail">{{# print( bytesToSize(Math.round(stats.averageWorkspaceSize*100)/100) ); }}</div>
191174
<div class="clearer"></div>
192175
</div>
193176
{{# } }}
194177

195-
{{# if( stats.averageWorkspaceSizeQuota != undefined && !isNaN(stats.averageWorkspaceSizeQuota) ) { }}
196-
<div class="stats-line stat-averageWorkspaceSizeQuota">
197-
<div class="attribute-name">average usage of 'size per workspace' quota:</div>
198-
<div class="attribute-detail">{{# print( Math.round(stats.averageWorkspaceSizeQuota*10000)/100 ); }}%</div>
178+
{{# if( stats.averageArchiveCount != undefined && !isNaN(stats.averageArchiveCount) ) { }}
179+
<div class="stats-line stat-averageArchiveCount">
180+
<div class="attribute-name">average number of archives per workspace:</div>
181+
<div class="attribute-detail">{{# print( Math.round(stats.averageArchiveCount*100)/100 ); }}</div>
199182
<div class="clearer"></div>
200183
</div>
201184
{{# } }}
@@ -216,33 +199,9 @@
216199
</div>
217200
{{# } }}
218201

219-
{{# if( stats.totalSizeQuota != undefined && !isNaN(stats.totalSizeQuota) ) { }}
220-
<div class="stats-line stat-totalSizeQuota">
221-
<div class="attribute-name">usage of 'total size' quota:</div>
222-
<div class="attribute-detail">{{# print( Math.round(stats.totalSizeQuota*10000)/100 ); }}%</div>
223-
<div class="clearer"></div>
224-
</div>
225-
{{# } }}
226-
227-
{{# if( stats.totalWorkspaceCount != undefined && !isNaN(stats.totalWorkspaceCount) ) { }}
228-
<div class="stats-line stat-totalWorkspaceCount">
229-
<div class="attribute-name">total number of hosted workspaces:</div>
230-
<div class="attribute-detail">{{# print(stats.totalWorkspaceCount); }}</div>
231-
<div class="clearer"></div>
232-
</div>
233-
{{# } }}
234-
235-
{{# if( stats.userArchiveCountQuota != undefined && !isNaN(stats.userArchiveCountQuota) ) { }}
236-
<div class="stats-line stat-userArchiveCountQuota">
237-
<div class="attribute-name">usage of 'archives per workspace' quota:</div>
238-
<div class="attribute-detail">{{# print( Math.round(stats.userArchiveCountQuota*10000)/100 ); }}%</div>
239-
<div class="clearer"></div>
240-
</div>
241-
{{# } }}
242-
243202
{{# if( stats.userWorkspaceSizeQuota != undefined && !isNaN(stats.userWorkspaceSizeQuota) ) { }}
244203
<div class="stats-line stat-userWorkspaceSizeQuota">
245-
<div class="attribute-name">usage of 'workspace size' quota:</div>
204+
<div class="attribute-name">space usage of this workspace:</div>
246205
<div class="attribute-detail">{{# print( Math.round(stats.userWorkspaceSizeQuota*10000)/100 ); }}%</div>
247206
<div class="clearer"></div>
248207
</div>

0 commit comments

Comments
 (0)