From e0086001890cbed86f6c540df7ebde7afbd3c2bf Mon Sep 17 00:00:00 2001 From: matthew-a-dunlap Date: Tue, 15 Jan 2019 16:16:50 -0500 Subject: [PATCH] Bugfix metrics load & metrics no-guestbook. Wire in metrics #5445 #5447 --- .../branding/custom-homepage-dynamic.html | 50 ++++++++++++------- .../dataverse/metrics/MetricsServiceBean.java | 41 ++++++++------- 2 files changed, 55 insertions(+), 36 deletions(-) diff --git a/doc/sphinx-guides/source/_static/installation/files/var/www/dataverse/branding/custom-homepage-dynamic.html b/doc/sphinx-guides/source/_static/installation/files/var/www/dataverse/branding/custom-homepage-dynamic.html index 76b4b277d79..d943ada57ae 100644 --- a/doc/sphinx-guides/source/_static/installation/files/var/www/dataverse/branding/custom-homepage-dynamic.html +++ b/doc/sphinx-guides/source/_static/installation/files/var/www/dataverse/branding/custom-homepage-dynamic.html @@ -161,18 +161,18 @@
All
-
5,640,188
-
66,177
+
+
Deposited
-
5,000,000
-
60,177
+
+
Harvested
-
640,188
-
6,177
+
+
@@ -188,18 +188,18 @@
All
-
5,640,188
-
66,177
+
+
Deposited
-
5,000,000
-
60,177
+
+
Harvested
-
640,188
-
6,177
+
+
@@ -300,8 +300,7 @@ dvArray.push([item.subject, item.count/*.toLocaleString('en')*/]); } }); - }); - $.get(metricBaseUrl + "datasets/bySubject?dataLocation=all", function(jData) { + $.get(metricBaseUrl + "datasets/bySubject?dataLocation=all", function(jData) { //var subArray = []; var resultHtml = ""; jData.data.forEach(function(item) { @@ -322,16 +321,29 @@ }); document.getElementById(elm).innerHTML = resultHtml; }); + }); + } writeRecentDatasetsInDataverses("(Journal)" , 3, "journals"); writeRecentDatasetsInDataverses("(\"Research+Project\"%20OR%20Researcher%20OR%20\"Research+Group\")" , 6, "researchers"); - queryMetricSimple("datasets", "", "activityAllTimeDatasetsValue"); - queryMetricSimple("downloads", "", "activityAllTimeFilesValue"); - - queryMetricSimple("datasets/pastDays", "/30", "activity30DaysDatasetsValue"); - queryMetricSimple("downloads/pastDays", "/30", "activity30DaysFilesValue"); + queryMetricSimple("datasets", "", "activityAllTimeAllDatasetsValue"); + queryMetricSimple("datasets/pastDays", "/30", "activity30DaysAllDatasetsValue"); + queryMetricSimple("datasets", "?dataLocation=local", "activityAllTimeDepositedDatasetsValue"); + queryMetricSimple("datasets/pastDays", "/30?dataLocation=local", "activity30DaysDepositedDatasetsValue"); + queryMetricSimple("datasets", "?dataLocation=remote", "activityAllTimeHarvestedDatasetsValue"); + queryMetricSimple("datasets/pastDays", "/30?dataLocation=remote", "activity30DaysHarvestedDatasetsValue"); + + queryMetricSimple("downloads", "", "activityAllTimeAllFilesValue"); + queryMetricSimple("downloads/pastDays", "/30", "activity30DaysAllFilesValue"); + queryMetricSimple("downloads", "?dataLocation=local", "activityAllTimeDepositedFilesValue"); + queryMetricSimple("downloads/pastDays", "/30?dataLocation=local", "activity30DaysDepositedFilesValue"); + queryMetricSimple("downloads", "?dataLocation=remote", "activityAllTimeHarvestedFilesValue"); + queryMetricSimple("downloads/pastDays", "/30?dataLocation=remote", "activity30DaysHarvestedFilesValue"); + +// queryMetricSimple("downloads/pastDays", "/30", "activity30DaysFilesValue"); +// queryMetricSimple("downloads", "", "activityAllTimeFilesValue"); //querySubject("dataversesBySubject"); querySubjectDataverseDataset("dataversesBySubject") diff --git a/src/main/java/edu/harvard/iq/dataverse/metrics/MetricsServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/metrics/MetricsServiceBean.java index 926e8cc20e7..743ec21eb88 100644 --- a/src/main/java/edu/harvard/iq/dataverse/metrics/MetricsServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/metrics/MetricsServiceBean.java @@ -16,6 +16,7 @@ import javax.ejb.EJB; import javax.ejb.Stateless; import javax.persistence.EntityManager; +import javax.persistence.NoResultException; import javax.persistence.NonUniqueResultException; import javax.persistence.PersistenceContext; import javax.persistence.Query; @@ -260,25 +261,31 @@ public long downloadsToMonth(String yyyymm) throws Exception { + "ORDER BY responsetime LIMIT 1;" ); - Timestamp earlyDateTimestamp = (Timestamp) earlyDateQuery.getSingleResult(); - Date earliestDate = new Date(earlyDateTimestamp.getTime()); - SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM"); - Date dateQueried = formatter2.parse(yyyymm); - - if(!dateQueried.before(earliestDate)) { - Query query = em.createNativeQuery("" - + "select count(id)\n" - + "from guestbookresponse\n" - + "where date_trunc('month', responsetime) <= to_date('" + yyyymm + "','YYYY-MM')" - + "or responsetime is NULL;" //includes historic guestbook records without date - ); - logger.fine("query: " + query); - return (long) query.getSingleResult(); - } - else { - //When we query before the earliest dated record, return 0; + try { + Timestamp earlyDateTimestamp = (Timestamp) earlyDateQuery.getSingleResult(); + Date earliestDate = new Date(earlyDateTimestamp.getTime()); + SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM"); + Date dateQueried = formatter2.parse(yyyymm); + + if(!dateQueried.before(earliestDate)) { + Query query = em.createNativeQuery("" + + "select count(id)\n" + + "from guestbookresponse\n" + + "where date_trunc('month', responsetime) <= to_date('" + yyyymm + "','YYYY-MM')" + + "or responsetime is NULL;" //includes historic guestbook records without date + ); + logger.fine("query: " + query); + return (long) query.getSingleResult(); + } + else { + //When we query before the earliest dated record, return 0; + return 0L; + } + } catch(NoResultException e) { + //If earlyDateQuery.getSingleResult is null, then there are no guestbooks and we can return 0 return 0L; } + }