[Trunk | Orcid Service]: MetricsService.java: a. Do not save in DB previous metrics (only current) | b. If one metric query does not respond correctly, do not update metrics.
This commit is contained in:
parent
2273f3c295
commit
ca6f47e7d6
|
@ -80,14 +80,14 @@ public class MetricsService {
|
|||
// @Scheduled(cron = "0 0 0 * * ?")
|
||||
// // every 5 mins for testing
|
||||
@Scheduled(cron = "0 0/5 * * * *")
|
||||
public List<Object> calculateMetrics() {
|
||||
public Metrics calculateMetrics() {
|
||||
log.info("Calculate metrics and add them in DB");
|
||||
|
||||
Optional<Metrics> oldMetrics = metricsDAO.findById("current");
|
||||
if(oldMetrics.isPresent()) {
|
||||
oldMetrics.get().setId("previous");
|
||||
metricsDAO.save(oldMetrics.get());
|
||||
}
|
||||
// Optional<Metrics> oldMetrics = metricsDAO.findById("current");
|
||||
// if(oldMetrics.isPresent()) {
|
||||
// oldMetrics.get().setId("previous");
|
||||
// metricsDAO.save(oldMetrics.get());
|
||||
// }
|
||||
|
||||
Metrics metrics = new Metrics();
|
||||
metrics.setId("current");
|
||||
|
@ -96,14 +96,16 @@ public class MetricsService {
|
|||
Map<String, Integer> works = (HashMap<String, Integer>) totalWorks.get(0);
|
||||
metrics.setTotal_works(works.get("works"));
|
||||
} else {
|
||||
metrics.setTotal_works(0);
|
||||
metrics.setTotal_works(-1);
|
||||
return metrics;
|
||||
}
|
||||
List<Object> totalUsers = countTotalUniqueUsers();
|
||||
if(totalUsers != null && totalUsers.get(0) != null) {
|
||||
Map<String, Integer> users = (HashMap<String, Integer>) totalUsers.get(0);
|
||||
metrics.setTotal_users(users.get("users"));
|
||||
} else {
|
||||
metrics.setTotal_users(0);
|
||||
metrics.setTotal_users(-1);
|
||||
return metrics;
|
||||
}
|
||||
// metrics.setWorks_per_month(countWorksPerYearAndMonth());
|
||||
List<Object> works_per_dashboard = countWorksPerDashboard();
|
||||
|
@ -125,7 +127,7 @@ public class MetricsService {
|
|||
// Total users: (unique/ per orcid): http://duffy.di.uoa.gr:8080/uoa-orcid-service/report/totalUniqueUsers
|
||||
// Works linked per month: http://duffy.di.uoa.gr:8080/uoa-orcid-service/report/worksPerYearAndMonth (not needed?)
|
||||
// Works linked per portal (not only explore): http://duffy.di.uoa.gr:8080/uoa-orcid-service/report/worksPerDashboard
|
||||
return totalWorks;
|
||||
return metrics;
|
||||
}
|
||||
|
||||
public String getMetrics() {
|
||||
|
|
Loading…
Reference in New Issue