[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 * * ?")
|
// @Scheduled(cron = "0 0 0 * * ?")
|
||||||
// // every 5 mins for testing
|
// // every 5 mins for testing
|
||||||
@Scheduled(cron = "0 0/5 * * * *")
|
@Scheduled(cron = "0 0/5 * * * *")
|
||||||
public List<Object> calculateMetrics() {
|
public Metrics calculateMetrics() {
|
||||||
log.info("Calculate metrics and add them in DB");
|
log.info("Calculate metrics and add them in DB");
|
||||||
|
|
||||||
Optional<Metrics> oldMetrics = metricsDAO.findById("current");
|
// Optional<Metrics> oldMetrics = metricsDAO.findById("current");
|
||||||
if(oldMetrics.isPresent()) {
|
// if(oldMetrics.isPresent()) {
|
||||||
oldMetrics.get().setId("previous");
|
// oldMetrics.get().setId("previous");
|
||||||
metricsDAO.save(oldMetrics.get());
|
// metricsDAO.save(oldMetrics.get());
|
||||||
}
|
// }
|
||||||
|
|
||||||
Metrics metrics = new Metrics();
|
Metrics metrics = new Metrics();
|
||||||
metrics.setId("current");
|
metrics.setId("current");
|
||||||
|
@ -96,14 +96,16 @@ public class MetricsService {
|
||||||
Map<String, Integer> works = (HashMap<String, Integer>) totalWorks.get(0);
|
Map<String, Integer> works = (HashMap<String, Integer>) totalWorks.get(0);
|
||||||
metrics.setTotal_works(works.get("works"));
|
metrics.setTotal_works(works.get("works"));
|
||||||
} else {
|
} else {
|
||||||
metrics.setTotal_works(0);
|
metrics.setTotal_works(-1);
|
||||||
|
return metrics;
|
||||||
}
|
}
|
||||||
List<Object> totalUsers = countTotalUniqueUsers();
|
List<Object> totalUsers = countTotalUniqueUsers();
|
||||||
if(totalUsers != null && totalUsers.get(0) != null) {
|
if(totalUsers != null && totalUsers.get(0) != null) {
|
||||||
Map<String, Integer> users = (HashMap<String, Integer>) totalUsers.get(0);
|
Map<String, Integer> users = (HashMap<String, Integer>) totalUsers.get(0);
|
||||||
metrics.setTotal_users(users.get("users"));
|
metrics.setTotal_users(users.get("users"));
|
||||||
} else {
|
} else {
|
||||||
metrics.setTotal_users(0);
|
metrics.setTotal_users(-1);
|
||||||
|
return metrics;
|
||||||
}
|
}
|
||||||
// metrics.setWorks_per_month(countWorksPerYearAndMonth());
|
// metrics.setWorks_per_month(countWorksPerYearAndMonth());
|
||||||
List<Object> works_per_dashboard = countWorksPerDashboard();
|
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
|
// 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 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
|
// 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() {
|
public String getMetrics() {
|
||||||
|
|
Loading…
Reference in New Issue