Add number on stats

This commit is contained in:
Panagiotis Kanakakis 2018-09-14 11:55:35 +00:00
parent 54f0546fe0
commit 7e3c8194d5
1 changed files with 23 additions and 2 deletions

View File

@ -1,5 +1,6 @@
package eu.dnetlib.repo.manager.service.controllers;
import com.mongodb.util.JSON;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
@ -72,7 +73,8 @@ public class StatsApiImpl implements StatsApi {
String publications = getTotalByType("other",baseAddress,"/publications/count");
String datasets = getTotalByType("other",baseAddress,"/datasets/count");
String software = getTotalByType("other",baseAddress,"/software/count");
JSONObject usagestats = getUsageStatsTotal();
JSONObject lastYearUsagestats = getLastYearUsageStatsTotal();
Integer usagestats = getUsageStatsTotal();
HashMap<String,Object> stats = new HashMap<>();
@ -85,6 +87,7 @@ public class StatsApiImpl implements StatsApi {
stats.put("datasets",datasets);
stats.put("software",software);
stats.put("lastYearUsagestats",lastYearUsagestats.toString());
stats.put("usagestats",usagestats.toString());
@ -110,7 +113,8 @@ public class StatsApiImpl implements StatsApi {
}
private JSONObject getUsageStatsTotal() throws JSONException {
private JSONObject getLastYearUsageStatsTotal() throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(usagestatsBaseAddress + "/totals")
.build().encode();
@ -129,5 +133,22 @@ public class StatsApiImpl implements StatsApi {
usagestats.put("year",year);
return usagestats;
}
private Integer getUsageStatsTotal() throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(usagestatsBaseAddress + "/totals")
.build().encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
JSONObject resultSet = new JSONObject(rs);
String downloads = resultSet.getString("downloads");
String views = resultSet.getString("views");
return Integer.valueOf(downloads) + Integer.valueOf(views);
}
}