diff --git a/src/main/java/eu/dnetlib/usagestats/UsageStatsApi.java b/src/main/java/eu/dnetlib/usagestats/UsageStatsApi.java
old mode 100644
new mode 100755
diff --git a/src/main/java/eu/dnetlib/usagestats/config/DataSourceConfiguration.java b/src/main/java/eu/dnetlib/usagestats/config/DataSourceConfiguration.java
old mode 100644
new mode 100755
diff --git a/src/main/java/eu/dnetlib/usagestats/config/SpringRedisConfiguration.java b/src/main/java/eu/dnetlib/usagestats/config/SpringRedisConfiguration.java
old mode 100644
new mode 100755
diff --git a/src/main/java/eu/dnetlib/usagestats/config/WebMvcConfiguration.java b/src/main/java/eu/dnetlib/usagestats/config/WebMvcConfiguration.java
old mode 100644
new mode 100755
diff --git a/src/main/java/eu/dnetlib/usagestats/controllers/SushiLiteController.java b/src/main/java/eu/dnetlib/usagestats/controllers/SushiLiteController.java
index a1dd237..9357d94 100755
--- a/src/main/java/eu/dnetlib/usagestats/controllers/SushiLiteController.java
+++ b/src/main/java/eu/dnetlib/usagestats/controllers/SushiLiteController.java
@@ -2,11 +2,14 @@ package eu.dnetlib.usagestats.controllers;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.usagestats.services.SushiLiteService;
+import eu.dnetlib.usagestats.sushilite.domain.SUSHI_Error_Model;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
@@ -92,8 +95,11 @@ class SushiLiteController {
if (report.indexOf(".zip") < 0) {
return new ResponseEntity<>(report, HttpStatus.OK);
} else {
-
- String compressedOutput = " {\"Report\":\"IR\", \"Description\":\"Compressed Report Due to large number of records\", \"URL To Download Report from: \":\"" + report + "\"}
";
+ ObjectMapper objectMapper = new ObjectMapper();
+ //String compressedOutput = " {\"Report\":\"IR\", \"Description\":\"Compressed Report Due to large number of records\", \"URL To Download Report from: \":\"" + report + "\"}
";
+ SUSHI_Error_Model errorModel = new SUSHI_Error_Model("100000", "Notice", "Compressed IR report due to a large number of records",
+ null, report);
+ String compressedOutput = "" + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorModel) + "
";
return new ResponseEntity<>(compressedOutput, HttpStatus.OK);
}
}
diff --git a/src/main/java/eu/dnetlib/usagestats/controllers/UsageStatsController.java b/src/main/java/eu/dnetlib/usagestats/controllers/UsageStatsController.java
old mode 100644
new mode 100755
index ac9b694..24f5dd9
--- a/src/main/java/eu/dnetlib/usagestats/controllers/UsageStatsController.java
+++ b/src/main/java/eu/dnetlib/usagestats/controllers/UsageStatsController.java
@@ -11,11 +11,7 @@ import eu.dnetlib.usagestats.portal.UsageStats;
import eu.dnetlib.usagestats.services.UsageStatsService;
import java.util.List;
import org.apache.log4j.Logger;
-import org.springframework.web.bind.annotation.CrossOrigin;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
@RestController
@@ -93,6 +89,12 @@ public class UsageStatsController {
return usageStatsService.getResultClicks(resultId);
}
+ @RequestMapping(value = "/resultspid", method = RequestMethod.GET)
+ public UsageStats getResultClicksByPID(@RequestParam(value = "doi", defaultValue = "") String doi) {
+ log.info("stats request for pid: " + doi);
+ return usageStatsService.getResultClicksByPID(doi);
+ }
+
@RequestMapping(value = "/allmetrics")
public TotalStatsReposViewsDownloads getTotalStatsReposViewsDownloads() {
log.info("total stats request");
diff --git a/src/main/java/eu/dnetlib/usagestats/portal/CountryRepositories.java b/src/main/java/eu/dnetlib/usagestats/portal/CountryRepositories.java
old mode 100644
new mode 100755
diff --git a/src/main/java/eu/dnetlib/usagestats/portal/CountryUsageStats.java b/src/main/java/eu/dnetlib/usagestats/portal/CountryUsageStats.java
old mode 100644
new mode 100755
diff --git a/src/main/java/eu/dnetlib/usagestats/portal/CountryUsageStatsAll.java b/src/main/java/eu/dnetlib/usagestats/portal/CountryUsageStatsAll.java
old mode 100644
new mode 100755
diff --git a/src/main/java/eu/dnetlib/usagestats/portal/MonthlyStats.java b/src/main/java/eu/dnetlib/usagestats/portal/MonthlyStats.java
old mode 100644
new mode 100755
diff --git a/src/main/java/eu/dnetlib/usagestats/portal/MonthlyUsageStats.java b/src/main/java/eu/dnetlib/usagestats/portal/MonthlyUsageStats.java
old mode 100644
new mode 100755
diff --git a/src/main/java/eu/dnetlib/usagestats/portal/RepositoryStats.java b/src/main/java/eu/dnetlib/usagestats/portal/RepositoryStats.java
old mode 100644
new mode 100755
diff --git a/src/main/java/eu/dnetlib/usagestats/portal/TotalStats.java b/src/main/java/eu/dnetlib/usagestats/portal/TotalStats.java
old mode 100644
new mode 100755
diff --git a/src/main/java/eu/dnetlib/usagestats/portal/TotalStatsReposViewsDownloads.java b/src/main/java/eu/dnetlib/usagestats/portal/TotalStatsReposViewsDownloads.java
old mode 100644
new mode 100755
diff --git a/src/main/java/eu/dnetlib/usagestats/portal/UsageStats.java b/src/main/java/eu/dnetlib/usagestats/portal/UsageStats.java
old mode 100644
new mode 100755
diff --git a/src/main/java/eu/dnetlib/usagestats/portal/YearlyStats.java b/src/main/java/eu/dnetlib/usagestats/portal/YearlyStats.java
old mode 100644
new mode 100755
diff --git a/src/main/java/eu/dnetlib/usagestats/repositories/UsageStatsRepository.java b/src/main/java/eu/dnetlib/usagestats/repositories/UsageStatsRepository.java
index 8d47b1a..f55ad9b 100755
--- a/src/main/java/eu/dnetlib/usagestats/repositories/UsageStatsRepository.java
+++ b/src/main/java/eu/dnetlib/usagestats/repositories/UsageStatsRepository.java
@@ -781,9 +781,17 @@ public class UsageStatsRepository {
while (rs.next()) {
if (repositoryIdentifier != null) {
- executeBatchItemsDSR(reportItems, repositoryIdentifier, rs.getString(1), beginDate, endDate, metricType, granularity);
+ if (checkIfDatacite(repositoryIdentifier)) {
+ executeBatchItemsDSRDatacite(reportItems, repositoryIdentifier, rs.getString(1), beginDate, endDate, metricType, granularity);
+ } else {
+ executeBatchItemsDSR(reportItems, repositoryIdentifier, rs.getString(1), beginDate, endDate, metricType, granularity);
+ }
} else {
- executeItemsAllRepoDSR(reportItems, rs.getString(1), beginDate, endDate, metricType, granularity);
+// if (checkIfDatacite(repositoryIdentifier)) {
+// executeItemsAllRepoDSRDatacite(reportItems, rs.getString(1), beginDate, endDate, metricType, granularity);
+// } else {
+ executeItemsAllRepoDSR(reportItems, rs.getString(1), beginDate, endDate, metricType, granularity);
+// }
}
}
} catch (Exception e) {
@@ -814,9 +822,17 @@ public class UsageStatsRepository {
while (rs.next()) {
if (repositoryIdentifier != null) {
- executeBatchItemsDSR(reportItems, repositoryIdentifier, rs.getString(1), beginDate, endDate, metricType, granularity);
+ if (checkIfDatacite(repositoryIdentifier)) {
+ executeBatchItemsDSRDatacite(reportItems, repositoryIdentifier, rs.getString(1), beginDate, endDate, metricType, granularity);
+ } else {
+ executeBatchItemsDSR(reportItems, repositoryIdentifier, rs.getString(1), beginDate, endDate, metricType, granularity);
+ }
} else {
- executeItemsAllRepoDSR(reportItems, rs.getString(1), beginDate, endDate, metricType, granularity);
+// if (checkIfDatacite(repositoryIdentifier)) {
+// executeItemsAllRepoDSRDatacite(reportItems, rs.getString(1), beginDate, endDate, metricType, granularity);
+// } else {
+ executeItemsAllRepoDSR(reportItems, rs.getString(1), beginDate, endDate, metricType, granularity);
+// }
}
}
} catch (Exception e) {
@@ -847,9 +863,11 @@ public class UsageStatsRepository {
connection = usageStatsDB.getConnection();
if (granularity.equalsIgnoreCase("totals")) {
if (dataType.equals("") || dataType.equals("All")) {
- st = connection.prepareStatement("SELECT rc.type, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, "
+ st = connection.prepareStatement("SELECT rc.type, sum(us.total_item_requests) as total_item_requests, "
+ +"sum(us.total_item_investigations) as total_item_investigations, "
+ +"sum(us.unique_item_requests) as unique_item_requests, "
+ +"sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us, "
+ statsDB + ".result_classifications rc WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND rc.id=us.result_id GROUP BY rc.type order by rc.type ASC;");
st.setString(1, beginDateStr);
@@ -879,9 +897,11 @@ public class UsageStatsRepository {
}
} else {
- st = connection.prepareStatement("SELECT rc.type, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, "
+ st = connection.prepareStatement("SELECT rc.type, sum(us.total_item_requests) as total_item_requests, "
+ +"sum(us.total_item_investigations) as total_item_investigations, "
+ +"sum(us.unique_item_requests) as unique_item_requests, "
+ +"sum(us.unique_item_investigations) as unique_item_investigations "
+ +"FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us, "
+ statsDB + ".result_classifications rc WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND rc.type=? AND rc.id=us.result_id GROUP BY rc.type order by rc.type ASC;");
st.setString(1, beginDateStr);
@@ -916,9 +936,11 @@ public class UsageStatsRepository {
}
} else if (granularity.equalsIgnoreCase("monthly")) {
if (dataType.equals("") || dataType.equals("All")) {
- st = connection.prepareStatement("SELECT rc.type, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, "
+ st = connection.prepareStatement("SELECT rc.type, us.`date`, sum(us.total_item_requests) as total_item_requests, "
+ +"sum(us.total_item_investigations) as total_item_investigations, "
+ +"sum(us.unique_item_requests) as unique_item_requests, "
+ +"sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us, "
+ statsDB + ".result_classifications rc WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND rc.id=us.result_id GROUP BY rc.type, us.`date` order by rc.type, us.`date` ASC;");
st.setString(1, beginDateStr);
@@ -980,9 +1002,11 @@ public class UsageStatsRepository {
//add last report item
reportItems.add(reportItem);
} else {
- st = connection.prepareStatement("SELECT rc.type, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, "
+ st = connection.prepareStatement("SELECT rc.type, us.`date`, sum(us.total_item_requests) as total_item_requests, "
+ +"sum(us.total_item_investigations) as total_item_investigations, "
+ +"sum(us.unique_item_requests) as unique_item_requests, "
+ +"sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us, "
+ statsDB + ".result_classifications rc WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND rc.type=? AND rc.id=us.result_id GROUP BY rc.type, us.`date` order by rc.type, us.`date` ASC;");
st.setString(1, beginDateStr);
@@ -1075,9 +1099,11 @@ public class UsageStatsRepository {
try {
connection = usageStatsDB.getConnection();
- st = connection.prepareStatement("SELECT us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us "
+ st = connection.prepareStatement("SELECT us.`date`, sum(us.total_item_requests) as total_item_requests, "
+ +"sum(us.total_item_investigations) as total_item_investigations, "
+ +"sum(us.unique_item_requests) as unique_item_requests, "
+ +"sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us "
+ "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? GROUP BY us.`date` order by us.`date` ASC;");
st.setString(1, beginDateStr);
@@ -1152,35 +1178,17 @@ public class UsageStatsRepository {
if (granularity.equalsIgnoreCase("totals")) {
if (dataType.equals("")) {
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND rc.id=us.result_id AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id "
- + "GROUP BY rc.type, rs.title, us.result_id, rs.title, rs.year order by rc.type ASC;");
-//WITH tpd as (select distinct id, concat(type,'#-#',pid) type_id from openaire_prod_stats.result_pids)
-//select type, downloads, views, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, uniquedownloads,uniqueviews
-//FROM (SELECT us.repository_id repo, rc.type type, sum(us.downloads) as downloads, sum(us.views) as views,
-//us.result_id as resultid, rs.title as item, rs.year as yop,
-//count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews
-//FROM openaire_prod_usage_stats.usage_stats us,(select distinct id, type from openaire_prod_stats.result_classifications) rc, openaire_prod_stats.result rs
-//WHERE us.`date`>='2020/01' AND us.`date`<='2020/02'
-//AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id='opendoar____::8e98d81f8217304975ccb23337bb5761'
-//GROUP BY rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp1, tpd
-//where tpd.id=resultid
-//group by repo,type,resultid,item,yop,downloads,views,uniquedownloads,uniqueviews
-
-//SELECT 'Dataset' as type, sum(case when dp.metric_type='total-dataset-requests' then count else 0 end) as downloads,
-//sum(case when dp.metric_type='total-dataset-investigations' then count else 0 end) as views,
-//id as resultid,dp.ds_title as item, dp.yop as yop, concat('Digital Object Identifier#-#',dp.ds_type) as oid,
-//sum(case when dp.metric_type='unique-dataset-requests' then count else 0 end) as uniquedownloads,
-//sum(case when dp.metric_type='unique-dataset-investigations' then count else 0 end) as uniqueviews,
-//dp.access_method access_method,dp.platform
-//FROM datasetsusagestats_20210312a.datasetsperformance dp, openaire_prod_stats.result_pids
-//WHERE dp.period_from>='2020-01-01' AND dp.period_end<='2020-12-01' and pid=ds_type
-//GROUP BY dp.ds_title, dp.yop, dp.platform, dp.access_method, dp.ds_type,id
+ st = connection.prepareStatement("WITH tpd as (SELECT distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, total_item_requests, total_item_investigations, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, unique_item_requests,unique_item_investigations "
+ + "FROM (SELECT us.repository_id repo, rc.type type, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+ + "sum(us.unique_item_requests) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us,(SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, "
+ + "openaire_prod_stats.result rs "
+ + "WHERE us.`date`>=? AND us.`date`<=? "
+ + "AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id=? "
+ + "GROUP BY rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp, tpd "
+ + "WHERE tpd.id=resultid GROUP BY repo,type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations;");
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
@@ -1217,26 +1225,17 @@ public class UsageStatsRepository {
}
} else {
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND rc.type=? AND rc.id=us.result_id "
- + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id "
- + "GROUP BY ro.id, rc.type, rs.title, us.result_id, rs.year order by rc.type ASC;");
-//WITH tpd as (select distinct id, concat(type,'#-#',pid) type_id from openaire_prod_stats.result_pids)
-//select type, downloads, views, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, uniquedownloads,uniqueviews
-//FROM (SELECT us.repository_id repo, us.`date` d1,rc.type type, sum(us.downloads) as downloads, sum(us.views) as views,
-//us.result_id as resultid, rs.title as item, rs.year as yop,
-//count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews
-//FROM openaire_prod_usage_stats.usage_stats us,(select distinct id, type from openaire_prod_stats.result_classifications) rc, openaire_prod_stats.result rs
-//WHERE us.`date`>='2020/01' AND us.`date`<='2020/02'
-//AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id='opendoar____::8e98d81f8217304975ccb23337bb5761'
-//GROUP BY us.`date`,rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp1, tpd
-//where tpd.id=resultid and type='Article'
-//group by repo,d1, type,resultid,item,yop,downloads,views,uniquedownloads,uniqueviews
+ st = connection.prepareStatement("WITH tpd as (SELECT distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, total_item_requests, total_item_investigations, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, unique_item_requests,unique_item_investigations "
+ + "FROM (SELECT us.repository_id repo, rc.type type, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+ + "sum(us.unique_item_requests) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us,(SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, "
+ + statsDB + ".result rs WHERE us.`date`>=? AND us.`date`<=? "
+ + "AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id=? and rc.type=? "
+ + "GROUP BY rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp, tpd "
+ + "WHERE tpd.id=resultid GROUP BY repo,type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations;");
+
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
st.setString(3, repositoryIdentifier);
@@ -1275,36 +1274,16 @@ public class UsageStatsRepository {
} else if (granularity.equalsIgnoreCase("monthly")) {
if (dataType.equals("")) {
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND rc.id=us.result_id AND us.result_id=rs.id AND ro.id=us.result_id "
- + "AND tpd.id=us.result_id "
- + "GROUP BY ro.id, rc.type, rs.title, us.result_id, us.`date`, rs.year order by rc.type, us.`date` ASC;");
-
-//WITH tpd as (select distinct id, concat(type,'#-#',pid) type_id from openaire_prod_stats.result_pids)
-//select type, `date`,downloads, views, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, uniquedownloads,uniqueviews
-//FROM (SELECT us.repository_id repo, us.`date` `date`,rc.type type, sum(us.downloads) as downloads, sum(us.views) as views,
-//us.result_id as resultid, rs.title as item, rs.year as yop,
-//count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews
-//FROM openaire_prod_usage_stats.usage_stats us,(select distinct id, type from openaire_prod_stats.result_classifications) rc, openaire_prod_stats.result rs
-//WHERE us.`date`>='2020/01' AND us.`date`<='2020/02'
-//AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id='opendoar____::8e98d81f8217304975ccb23337bb5761'
-//GROUP BY us.`date`,rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp1, tpd
-//where tpd.id=resultid group by repo,`date`, type,resultid,item,yop,downloads,views,uniquedownloads,uniqueviews
+ st = connection.prepareStatement("WITH tpd as (SELECT distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, `date`,total_item_requests, total_item_investigations, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, unique_item_requests,unique_item_investigations "
+ + "FROM (SELECT us.repository_id repo, us.`date` `date`,rc.type type, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+ + "sum(us.unique_item_requests) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us,(SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, "
+ + statsDB + ".result rs WHERE us.`date`>=? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id=? "
+ + "GROUP BY us.`date`,rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp1, tpd "
+ + "WHERE tpd.id=resultid GROUP BY repo,`date`, type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations");
-//SELECT 'Dataset' as type,dp.period_end, sum(case when dp.metric_type='total-dataset-requests' then count else 0 end) as downloads,
-//sum(case when dp.metric_type='total-dataset-investigations' then count else 0 end) as views,
-//id as resultid,dp.ds_title as item, dp.yop as yop, concat('Digital Object Identifier#-#',dp.ds_type) as oid,
-//sum(case when dp.metric_type='unique-dataset-requests' then count else 0 end) as uniquedownloads,
-//sum(case when dp.metric_type='unique-dataset-investigations' then count else 0 end) as uniqueviews,
-//dp.access_method access_method,dp.platform
-//FROM datasetsusagestats_20210312a.datasetsperformance dp, openaire_prod_stats.result_pids
-//WHERE dp.period_from>='2020-01-01' AND dp.period_end<='2020-12-01' and pid=ds_type
-//GROUP BY dp.period_end,dp.ds_title, dp.yop, dp.platform, dp.access_method, dp.ds_type,id
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
@@ -1365,36 +1344,18 @@ public class UsageStatsRepository {
//fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
}
} else {
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND rc.type=? AND rc.id=us.result_id "
- + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id "
- + "GROUP BY ro.id, rc.type, rs.title, us.result_id, us.`date`, rs.year order by rc.type, us.`date` ASC;");
-
-//WITH tpd as (select distinct id, concat(type,'#-#',pid) type_id from openaire_prod_stats.result_pids)
-//select type, `date`,downloads, views, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, uniquedownloads,uniqueviews
-//FROM (SELECT us.repository_id repo, us.`date` `date`,rc.type type, sum(us.downloads) as downloads, sum(us.views) as views,
-//us.result_id as resultid, rs.title as item, rs.year as yop,
-//count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews
-//FROM openaire_prod_usage_stats.usage_stats us,(select distinct id, type from openaire_prod_stats.result_classifications) rc, openaire_prod_stats.result rs
-//WHERE us.`date`>='2020/01' AND us.`date`<='2020/02'
-//AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id='opendoar____::8e98d81f8217304975ccb23337bb5761' AND rc.type=?
-//GROUP BY us.`date`,rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp1, tpd
-//where tpd.id=resultid group by repo,`date`, type,resultid,item,yop,downloads,views,uniquedownloads,uniqueviews
+ st = connection.prepareStatement("WITH tpd as (SELECT distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, `date`,total_item_requests, total_item_investigations, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, unique_item_requests,unique_item_investigations "
+ + "FROM (SELECT us.repository_id repo, us.`date` `date`,rc.type type, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+ + "sum(us.unique_item_requests) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us,(SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, "
+ + statsDB + ".result rs WHERE us.`date`>=? AND us.`date`<=? "
+ + "AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id=? AND rc.type=? "
+ + "GROUP BY us.`date`,rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp, tpd "
+ + "WHERE tpd.id=resultid group by repo,`date`, type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations;");
-//SELECT 'Dataset' as type,dp.period_end, sum(case when dp.metric_type='total-dataset-requests' then count else 0 end) as downloads,
-//sum(case when dp.metric_type='total-dataset-investigations' then count else 0 end) as views,
-//id as resultid,dp.ds_title as item, dp.yop as yop, concat('Digital Object Identifier#-#',dp.ds_type) as oid,
-//sum(case when dp.metric_type='unique-dataset-requests' then count else 0 end) as uniquedownloads,
-//sum(case when dp.metric_type='unique-dataset-investigations' then count else 0 end) as uniqueviews,
-//dp.access_method access_method,dp.platform
-//FROM datasetsusagestats_20210312a.datasetsperformance dp, openaire_prod_stats.result_pids
-//WHERE dp.period_from>='2020-01-01' AND dp.period_end<='2020-12-01' and pid=ds_type
-//GROUP BY dp.period_end,dp.ds_title, dp.yop, dp.platform, dp.access_method, dp.ds_type,id
+
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
st.setString(3, repositoryIdentifier);
@@ -1484,35 +1445,16 @@ public class UsageStatsRepository {
if (granularity.equalsIgnoreCase("totals")) {
if (dataType.equals("")) {
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND us.result_id=? AND rc.id=us.result_id AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id "
- + "GROUP BY rc.type, rs.title, us.result_id, rs.title, rs.year order by rc.type ASC;");
-//WITH tpd as (select distinct id, concat(type,'#-#',pid) type_id from openaire_prod_stats.result_pids)
-//select type, downloads, views, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, uniquedownloads,uniqueviews
-//FROM (SELECT us.repository_id repo, rc.type type, sum(us.downloads) as downloads, sum(us.views) as views,
-//us.result_id as resultid, rs.title as item, rs.year as yop,
-//count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews
-//FROM openaire_prod_usage_stats.usage_stats us,(select distinct id, type from openaire_prod_stats.result_classifications) rc, openaire_prod_stats.result rs
-//WHERE us.`date`>='2020/01' AND us.`date`<='2020/02'
-//AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id='opendoar____::8e98d81f8217304975ccb23337bb5761' AND us.result_id=?
-//GROUP BY rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp1, tpd
-//where tpd.id=resultid
-//group by repo,type,resultid,item,yop,downloads,views,uniquedownloads,uniqueviews
+ st = connection.prepareStatement("WITH tpd as (SELECT distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, total_item_requests, total_item_investigations, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, unique_item_requests,unique_item_investigations "
+ + "FROM (SELECT us.repository_id repo, rc.type type, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+ + "sum(us.unique_item_requests) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us,(SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, "
+ + statsDB + ".result rs WHERE us.`date`>=? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id=? "
+ + "AND us.result_id=? GROUP BY rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp, tpd WHERE tpd.id=resultid "
+ + "GROUP BY repo,type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations;");
-//SELECT 'Dataset' as type, sum(case when dp.metric_type='total-dataset-requests' then count else 0 end) as downloads,
-//sum(case when dp.metric_type='total-dataset-investigations' then count else 0 end) as views,
-//id as resultid,dp.ds_title as item, dp.yop as yop, concat('Digital Object Identifier#-#',dp.ds_type) as oid,
-//sum(case when dp.metric_type='unique-dataset-requests' then count else 0 end) as uniquedownloads,
-//sum(case when dp.metric_type='unique-dataset-investigations' then count else 0 end) as uniqueviews,
-//dp.access_method access_method,dp.platform
-//FROM datasetsusagestats_20210312a.datasetsperformance dp, openaire_prod_stats.result_pids
-//WHERE dp.period_from>='2020-01-01' AND dp.period_end<='2020-12-01' and pid=ds_type AND ds_type=?
-//GROUP BY dp.ds_title, dp.yop, dp.platform, dp.access_method, dp.ds_type,id
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
st.setString(3, repositoryIdentifier);
@@ -1547,35 +1489,16 @@ public class UsageStatsRepository {
reportItems.add(reportItem);
}
} else {
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND us.result_id=? AND rc.type=? AND rc.id=us.result_id "
- + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id "
- + "GROUP BY ro.id, rc.type, rs.title, us.result_id, rs.year order by rc.type ASC;");
-//WITH tpd as (select distinct id, concat(type,'#-#',pid) type_id from openaire_prod_stats.result_pids)
-//select type, downloads, views, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, uniquedownloads,uniqueviews
-//FROM (SELECT us.repository_id repo, us.`date` `date`,rc.type type, sum(us.downloads) as downloads, sum(us.views) as views,
-//us.result_id as resultid, rs.title as item, rs.year as yop,
-//count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews
-//FROM openaire_prod_usage_stats.usage_stats us,(select distinct id, type from openaire_prod_stats.result_classifications) rc, openaire_prod_stats.result rs
-//WHERE us.`date`>='2020/01' AND us.`date`<='2020/02'
-//AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id='opendoar____::8e98d81f8217304975ccb23337bb5761' AND us.result_id=? AND rc.type=?
-//GROUP BY rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp1, tpd
-//where tpd.id=resultid group by repo, type,resultid,item,yop,downloads,views,uniquedownloads,uniqueviews
+ st = connection.prepareStatement("WITH tpd as (select distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, total_item_requests, total_item_investigations, resultid, item, yop, group_concat(distinct tpd.type_id,'#!#') as oid, unique_item_requests,unique_item_investigations "
+ + "FROM (SELECT us.repository_id repo, rc.type type, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, sum(us.unique_item_requests) as unique_item_requests, "
+ + "sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us,(select distinct id, type FROM " + statsDB + ".result_classifications) rc, "
+ + statsDB + ".result rs WHERE us.`date`>=? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id "
+ + "AND us.repository_id=? AND us.result_id=? AND rc.type=? GROUP BY rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp, tpd "
+ + "WHERE tpd.id=resultid group by repo, type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations;");
-//SELECT 'Dataset' as type, sum(case when dp.metric_type='total-dataset-requests' then count else 0 end) as downloads,
-//sum(case when dp.metric_type='total-dataset-investigations' then count else 0 end) as views,
-//id as resultid,dp.ds_title as item, dp.yop as yop, concat('Digital Object Identifier#-#',dp.ds_type) as oid,
-//sum(case when dp.metric_type='unique-dataset-requests' then count else 0 end) as uniquedownloads,
-//sum(case when dp.metric_type='unique-dataset-investigations' then count else 0 end) as uniqueviews,
-//dp.access_method access_method,dp.platform
-//FROM datasetsusagestats_20210312a.datasetsperformance dp, openaire_prod_stats.result_pids
-//WHERE dp.period_from>='2020-01-01' AND dp.period_end<='2020-12-01' and pid=ds_type and dp.ds_type=?
-//GROUP BY dp.ds_title, dp.yop, dp.platform, dp.access_method, dp.ds_type,id
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
st.setString(3, repositoryIdentifier);
@@ -1607,36 +1530,16 @@ public class UsageStatsRepository {
} else if (granularity.equalsIgnoreCase("monthly")) {
if (dataType.equals("")) {
+ st = connection.prepareStatement("WITH tpd as (select distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, `date`,total_item_requests, total_item_investigations, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, uniquedownloads,uniqueviews "
+ + "FROM (SELECT us.repository_id repo, us.`date` `date`,rc.type type, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+ + "sum(us.unique_item_requests) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us,(select distinct id, type FROM " + statsDB + ".result_classifications) rc, "
+ + statsDB + ".result rs WHERE us.`date`>=? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id=? AND us.result_id=? "
+ + "GROUP BY us.`date`,rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp, tpd "
+ + "WHERE tpd.id=resultid group by repo,`date`, type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations;");
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND us.result_id=? AND rc.id=us.result_id AND us.result_id=rs.id AND ro.id=us.result_id "
- + "AND tpd.id=us.result_id "
- + "GROUP BY ro.id, rc.type, rs.title, us.result_id, us.`date`, rs.year order by rc.type, us.`date` ASC;");
-//WITH tpd as (select distinct id, concat(type,'#-#',pid) type_id from openaire_prod_stats.result_pids)
-//select type, `date`,downloads, views, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, uniquedownloads,uniqueviews
-//FROM (SELECT us.repository_id repo, us.`date` `date`,rc.type type, sum(us.downloads) as downloads, sum(us.views) as views,
-//us.result_id as resultid, rs.title as item, rs.year as yop,
-//count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews
-//FROM openaire_prod_usage_stats.usage_stats us,(select distinct id, type from openaire_prod_stats.result_classifications) rc, openaire_prod_stats.result rs
-//WHERE us.`date`>='2020/01' AND us.`date`<='2020/02'
-//AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id='opendoar____::8e98d81f8217304975ccb23337bb5761' AND us.result_id=?
-//GROUP BY us.`date`,rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp1, tpd
-//where tpd.id=resultid group by repo,`date`, type,resultid,item,yop,downloads,views,uniquedownloads,uniqueviews
-
-//SELECT 'Dataset' as type,dp.period_end, sum(case when dp.metric_type='total-dataset-requests' then count else 0 end) as downloads,
-//sum(case when dp.metric_type='total-dataset-investigations' then count else 0 end) as views,
-//id as resultid,dp.ds_title as item, dp.yop as yop, concat('Digital Object Identifier#-#',dp.ds_type) as oid,
-//sum(case when dp.metric_type='unique-dataset-requests' then count else 0 end) as uniquedownloads,
-//sum(case when dp.metric_type='unique-dataset-investigations' then count else 0 end) as uniqueviews,
-//dp.access_method access_method,dp.platform
-//FROM datasetsusagestats_20210312a.datasetsperformance dp, openaire_prod_stats.result_pids
-//WHERE dp.period_from>='2020-01-01' AND dp.period_end<='2020-12-01' and pid=ds_type and dp.ds_type=?
-//GROUP BY dp.period_end,dp.ds_title, dp.yop, dp.platform, dp.access_method, dp.ds_type,id
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
st.setString(3, repositoryIdentifier);
@@ -1696,35 +1599,17 @@ public class UsageStatsRepository {
//fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
}
} else {
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND us.result_id=? AND rc.type=? AND rc.id=us.result_id "
- + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id "
- + "GROUP BY ro.id, rc.type, rs.title, us.result_id, us.`date`, rs.year order by rc.type, us.`date` ASC;");
-//WITH tpd as (select distinct id, concat(type,'#-#',pid) type_id from openaire_prod_stats.result_pids)
-//select type, `date`,downloads, views, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, uniquedownloads,uniqueviews
-//FROM (SELECT us.repository_id repo, us.`date` `date`,rc.type type, sum(us.downloads) as downloads, sum(us.views) as views,
-//us.result_id as resultid, rs.title as item, rs.year as yop,
-//count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews
-//FROM openaire_prod_usage_stats.usage_stats us,(select distinct id, type from openaire_prod_stats.result_classifications) rc, openaire_prod_stats.result rs
-//WHERE us.`date`>='2020/01' AND us.`date`<='2020/02'
-//AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id='opendoar____::8e98d81f8217304975ccb23337bb5761' AND us.result_id=? AND rc.type=?
-//GROUP BY us.`date`,rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp1, tpd
-//where tpd.id=resultid group by repo,`date`, type,resultid,item,yop,downloads,views,uniquedownloads,uniqueviews
+ st = connection.prepareStatement("WITH tpd as (SELECT distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, `date`,total_item_requests, total_item_investigations, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, unique_item_requests,unique_item_investigations "
+ + "FROM (SELECT us.repository_id repo, us.`date` `date`,rc.type type, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+ + "sum(us.unique_item_requests) as unique_item_requests, sum(unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us,(select distinct id, type FROM " + statsDB + ".result_classifications) rc, " + statsDB + ".result rs "
+ + "WHERE us.`date`>=? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id "
+ + "AND us.repository_id=? AND us.result_id=? AND rc.type=? "
+ + "GROUP BY us.`date`,rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp, tpd "
+ + "WHERE tpd.id=resultid group by repo,`date`, type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations;");
-//SELECT 'Dataset' as type,dp.period_end, sum(case when dp.metric_type='total-dataset-requests' then count else 0 end) as downloads,
-//sum(case when dp.metric_type='total-dataset-investigations' then count else 0 end) as views,
-//id as resultid,dp.ds_title as item, dp.yop as yop, concat('Digital Object Identifier#-#',dp.ds_type) as oid,
-//sum(case when dp.metric_type='unique-dataset-requests' then count else 0 end) as uniquedownloads,
-//sum(case when dp.metric_type='unique-dataset-investigations' then count else 0 end) as uniqueviews,
-//dp.access_method access_method,dp.platform
-//FROM datasetsusagestats_20210312a.datasetsperformance dp, openaire_prod_stats.result_pids
-//WHERE dp.period_from>='2020-01-01' AND dp.period_end<='2020-12-01' and pid=ds_type and dp.ds_type=?
-//GROUP BY dp.period_end,dp.ds_title, dp.yop, dp.platform, dp.access_method, dp.ds_type,id
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
st.setString(3, repositoryIdentifier);
@@ -1826,14 +1711,16 @@ public class UsageStatsRepository {
if (granularity.equalsIgnoreCase("totals")) {
if (dataType.equals("")) {
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, ds.name, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd, " + statsDB + ".datasource ds "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=ds.id AND us.result_id=? AND rc.id=us.result_id AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id "
- + "GROUP BY rc.type, rs.title, us.result_id, rs.title, rs.year, ds.name order by rc.type ASC;");
+ st = connection.prepareStatement("WITH tpd as (SELECT distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, total_item_requests, total_item_investigations, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, name, unique_item_requests,unique_item_investigations "
+ + "FROM (SELECT us.repository_id repo,rc.type type, ds.name as name, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+ + "sum(us.unique_item_requests) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us, (SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, " + statsDB + ".result rs, "
+ + statsDB + ".datasource ds WHERE us.`date`>=? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id AND us.result_id=? "
+ + "AND us.repository_id=ds.id GROUP BY rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id, ds.name) tmp, tpd "
+ + "WHERE tpd.id=resultid group by repo,name, type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations");
+
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
@@ -1869,15 +1756,15 @@ public class UsageStatsRepository {
}
} else {
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, ds.name, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd, " + statsDB + ".datasource ds "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=ds.id AND us.result_id=? AND rc.type=? AND rc.id=us.result_id "
- + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id "
- + "GROUP BY ro.id, rc.type, rs.title, us.result_id, rs.year, ds.name order by rc.type ASC;");
+ st = connection.prepareStatement("WITH tpd as (SELECT distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, total_item_requests, total_item_investigations, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, name, unique_item_requests,unique_item_investigations "
+ + "FROM (SELECT us.repository_id repo,rc.type type, ds.name as name, sum(us.unique_item_requests) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+ + "sum(us.unique_item_requests) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us, (SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, " + statsDB + ".result rs, "
+ + statsDB + ".datasource ds WHERE us.`date`>=? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id AND us.result_id=? AND rc.type=? "
+ + "AND us.repository_id=ds.id GROUP BY rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id, ds.name) tmp, tpd "
+ + "WHERE tpd.id=resultid group by repo,name, type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations");
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
@@ -1902,8 +1789,8 @@ public class UsageStatsRepository {
}
while (rs.next()) {
- String platform = getInstitutionName(rs.getString(8));
- reportItem = new COUNTER_Item_Usage(rs.getString(5), "OpenAIRE", platform, rs.getString(1), Integer.toString(rs.getInt(6)), null, "Regular");
+ //String platform = getInstitutionName(rs.getString(8));
+ reportItem = new COUNTER_Item_Usage(rs.getString(5), "OpenAIRE", rs.getString(8), rs.getString(1), Integer.toString(rs.getInt(6)), null, "Regular");
String[] identifiersAll = rs.getString(7).split("#!#");
for (int i = 0; i < identifiersAll.length; i++) {
String[] typeIdentifierArray = identifiersAll[i].split("#-#");
@@ -1920,15 +1807,15 @@ public class UsageStatsRepository {
if (dataType.equals("")) {
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, ds.name, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd, " + statsDB + ".datasource ds "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=ds.id AND us.result_id=? AND rc.id=us.result_id AND us.result_id=rs.id AND ro.id=us.result_id "
- + "AND tpd.id=us.result_id "
- + "GROUP BY ro.id, rc.type, rs.title, us.result_id, us.`date`, rs.year, ds.name order by rc.type, us.`date` ASC;");
+ st = connection.prepareStatement("WITH tpd as (select distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, `date`,total_item_requests, total_item_investigations, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, name, unique_item_requests,unique_item_investigations "
+ + "FROM (SELECT us.repository_id repo, us.`date` `date`,rc.type type, ds.name as name, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, sum(us.unique_item_requests) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us, (SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, " + statsDB + ".result rs, "
+ + statsDB + ".datasource ds WHERE us.`date`>=? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id AND us.result_id=? AND us.repository_id=ds.id "
+ + "GROUP BY us.`date`,rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id, ds.name) tmp, tpd "
+ + "WHERE tpd.id=resultid group by repo,`date`,name, type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations;");
+
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
st.setString(3, itemIdentifier);
@@ -1986,15 +1873,14 @@ public class UsageStatsRepository {
//fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
}
} else {
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, ds.name, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd, " + statsDB + ".datasource ds "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=ds.id AND us.result_id=? AND rc.type=? AND rc.id=us.result_id "
- + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id "
- + "GROUP BY ro.id, rc.type, rs.title, us.result_id, us.`date`, rs.year, ds.name order by rc.type, us.`date` ASC;");
+ st = connection.prepareStatement("WITH tpd as (select distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, `date`,total_item_requests, total_item_investigations, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, name, unique_item_requests,unique_item_investigations "
+ + "FROM (SELECT us.repository_id repo, us.`date` `date`,rc.type type, ds.name as name, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, sum(us.unique_item_requests) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us, (SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, " + statsDB + ".result rs, "
+ + statsDB + ".datasource ds WHERE us.`date`>=? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id AND us.result_id=? AND us.repository_id=ds.id AND rc.type=? "
+ + "GROUP BY us.`date`,rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id, ds.name) tmp, tpd "
+ + "WHERE tpd.id=resultid group by repo,`date`,name, type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations;");
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
st.setString(3, itemIdentifier);
@@ -2095,17 +1981,25 @@ public class UsageStatsRepository {
if (granularity.equalsIgnoreCase("totals")) {
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews, "
- + "case when us.source='Datacite' then dp.access_method else 'regular' end as access_method "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd, datasetsusagestats_20210312a.datasetsperformance dp "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND rc.id=us.result_id "
- + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id AND rc.type='Dataset' AND dp.ds_type=ro.oid "
- + "GROUP BY us.source, ro.id, rc.type, rs.title, us.result_id, rs.year, dp.access_method ORDER by rc.type ASC;");
-
+// st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
+// + "SELECT rc.type, sum(us.downloads) as downloads, sum(us.views) as views, "
+// + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
+// + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews, "
+// + "case when us.source='Datacite' then dp.access_method else 'regular' end as access_method "
+// + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
+// + statsDB + ".result_oids ro, tpd, datasetsusagestats_20210312a.datasetsperformance dp "
+// + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND rc.id=us.result_id "
+// + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id AND rc.type='Dataset' AND dp.ds_type=ro.oid "
+// + "GROUP BY us.source, ro.id, rc.type, rs.title, us.result_id, rs.year, dp.access_method ORDER by rc.type ASC;");
+ st = connection.prepareStatement("WITH tpd as (SELECT distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, total_item_requests, total_item_investigations, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, unique_item_requests,unique_item_investigations, 'Regular' as access_method "
+ + "FROM (SELECT us.repository_id repo, rc.type type, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+ + "sum(us.unique_item_requests) as unique_item_requests, sum(unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us,(SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, openaire_prod_stats.result rs "
+ + "WHERE us.`date`>='? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id=? "
+ + "AND rc.type='Dataset' GROUP BY rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp, tpd "
+ + "WHERE tpd.id=resultid GROUP BY repo,type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations;");
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
st.setString(3, repositoryIdentifier);
@@ -2140,16 +2034,27 @@ public class UsageStatsRepository {
}
//}
} else if (granularity.equalsIgnoreCase("monthly")) {
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews, "
- + "case when us.source='Datacite' then dp.access_method else 'regular' end as access_method "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd, datasetsusagestats_20210312a.datasetsperformance dp "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND rc.id=us.result_id "
- + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id AND rc.type='Dataset' AND dp.ds_type=ro.oid "
- + "GROUP BY us.source, ro.id, rc.type, rs.title, us.result_id, us.`date`, rs.year, dp.access_method ORDER by rc.type, us.`date` ASC;");
+// st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
+// + "SELECT rc.type, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
+// + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
+// + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews, "
+// + "case when us.source='Datacite' then dp.access_method else 'regular' end as access_method "
+// + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
+// + statsDB + ".result_oids ro, tpd, datasetsusagestats_20210312a.datasetsperformance dp "
+// + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND rc.id=us.result_id "
+// + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id AND rc.type='Dataset' AND dp.ds_type=ro.oid "
+// + "GROUP BY us.source, ro.id, rc.type, rs.title, us.result_id, us.`date`, rs.year, dp.access_method ORDER by rc.type, us.`date` ASC;");
+
+ st = connection.prepareStatement("WITH tpd as (SELECT distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, `date`, total_item_requests, total_item_investigations, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, unique_item_requests,unique_item_investigations, 'Regular' as access_method "
+ + "FROM (SELECT us.repository_id repo, us.`date` as `date`, rc.type type, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+ + "sum(us.unique_item_requests) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us,(SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, openaire_prod_stats.result rs "
+ + "WHERE us.`date`>=? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id=? "
+ + "AND rc.type='Dataset' GROUP BY us.`date`, rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp, tpd "
+ + "WHERE tpd.id=resultid GROUP BY repo,`date`, type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations ORDER BY `date` ASC;");
+
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
st.setString(3, repositoryIdentifier);
@@ -2233,17 +2138,25 @@ public class UsageStatsRepository {
connection = usageStatsDB.getConnection();
if (granularity.equalsIgnoreCase("totals")) {
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews,"
- + "case when us.source='Datacite' then dp.access_method else 'regular' end as access_method "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd, datasetsusagestats_20210312a.datasetsperformance dp "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND us.result_id=? AND rc.id=us.result_id "
- + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id AND rc.type='Dataset' AND dp.ds_type=ro.oid "
- + "GROUP BY us.source, ro.id, rc.type, rs.title, us.result_id, rs.year, dp.access_method ORDER by rc.type ASC;");
-
+// st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
+// + "SELECT rc.type, sum(us.downloads) as downloads, sum(us.views) as views, "
+// + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
+// + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews,"
+// + "case when us.source='Datacite' then dp.access_method else 'regular' end as access_method "
+// + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
+// + statsDB + ".result_oids ro, tpd, datasetsusagestats_20210312a.datasetsperformance dp "
+// + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND us.result_id=? AND rc.id=us.result_id "
+// + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id AND rc.type='Dataset' AND dp.ds_type=ro.oid "
+// + "GROUP BY us.source, ro.id, rc.type, rs.title, us.result_id, rs.year, dp.access_method ORDER by rc.type ASC;");
+ st = connection.prepareStatement("WITH tpd as (SELECT distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, total_item_requests, total_item_investigations, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, unique_item_requests,unique_item_investigations, 'Regular' as access_method "
+ + "FROM (SELECT us.repository_id repo, rc.type type, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+ + "sum(us.unique_item_requests) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us,(SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, openaire_prod_stats.result rs "
+ + "WHERE us.`date`>=? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id=? AND us.result_id=? "
+ + "AND rc.type='Dataset' GROUP BY rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp, tpd "
+ + "WHERE tpd.id=resultid GROUP BY repo,type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations;");
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
st.setString(3, repositoryIdentifier);
@@ -2278,16 +2191,25 @@ public class UsageStatsRepository {
}
} else if (granularity.equalsIgnoreCase("monthly")) {
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews, "
- + "case when us.source='Datacite' then dp.access_method else 'regular' end as access_method "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd, datasetsusagestats_20210312a.datasetsperformance dp "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND us.result_id=? AND rc.id=us.result_id "
- + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id AND rc.type='Dataset' AND dp.ds_type=ro.oid "
- + "GROUP BY us.source, ro.id, rc.type, rs.title, us.result_id, us.`date`, rs.year, dp.access_method ORDER by rc.type, us.`date` ASC;");
+// st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
+// + "SELECT rc.type, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
+// + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
+// + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews, "
+// + "case when us.source='Datacite' then dp.access_method else 'regular' end as access_method "
+// + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
+// + statsDB + ".result_oids ro, tpd, datasetsusagestats_20210312a.datasetsperformance dp "
+// + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND us.result_id=? AND rc.id=us.result_id "
+// + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id AND rc.type='Dataset' AND dp.ds_type=ro.oid "
+// + "GROUP BY us.source, ro.id, rc.type, rs.title, us.result_id, us.`date`, rs.year, dp.access_method ORDER by rc.type, us.`date` ASC;");
+ st = connection.prepareStatement("WITH tpd as (SELECT distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, `date`, total_item_requests, total_item_investigations, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, unique_item_requests,unique_item_investigations, 'Regular' as access_method "
+ + "FROM (SELECT us.repository_id repo, us.`date` as `date`, rc.type type, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+ + "sum(us.unique_item_requests) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us,(SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, openaire_prod_stats.result rs "
+ + "WHERE us.`date`>=? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id AND us.repository_id=? AND us.result_id=? "
+ + "AND rc.type='Dataset' GROUP BY us.`date`, rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id, us.`date`) tmp, tpd "
+ + "WHERE tpd.id=resultid GROUP BY repo,`date`, type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations ORDER BY `date` ASC;");
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
st.setString(3, repositoryIdentifier);
@@ -2376,7 +2298,9 @@ public class UsageStatsRepository {
Connection connection = null;
PreparedStatement st = null;
+ PreparedStatement st1 = null;
ResultSet rs = null;
+ ResultSet rs1 = null;
try {
connection = usageStatsDB.getConnection();
@@ -2384,21 +2308,42 @@ public class UsageStatsRepository {
if (granularity.equalsIgnoreCase("totals")) {
st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, sum(us.downloads) as downloads, sum(us.views) as views, "
+ + "SELECT rc.type, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, ds.name, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews, "
+ + "sum(us.unique_item_requests) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations, "
+ "case when us.source='Datacite' then dp.access_method else 'regular' end as access_method "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd, " + statsDB + ".datasource ds, datasetsusagestats_20210312a.datasetsperformance dp "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
+ + statsDB + ".result_oids ro, tpd, " + statsDB + ".datasource ds, openaire_prod_datacite_usage_stats.datasetsperformance_nonarray_view dp "
+ "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=ds.id AND us.result_id=? AND rc.id=us.result_id "
+ "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id AND rc.type='Dataset' AND dp.ds_type=ro.oid "
+ "GROUP BY us.source, ro.id, rc.type, rs.title, us.result_id, rs.year, ds.name,dp.access_method ORDER by rc.type ASC;");
-
+ st = connection.prepareStatement("WITH tpd as (SELECT distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, total_item_requests, total_item_investigations, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid,name, unique_item_requests,unique_item_investigations, 'Regular' as access_method "
+ + "FROM (SELECT us.repository_id repo, rc.type type, ds.name, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+ + "sum(us.unique_item_requests) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us,(SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, " + statsDB + ".result rs, "
+ + statsDB + ".datasource ds WHERE us.`date`>=? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id AND us.result_id=? "
+ + "AND rc.type='Dataset' AND ds.id=us.repository_id GROUP BY rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id, ds.name) tmp, tpd "
+ + "WHERE tpd.id=resultid GROUP BY name, type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations ");
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
st.setString(3, itemIdentifier);
+// + "UNION "
+ st1 = connection.prepareStatement("SELECT 'Dataset' as type, sum(case when dp.metric_type='total-dataset-requests' then count else 0 end) as downloads, "
+ + "sum(case when dp.metric_type='total-dataset-investigations' then count else 0 end) as views, "
+ + "rp.id as resultid,dp.ds_title as item, cast(dp.yop as Int) as yop, concat('Digital Object Identifier#-#',dp.ds_type) as oid, dp.platform, "
+ + "sum(case when dp.metric_type='unique-dataset-requests' then count else 0 end) as uniquedownloads, "
+ + "sum(case when dp.metric_type='unique-dataset-investigations' then count else 0 end) as uniqueviews, "
+ + "dp.access_method access_method FROM openaire_prod_datacite_usage_stats.datasetsperformance_nonarray_view dp, "
+ + statsDB + ".result_pids rp, " + statsDB + ".datasource ds "
+ + "WHERE dp.period_from>=? AND dp.period_end<=? and rp.pid=ds_type AND rp.id=? "
+ + "AND ds.name=dp.platform GROUP BY dp.ds_title, dp.yop, dp.platform, dp.access_method, dp.ds_type,rp.id ");
+
+ st1.setString(1, report_dateFormat.format(beginDate));
+ st1.setString(2, report_dateFormat.format(endDate));
+ st1.setString(3, itemIdentifier);
- rs = st.executeQuery();
COUNTER_Dataset_Usage reportItem = null;
boolean[] metricTypeValue = {false, false, false, false};
@@ -2415,8 +2360,9 @@ public class UsageStatsRepository {
metricTypeValue[3] = true;
}
+ rs = st.executeQuery();
while (rs.next()) {
- String platform = getInstitutionName(rs.getString(8));
+ // String platform = getInstitutionName(rs.getString(8));
reportItem = new COUNTER_Dataset_Usage(rs.getString(5), "OpenAIRE", rs.getString(8), rs.getString(1), Integer.toString(rs.getInt(6)), rs.getString(11));
String[] identifiersAll = rs.getString(7).split("#!#");
for (int i = 0; i < identifiersAll.length; i++) {
@@ -2428,24 +2374,58 @@ public class UsageStatsRepository {
metricTypeValue[0] == true ? rs.getString(2) : null, metricTypeValue[1] == true ? rs.getString(3) : null, metricTypeValue[2] == true ? rs.getString(9) : null, metricTypeValue[3] == true ? rs.getString(10) : null));
reportItems.add(reportItem);
}
+ rs1 = st1.executeQuery();
+ while (rs1.next()) {
+ // String platform = getInstitutionName(rs.getString(8));
+ reportItem = new COUNTER_Dataset_Usage(rs1.getString(5), "OpenAIRE", rs1.getString(8), rs1.getString(1), Integer.toString(rs1.getInt(6)), rs1.getString(11));
+ String[] identifiersAll = rs1.getString(7).split("#!#");
+ for (int i = 0; i < identifiersAll.length; i++) {
+ String[] typeIdentifierArray = identifiersAll[i].split("#-#");
+ reportItem.addIdentifier(new COUNTER_Dataset_Identifiers(typeIdentifierArray[0], typeIdentifierArray[1]));
+ }
- //}
+ reportItem.addPerformance(new COUNTER_Dataset_Performance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate),
+ metricTypeValue[0] == true ? rs1.getString(2) : null, metricTypeValue[1] == true ? rs1.getString(3) : null, metricTypeValue[2] == true ? rs1.getString(9) : null, metricTypeValue[3] == true ? rs1.getString(10) : null));
+ reportItems.add(reportItem);
+ }
} else if (granularity.equalsIgnoreCase("monthly")) {
- st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
- + "SELECT rc.type, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
- + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, ds.name, "
- + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews, "
- + "case when us.source='Datacite' then dp.access_method else 'regular' end as access_method "
- + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
- + statsDB + ".result_oids ro, tpd, " + statsDB + ".datasource ds, datasetsusagestats_20210312a.datasetsperformance dp "
- + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=ds.id AND us.result_id=? AND rc.id=us.result_id "
- + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id AND rc.type='Dataset' AND dp.ds_type=ro.oid "
- + "GROUP BY us.source, ro.id, rc.type, rs.title, us.result_id, us.`date`, rs.year, ds.name, dp.access_method ORDER by rc.type, us.`date` ASC;");
+// st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
+// + "SELECT rc.type, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
+// + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, ds.name, "
+// + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews, "
+// + "case when us.source='Datacite' then dp.access_method else 'regular' end as access_method "
+// + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
+// + statsDB + ".result_oids ro, tpd, " + statsDB + ".datasource ds, datasetsusagestats_20210312a.datasetsperformance dp "
+// + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=ds.id AND us.result_id=? AND rc.id=us.result_id "
+// + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id AND rc.type='Dataset' AND dp.ds_type=ro.oid "
+// + "GROUP BY us.source, ro.id, rc.type, rs.title, us.result_id, us.`date`, rs.year, ds.name, dp.access_method ORDER by rc.type, us.`date` ASC;");
+ st = connection.prepareStatement("WITH tpd as (SELECT distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+ + "SELECT type, `date`, total_item_requests, total_item_investigations, resultid, item, yop, group_concat(distinct tpd.type_id,'#!#') as oid, unique_item_requests,unique_item_investigations, name, 'Regular' as access_method "
+ + "FROM (SELECT us.repository_id repo, us.`date` as `date`, rc.type type,ds.name, sum(us.total_item_requests) as total_item_requests, sum(us.total_item_investigations) as total_item_investigations, "
+ + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+ + "sum(us.unique_item_requests)) as unique_item_requests, sum(us.unique_item_investigations) as unique_item_investigations "
+ + "FROM " + usagestatsImpalaDB + ".counter_r5_stats_with_metrics us,(SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, openaire_prod_stats.result rs, "
+ + statsDB + ".datasource ds WHERE us.`date`>=? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id AND ds.id=us.repository_id AND us.result_id=? "
+ + "AND rc.type='Dataset' GROUP BY ds.name, us.repository_id, rc.type, us.`date`, rs.title, us.result_id, rs.title, rs.year, us.`date`) tmp, tpd "
+ + "WHERE tpd.id=resultid GROUP BY name,`date`, type,resultid,item,yop,total_item_requests,total_item_investigations,unique_item_requests,unique_item_investigations ORDER BY `date` ASC;");
st.setString(1, beginDateStr);
st.setString(2, endDateStr);
st.setString(3, itemIdentifier);
+ st1 = connection.prepareStatement("SELECT 'Dataset' as type, dp.period_from, sum(case when dp.metric_type='total-dataset-requests' then count else 0 end) as downloads, "
+ + "sum(case when dp.metric_type='total-dataset-investigations' then count else 0 end) as views, "
+ + "rp.id as resultid,dp.ds_title as item, dp.yop as yop, concat('Digital Object Identifier#-#',dp.ds_type) as oid, "
+ + "sum(case when dp.metric_type='unique-dataset-requests' then count else 0 end) as uniquedownloads, "
+ + "sum(case when dp.metric_type='unique-dataset-investigations' then count else 0 end) as uniqueviews, dp.platform, "
+ + "dp.access_method access_method FROM openaire_prod_datacite_usage_stats.datasetsperformance_nonarray_view dp, "
+ + statsDB + ".result_pids rp, " + statsDB + ".datasource ds "
+ + "WHERE dp.period_from>=? AND dp.period_end<=? and rp.pid=ds_type and rp.id=? and ds.name=dp.platform "
+ + "GROUP BY dp.ds_title, dp.yop, dp.platform, dp.access_method, dp.ds_type,rp.id, dp.period_from");
+ st1.setString(1, report_dateFormat.format(beginDate));
+ st1.setString(2, report_dateFormat.format(endDate));
+ st1.setString(3, itemIdentifier);
+
rs = st.executeQuery();
String result = "";
String lastDate = "";
@@ -2488,7 +2468,7 @@ public class UsageStatsRepository {
// reportItem = new COUNTER_Platform_Usage("", "OpenAIRE", rs.getString(1), "Regular", "");
datatype = rs.getString(1);
}
- reportItem = new COUNTER_Dataset_Usage(rs.getString(6), "OpenAIRE", rs.getString(9), rs.getString(1), Integer.toString(rs.getInt(7)), rs.getString(12));
+ reportItem = new COUNTER_Dataset_Usage(rs.getString(6), "OpenAIRE", rs.getString(11), rs.getString(1), Integer.toString(rs.getInt(7)), rs.getString(12));
String[] identifiersAll = rs.getString(8).split("#!#");
for (int i = 0; i < identifiersAll.length; i++) {
String[] typeIdentifierArray = identifiersAll[i].split("#-#");
@@ -2496,7 +2476,7 @@ public class UsageStatsRepository {
}
reportItem.addPerformance(new COUNTER_Dataset_Performance(report_dateFormat.format(postgresFormat.parse(rs.getString(2))), report_dateFormat.format(endC.getTime()),
- metricTypeValue[0] == true ? rs.getString(3) : null, metricTypeValue[1] == true ? rs.getString(4) : null, metricTypeValue[2] == true ? rs.getString(10) : null, metricTypeValue[3] == true ? rs.getString(11) : null));
+ metricTypeValue[0] == true ? rs.getString(3) : null, metricTypeValue[1] == true ? rs.getString(4) : null, metricTypeValue[2] == true ? rs.getString(9) : null, metricTypeValue[3] == true ? rs.getString(10) : null));
reportItems.add(reportItem);
endC.setTime(postgresFormat.parse(rs.getString(2)));
@@ -2505,6 +2485,37 @@ public class UsageStatsRepository {
//if (reportItem != null) {
//fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
}
+ rs1 = st1.executeQuery();
+ while (rs1.next()) {
+ Calendar endC = Calendar.getInstance();
+ endC.setTime(report_dateFormat.parse(rs1.getString(2)));
+ endC.set(Calendar.DATE, endC.getActualMaximum(Calendar.DATE));
+// //iterate on data types
+ if (!datatype.equals(rs1.getString(1))) {
+// if (reportItem != null) {
+// reportItems.add(reportItem);
+// }
+// reportItem = new COUNTER_Platform_Usage("", "OpenAIRE", rs.getString(1), "Regular", "");
+ datatype = rs1.getString(1);
+ }
+ reportItem = new COUNTER_Dataset_Usage(rs1.getString(6), "OpenAIRE", rs1.getString(11), rs1.getString(1), Integer.toString(rs1.getInt(7)), rs1.getString(12));
+ String[] identifiersAll = rs1.getString(8).split("#!#");
+ for (int i = 0; i < identifiersAll.length; i++) {
+ String[] typeIdentifierArray = identifiersAll[i].split("#-#");
+ reportItem.addIdentifier(new COUNTER_Dataset_Identifiers(typeIdentifierArray[0], typeIdentifierArray[1]));
+ }
+
+ reportItem.addPerformance(new COUNTER_Dataset_Performance(report_dateFormat.format(report_dateFormat.parse(rs1.getString(2))), report_dateFormat.format(endC.getTime()),
+ metricTypeValue[0] == true ? rs1.getString(3) : null, metricTypeValue[1] == true ? rs1.getString(4) : null, metricTypeValue[2] == true ? rs1.getString(9) : null, metricTypeValue[3] == true ? rs1.getString(10) : null));
+ reportItems.add(reportItem);
+
+ endC.setTime(report_dateFormat.parse(rs1.getString(2)));
+ endC.add(Calendar.MONTH, 1);
+ lastDate = report_dateFormat.format(endC.getTime());
+ //if (reportItem != null) {
+ //fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
+ }
+
}
/*
jedis.put(redis_key, "persistent", "false");
@@ -2521,6 +2532,502 @@ public class UsageStatsRepository {
}
}
+ public void executeBatchItemsDSRDatacite(List reportItems,
+ String repositoryIdentifier, String itemIdentifier, Date beginDate,
+ Date endDate, List metricType, String granularity) throws Exception {
+ SimpleDateFormat report_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ //SimpleDateFormat postgresFormat = new SimpleDateFormat("yyyy/MM");
+ String beginDateStr = report_dateFormat.format(beginDate);
+ String endDateStr = report_dateFormat.format(endDate);
+
+ Connection connection = null;
+ PreparedStatement st = null;
+ ResultSet rs = null;
+ String platform = getInstitutionName(repositoryIdentifier);
+
+ if (itemIdentifier.equals("")) {
+ try {
+ connection = usageStatsDB.getConnection();
+
+ if (granularity.equalsIgnoreCase("totals")) {
+
+// st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
+// + "SELECT rc.type, sum(us.downloads) as downloads, sum(us.views) as views, "
+// + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
+// + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews, "
+// + "case when us.source='Datacite' then dp.access_method else 'regular' end as access_method "
+// + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
+// + statsDB + ".result_oids ro, tpd, datasetsusagestats_20210312a.datasetsperformance dp "
+// + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND rc.id=us.result_id "
+// + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id AND rc.type='Dataset' AND dp.ds_type=ro.oid "
+// + "GROUP BY us.source, ro.id, rc.type, rs.title, us.result_id, rs.year, dp.access_method ORDER by rc.type ASC;");
+ st = connection.prepareStatement("SELECT 'Dataset' as type, sum(case when dp.metric_type='total-dataset-requests' then count else 0 end) as downloads, "
+ + "sum(case when dp.metric_type='total-dataset-investigations' then count else 0 end) as views, "
+ + "rp.id as resultid,dp.ds_title as item, dp.yop as yop, concat('Digital Object Identifier#-#',dp.ds_type) as oid, "
+ + "sum(case when dp.metric_type='unique-dataset-requests' then count else 0 end) as uniquedownloads, "
+ + "sum(case when dp.metric_type='unique-dataset-investigations' then count else 0 end) as uniqueviews, "
+ + "dp.access_method access_method, dp.platform FROM openaire_prod_datacite_usage_stats.datasetsperformance_nonarray_view dp, "
+ + statsDB + ".result_pids rp, " + statsDB + ".datasource ds "
+ + "WHERE dp.period_from>=? AND dp.period_end<=? and rp.pid=ds_type and ds.id=? and ds.name=dp.platform "
+ + "GROUP BY dp.ds_title, dp.yop, dp.platform, dp.access_method, dp.ds_type,rp.id");
+ st.setString(1, beginDateStr);
+ st.setString(2, endDateStr);
+ st.setString(3, repositoryIdentifier);
+
+ rs = st.executeQuery();
+ COUNTER_Dataset_Usage reportItem = null;
+ boolean[] metricTypeValue = {false, false, false, false};
+
+ if (metricType.contains("Total_Dataset_Requests")) {
+ metricTypeValue[0] = true;
+ }
+ if (metricType.contains("Total_Dataset_Investigations")) {
+ metricTypeValue[1] = true;
+ }
+ if (metricType.contains("Unique_Dataset_Requests")) {
+ metricTypeValue[2] = true;
+ }
+ if (metricType.contains("Unique_Dataset_Investigations")) {
+ metricTypeValue[3] = true;
+ }
+ while (rs.next()) {
+ reportItem = new COUNTER_Dataset_Usage(rs.getString(5), "OpenAIRE", platform, rs.getString(1), Integer.toString(rs.getInt(6)), rs.getString(10));
+ String[] identifiersAll = rs.getString(7).split("#!#");
+ for (int i = 0; i < identifiersAll.length; i++) {
+ String[] typeIdentifierArray = identifiersAll[i].split("#-#");
+ reportItem.addIdentifier(new COUNTER_Dataset_Identifiers(typeIdentifierArray[0], typeIdentifierArray[1]));
+ }
+
+ reportItem.addPerformance(new COUNTER_Dataset_Performance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate),
+ metricTypeValue[0] == true ? rs.getString(2) : null, metricTypeValue[1] == true ? rs.getString(3) : null, metricTypeValue[2] == true ? rs.getString(8) : null, metricTypeValue[3] == true ? rs.getString(9) : null));
+ reportItems.add(reportItem);
+ }
+ //}
+ } else if (granularity.equalsIgnoreCase("monthly")) {
+// st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
+// + "SELECT rc.type, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
+// + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
+// + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews, "
+// + "case when us.source='Datacite' then dp.access_method else 'regular' end as access_method "
+// + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
+// + statsDB + ".result_oids ro, tpd, datasetsusagestats_20210312a.datasetsperformance dp "
+// + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND rc.id=us.result_id "
+// + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id AND rc.type='Dataset' AND dp.ds_type=ro.oid "
+// + "GROUP BY us.source, ro.id, rc.type, rs.title, us.result_id, us.`date`, rs.year, dp.access_method ORDER by rc.type, us.`date` ASC;");
+
+ st = connection.prepareStatement("SELECT 'Dataset' as type, dp.period_from, sum(case when dp.metric_type='total-dataset-requests' then count else 0 end) as downloads, "
+ + "sum(case when dp.metric_type='total-dataset-investigations' then count else 0 end) as views, "
+ + "rp.id as resultid,dp.ds_title as item, dp.yop as yop, concat('Digital Object Identifier#-#',dp.ds_type) as oid, "
+ + "sum(case when dp.metric_type='unique-dataset-requests' then count else 0 end) as uniquedownloads, "
+ + "sum(case when dp.metric_type='unique-dataset-investigations' then count else 0 end) as uniqueviews, "
+ + "dp.access_method access_method, dp.platform FROM openaire_prod_datacite_usage_stats.datasetsperformance_nonarray_view dp, "
+ + statsDB + ".result_pids rp, " + statsDB + ".datasource ds "
+ + "WHERE dp.period_from>=? AND dp.period_end<=? and rp.pid=ds_type and ds.id=? and ds.name=dp.platform "
+ + "GROUP BY dp.ds_title, dp.yop, dp.platform, dp.access_method, dp.ds_type,rp.id, dp.period_from");
+
+ st.setString(1, beginDateStr);
+ st.setString(2, endDateStr);
+ st.setString(3, repositoryIdentifier);
+ rs = st.executeQuery();
+
+ String result = "";
+ String lastDate = "";
+ COUNTER_Dataset_Usage reportItem = null;
+ boolean[] metricTypeValue = {false, false, false, false};
+
+ if (metricType.contains("Total_Dataset_Requests")) {
+ metricTypeValue[0] = true;
+ }
+ if (metricType.contains("Total_Dataset_Investigations")) {
+ metricTypeValue[1] = true;
+ }
+ if (metricType.contains("Unique_Dataset_Requests")) {
+ metricTypeValue[2] = true;
+ }
+ if (metricType.contains("Unique_Dataset_Investigations")) {
+ metricTypeValue[3] = true;
+ }
+
+ int ft_total = 0;
+ int abstr = 0;
+
+ Calendar endCal = Calendar.getInstance();
+ endCal.setTime(report_dateFormat.parse(endDateStr));
+ endCal.add(Calendar.MONTH, 1);
+ Date endDateForZeros = endCal.getTime();
+
+ lastDate = beginDateStr;
+ String datatype = "";
+ List identifiers = null;
+
+ while (rs.next()) {
+ Calendar endC = Calendar.getInstance();
+ endC.setTime(report_dateFormat.parse(rs.getString(2)));
+ endC.set(Calendar.DATE, endC.getActualMaximum(Calendar.DATE));
+// //iterate on data types
+ if (!datatype.equals(rs.getString(1))) {
+// if (reportItem != null) {
+// reportItems.add(reportItem);
+// }
+// reportItem = new COUNTER_Platform_Usage("", "OpenAIRE", rs.getString(1), "Regular", "");
+ datatype = rs.getString(1);
+ }
+
+ reportItem = new COUNTER_Dataset_Usage(rs.getString(6), "OpenAIRE", platform, rs.getString(1), Integer.toString(rs.getInt(7)), rs.getString(11));
+ String[] identifiersAll = rs.getString(8).split("#!#");
+ for (int i = 0; i < identifiersAll.length; i++) {
+ String[] typeIdentifierArray = identifiersAll[i].split("#-#");
+ reportItem.addIdentifier(new COUNTER_Dataset_Identifiers(typeIdentifierArray[0], typeIdentifierArray[1]));
+ }
+ reportItem.addPerformance(new COUNTER_Dataset_Performance(report_dateFormat.format(report_dateFormat.parse(rs.getString(2))), report_dateFormat.format(endC.getTime()),
+ metricTypeValue[0] == true ? rs.getString(3) : null, metricTypeValue[1] == true ? rs.getString(4) : null, metricTypeValue[2] == true ? rs.getString(9) : null, metricTypeValue[3] == true ? rs.getString(10) : null));
+ reportItems.add(reportItem);
+
+ endC.setTime(report_dateFormat.parse(rs.getString(2)));
+ endC.add(Calendar.MONTH, 1);
+ lastDate = report_dateFormat.format(endC.getTime());
+ //if (reportItem != null) {
+ //fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
+ }
+ }
+ /*
+ jedis.put(redis_key, "persistent", "false");
+ jedis.put(redis_key, "query", st.toString());
+ jedis.put(redis_key, "result", toJson(reportItems));
+ jedis.put(redis_key, "fetchMode", "3");
+ */
+ } catch (Exception e) {
+ log.error("Batch Item Report failed: ", e);
+ } finally {
+ DbUtils.closeQuietly(rs);
+ DbUtils.closeQuietly(st);
+ DbUtils.closeQuietly(connection);
+ }
+ } else {
+ try {
+ connection = usageStatsDB.getConnection();
+
+ if (granularity.equalsIgnoreCase("totals")) {
+// st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
+// + "SELECT rc.type, sum(us.downloads) as downloads, sum(us.views) as views, "
+// + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
+// + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews,"
+// + "case when us.source='Datacite' then dp.access_method else 'regular' end as access_method "
+// + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
+// + statsDB + ".result_oids ro, tpd, datasetsusagestats_20210312a.datasetsperformance dp "
+// + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND us.result_id=? AND rc.id=us.result_id "
+// + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id AND rc.type='Dataset' AND dp.ds_type=ro.oid "
+// + "GROUP BY us.source, ro.id, rc.type, rs.title, us.result_id, rs.year, dp.access_method ORDER by rc.type ASC;");
+ st = connection.prepareStatement("SELECT 'Dataset' as type, sum(case when dp.metric_type='total-dataset-requests' then count else 0 end) as downloads, "
+ + "sum(case when dp.metric_type='total-dataset-investigations' then count else 0 end) as views, "
+ + "rp.id as resultid,dp.ds_title as item, dp.yop as yop, concat('Digital Object Identifier#-#',dp.ds_type) as oid, "
+ + "sum(case when dp.metric_type='unique-dataset-requests' then count else 0 end) as uniquedownloads, "
+ + "sum(case when dp.metric_type='unique-dataset-investigations' then count else 0 end) as uniqueviews, "
+ + "dp.access_method access_method, dp.platform FROM openaire_prod_datacite_usage_stats.datasetsperformance_nonarray_view dp, "
+ + statsDB + ".result_pids rp, " + statsDB + ".datasource ds "
+ + "WHERE dp.period_from>=? AND dp.period_end<=? and rp.pid=ds_type and ds.id=? AND rp.id=? and ds.name=dp.platform "
+ + "GROUP BY dp.ds_title, dp.yop, dp.platform, dp.access_method, dp.ds_type,rp.id");
+ st.setString(1, beginDateStr);
+ st.setString(2, endDateStr);
+ st.setString(3, repositoryIdentifier);
+ st.setString(4, itemIdentifier);
+
+ rs = st.executeQuery();
+ COUNTER_Dataset_Usage reportItem = null;
+ boolean[] metricTypeValue = {false, false, false, false};
+ if (metricType.contains("Total_Dataset_Requests")) {
+ metricTypeValue[0] = true;
+ }
+ if (metricType.contains("Total_Dataset_Investigations")) {
+ metricTypeValue[1] = true;
+ }
+ if (metricType.contains("Unique_Dataset_Requests")) {
+ metricTypeValue[2] = true;
+ }
+ if (metricType.contains("Unique_Dataset_Investigations")) {
+ metricTypeValue[3] = true;
+ }
+
+ while (rs.next()) {
+ reportItem = new COUNTER_Dataset_Usage(rs.getString(5), "OpenAIRE", platform, rs.getString(1), Integer.toString(rs.getInt(6)), rs.getString(10));
+ String[] identifiersAll = rs.getString(7).split("#!#");
+ for (int i = 0; i < identifiersAll.length; i++) {
+ String[] typeIdentifierArray = identifiersAll[i].split("#-#");
+ reportItem.addIdentifier(new COUNTER_Dataset_Identifiers(typeIdentifierArray[0], typeIdentifierArray[1]));
+ }
+ reportItem.addPerformance(new COUNTER_Dataset_Performance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate),
+ metricTypeValue[0] == true ? rs.getString(2) : null, metricTypeValue[1] == true ? rs.getString(3) : null, metricTypeValue[2] == true ? rs.getString(8) : null, metricTypeValue[3] == true ? rs.getString(9) : null));
+ reportItems.add(reportItem);
+ }
+ } else if (granularity.equalsIgnoreCase("monthly")) {
+
+// st = connection.prepareStatement("WITH tpd as (select id, concat(type,'#-#',pid) type_id from " + statsDB + ".result_pids) "
+// + "SELECT rc.type, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views, "
+// + "us.result_id as resultid, rs.title as item, rs.year as yop, group_concat(distinct tpd.type_id,'#!#') as oid, "
+// + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews, "
+// + "case when us.source='Datacite' then dp.access_method else 'regular' end as access_method "
+// + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc, " + statsDB + ".result rs, "
+// + statsDB + ".result_oids ro, tpd, datasetsusagestats_20210312a.datasetsperformance dp "
+// + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? AND us.result_id=? AND rc.id=us.result_id "
+// + "AND us.result_id=rs.id AND ro.id=us.result_id AND tpd.id=us.result_id AND rc.type='Dataset' AND dp.ds_type=ro.oid "
+// + "GROUP BY us.source, ro.id, rc.type, rs.title, us.result_id, us.`date`, rs.year, dp.access_method ORDER by rc.type, us.`date` ASC;");
+ st = connection.prepareStatement("SELECT 'Dataset' as type, dp.period_from, sum(case when dp.metric_type='total-dataset-requests' then count else 0 end) as downloads, "
+ + "sum(case when dp.metric_type='total-dataset-investigations' then count else 0 end) as views, "
+ + "rp.id as resultid,dp.ds_title as item, dp.yop as yop, concat('Digital Object Identifier#-#',dp.ds_type) as oid, "
+ + "sum(case when dp.metric_type='unique-dataset-requests' then count else 0 end) as uniquedownloads, "
+ + "sum(case when dp.metric_type='unique-dataset-investigations' then count else 0 end) as uniqueviews, "
+ + "dp.access_method access_method, dp.platform FROM openaire_prod_datacite_usage_stats.datasetsperformance_nonarray_view dp, "
+ + statsDB + ".result_pids rp, " + statsDB + ".datasource ds "
+ + "WHERE dp.period_from>=? AND dp.period_end<=? and rp.pid=ds_type and ds.id=? AND rp.id=? and ds.name=dp.platform "
+ + "GROUP BY dp.ds_title, dp.yop, dp.platform, dp.access_method, dp.ds_type,rp.id, dp.period_from");
+ st.setString(1, beginDateStr);
+ st.setString(2, endDateStr);
+ st.setString(3, repositoryIdentifier);
+ st.setString(4, itemIdentifier);
+
+ rs = st.executeQuery();
+ String result = "";
+ String lastDate = "";
+ COUNTER_Dataset_Usage reportItem = null;
+
+ boolean[] metricTypeValue = {false, false, false, false};
+
+ if (metricType.contains("Total_Dataset_Requests")) {
+ metricTypeValue[0] = true;
+ }
+ if (metricType.contains("Total_Dataset_Investigations")) {
+ metricTypeValue[1] = true;
+ }
+ if (metricType.contains("Unique_Dataset_Requests")) {
+ metricTypeValue[2] = true;
+ }
+ if (metricType.contains("Unique_Dataset_Investigations")) {
+ metricTypeValue[3] = true;
+ }
+
+ int ft_total = 0;
+ int abstr = 0;
+
+ Calendar endCal = Calendar.getInstance();
+ endCal.setTime(report_dateFormat.parse(endDateStr));
+ endCal.add(Calendar.MONTH, 1);
+ Date endDateForZeros = endCal.getTime();
+
+ lastDate = beginDateStr;
+ String datatype = "";
+
+ while (rs.next()) {
+ Calendar endC = Calendar.getInstance();
+ endC.setTime(report_dateFormat.parse(rs.getString(2)));
+ endC.set(Calendar.DATE, endC.getActualMaximum(Calendar.DATE));
+// //iterate on data types
+ if (!datatype.equals(rs.getString(1))) {
+ datatype = rs.getString(1);
+ }
+
+ reportItem = new COUNTER_Dataset_Usage(rs.getString(6), "OpenAIRE", platform, rs.getString(1), Integer.toString(rs.getInt(7)), rs.getString(11));
+ String[] identifiersAll = rs.getString(8).split("#!#");
+ for (int i = 0; i < identifiersAll.length; i++) {
+ String[] typeIdentifierArray = identifiersAll[i].split("#-#");
+ reportItem.addIdentifier(new COUNTER_Dataset_Identifiers(typeIdentifierArray[0], typeIdentifierArray[1]));
+ }
+ reportItem.addPerformance(new COUNTER_Dataset_Performance(report_dateFormat.format(report_dateFormat.parse(rs.getString(2))), report_dateFormat.format(endC.getTime()),
+ metricTypeValue[0] == true ? rs.getString(3) : null, metricTypeValue[1] == true ? rs.getString(4) : null, metricTypeValue[2] == true ? rs.getString(9) : null, metricTypeValue[3] == true ? rs.getString(10) : null));
+ reportItems.add(reportItem);
+
+ endC.setTime(report_dateFormat.parse(rs.getString(2)));
+ endC.add(Calendar.MONTH, 1);
+ lastDate = report_dateFormat.format(endC.getTime());
+ //if (reportItem != null) {
+ //fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
+ }
+ }
+ /*
+ jedis.put(redis_key, "persistent", "false");
+ jedis.put(redis_key, "query", st.toString());
+ jedis.put(redis_key, "result", toJson(reportItems));
+ jedis.put(redis_key, "fetchMode", "3");
+ */
+ } catch (Exception e) {
+ log.error("Batch Item Report failed: ", e);
+ } finally {
+ DbUtils.closeQuietly(rs);
+ DbUtils.closeQuietly(st);
+ DbUtils.closeQuietly(connection);
+ }
+ }
+ }
+
+// public void executeItemsAllRepoDSRDatacite(List reportItems,
+// String itemIdentifier, Date beginDate,
+// Date endDate, List metricType, String granularity) throws Exception {
+// SimpleDateFormat report_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+// SimpleDateFormat postgresFormat = new SimpleDateFormat("yyyy/MM");
+// String beginDateStr = postgresFormat.format(beginDate);
+// String endDateStr = postgresFormat.format(endDate);
+//
+// Connection connection = null;
+// PreparedStatement st = null;
+// ResultSet rs = null;
+//
+// try {
+// connection = usageStatsDB.getConnection();
+//
+// if (granularity.equalsIgnoreCase("totals")) {
+//
+//// st = connection.prepareStatement("WITH tpd as (SELECT distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+//// + "SELECT type, downloads, views, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, uniquedownloads,uniqueviews, 'Regular' as access_method "
+//// + "FROM (SELECT us.repository_id repo, rc.type type, sum(us.downloads) as downloads, sum(us.views) as views, "
+//// + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+//// + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
+//// + "FROM " + usagestatsImpalaDB + ".usage_stats us,(SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, openaire_prod_stats.result rs "
+//// + "WHERE us.`date`>=? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id AND us.result_id=? "
+//// + "AND rc.type='Dataset' GROUP BY rc.type, rs.title, us.result_id, rs.title, rs.year, us.repository_id) tmp, tpd "
+//// + "WHERE tpd.id=resultid GROUP BY repo, type,resultid,item,yop,downloads,views,uniquedownloads,uniqueviews");
+// st = connection.prepareStatement("SELECT 'Dataset' as type, sum(case when dp.metric_type='total-dataset-requests' then count else 0 end) as downloads, "
+// + "sum(case when dp.metric_type='total-dataset-investigations' then count else 0 end) as views, "
+// + "rp.id as resultid,dp.ds_title as item, dp.yop as yop, concat('Digital Object Identifier#-#',dp.ds_type) as oid, "
+// + "sum(case when dp.metric_type='unique-dataset-requests' then count else 0 end) as uniquedownloads, "
+// + "sum(case when dp.metric_type='unique-dataset-investigations' then count else 0 end) as uniqueviews, "
+// + "dp.access_method access_method, dp.platform FROM datasetsusagestats_20210312a.datasetsperformance dp, "
+// + statsDB + ".result_pids rp, " + statsDB + ".datasource ds "
+// + "WHERE dp.period_from>=? AND dp.period_end<=? and rp.pid=ds_type AND rp.id=? and ds.name=dp.platform "
+// + "GROUP BY dp.ds_title, dp.yop, dp.platform, dp.access_method, dp.ds_type,rp.id");
+// st.setString(1, beginDateStr);
+// st.setString(2, endDateStr);
+// st.setString(3, itemIdentifier);
+//
+// rs = st.executeQuery();
+// COUNTER_Dataset_Usage reportItem = null;
+// boolean[] metricTypeValue = {false, false, false, false};
+//
+// if (metricType.contains("Total_Dataset_Requests")) {
+// metricTypeValue[0] = true;
+// }
+// if (metricType.contains("Total_Dataset_Investigations")) {
+// metricTypeValue[1] = true;
+// }
+// if (metricType.contains("Unique_Dataset_Requests")) {
+// metricTypeValue[2] = true;
+// }
+// if (metricType.contains("Unique_Dataset_Investigations")) {
+// metricTypeValue[3] = true;
+// }
+//
+// while (rs.next()) {
+// String platform = getInstitutionName(rs.getString(8));
+// reportItem = new COUNTER_Dataset_Usage(rs.getString(5), "OpenAIRE", rs.getString(8), rs.getString(1), Integer.toString(rs.getInt(6)), rs.getString(11));
+// String[] identifiersAll = rs.getString(7).split("#!#");
+// for (int i = 0; i < identifiersAll.length; i++) {
+// String[] typeIdentifierArray = identifiersAll[i].split("#-#");
+// reportItem.addIdentifier(new COUNTER_Dataset_Identifiers(typeIdentifierArray[0], typeIdentifierArray[1]));
+// }
+//
+// reportItem.addPerformance(new COUNTER_Dataset_Performance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate),
+// metricTypeValue[0] == true ? rs.getString(2) : null, metricTypeValue[1] == true ? rs.getString(3) : null, metricTypeValue[2] == true ? rs.getString(9) : null, metricTypeValue[3] == true ? rs.getString(10) : null));
+// reportItems.add(reportItem);
+// }
+//
+// //}
+// } else if (granularity.equalsIgnoreCase("monthly")) {
+//
+//// st = connection.prepareStatement("WITH tpd as (SELECT distinct id, concat(type,'#-#',pid) type_id FROM " + statsDB + ".result_pids) "
+//// + "SELECT type, `date`, downloads, views, resultid, item,yop,group_concat(distinct tpd.type_id,'#!#') as oid, uniquedownloads,uniqueviews, 'Regular' as access_method "
+//// + "FROM (SELECT us.repository_id repo, us.`date` as `date`, rc.type type, sum(us.downloads) as downloads, sum(us.views) as views, "
+//// + "us.result_id as resultid, rs.title as item, rs.year as yop, "
+//// + "count(case when us.downloads >0 then 1 else null end) as uniquedownloads, count(case when us.views >0 then 1 else null end) as uniqueviews "
+//// + "FROM " + usagestatsImpalaDB + ".usage_stats us,(SELECT distinct id, type FROM " + statsDB + ".result_classifications) rc, openaire_prod_stats.result rs "
+//// + "WHERE us.`date`>=? AND us.`date`<=? AND rc.id=us.result_id AND us.result_id=rs.id AND us.result_id=? "
+//// + "AND rc.type='Dataset' GROUP BY rc.type, us.`date`, rs.title, us.result_id, rs.title, rs.year, us.`date`) tmp, tpd "
+//// + "WHERE tpd.id=resultid GROUP BY repo,`date`, type,resultid,item,yop,downloads,views,uniquedownloads,uniqueviews ORDER BY `date` ASC;");
+// st = connection.prepareStatement("SELECT 'Dataset' as type, dp.period_from, sum(case when dp.metric_type='total-dataset-requests' then count else 0 end) as downloads, "
+// + "sum(case when dp.metric_type='total-dataset-investigations' then count else 0 end) as views, "
+// + "rp.id as resultid,dp.ds_title as item, dp.yop as yop, concat('Digital Object Identifier#-#',dp.ds_type) as oid, "
+// + "sum(case when dp.metric_type='unique-dataset-requests' then count else 0 end) as uniquedownloads, "
+// + "sum(case when dp.metric_type='unique-dataset-investigations' then count else 0 end) as uniqueviews, "
+// + "dp.access_method access_method, dp.platform FROM datasetsusagestats_20210312a.datasetsperformance dp, "
+// + statsDB + ".result_pids rp, " + statsDB + ".datasource ds "
+// + "WHERE dp.period_from>=? AND dp.period_end<=? and rp.pid=ds_type and rp.id=? and ds.name=dp.platform "
+// + "GROUP BY dp.ds_title, dp.yop, dp.platform, dp.access_method, dp.ds_type,rp.id, dp.period_from");
+// st.setString(1, beginDateStr);
+// st.setString(2, endDateStr);
+// st.setString(3, itemIdentifier);
+//
+// rs = st.executeQuery();
+// String result = "";
+// String lastDate = "";
+// COUNTER_Dataset_Usage reportItem = null;
+// boolean[] metricTypeValue = {false, false, false, false};
+//
+// if (metricType.contains("Total_Dataset_Requests")) {
+// metricTypeValue[0] = true;
+// }
+// if (metricType.contains("Total_Dataset_Investigations")) {
+// metricTypeValue[1] = true;
+// }
+// if (metricType.contains("Unique_Dataset_Requests")) {
+// metricTypeValue[2] = true;
+// }
+// if (metricType.contains("Unique_Dataset_Investigations")) {
+// metricTypeValue[3] = true;
+// }
+//
+// int ft_total = 0;
+// int abstr = 0;
+//
+// Calendar endCal = Calendar.getInstance();
+// endCal.setTime(postgresFormat.parse(endDateStr));
+// endCal.add(Calendar.MONTH, 1);
+// Date endDateForZeros = endCal.getTime();
+//
+// lastDate = beginDateStr;
+// String datatype = "";
+//
+// while (rs.next()) {
+// Calendar endC = Calendar.getInstance();
+// endC.setTime(postgresFormat.parse(rs.getString(2)));
+// endC.set(Calendar.DATE, endC.getActualMaximum(Calendar.DATE));
+//// //iterate on data types
+// if (!datatype.equals(rs.getString(1))) {
+//// if (reportItem != null) {
+//// reportItems.add(reportItem);
+//// }
+//// reportItem = new COUNTER_Platform_Usage("", "OpenAIRE", rs.getString(1), "Regular", "");
+// datatype = rs.getString(1);
+// }
+// reportItem = new COUNTER_Dataset_Usage(rs.getString(6), "OpenAIRE", rs.getString(9), rs.getString(1), Integer.toString(rs.getInt(7)), rs.getString(12));
+// String[] identifiersAll = rs.getString(8).split("#!#");
+// for (int i = 0; i < identifiersAll.length; i++) {
+// String[] typeIdentifierArray = identifiersAll[i].split("#-#");
+// reportItem.addIdentifier(new COUNTER_Dataset_Identifiers(typeIdentifierArray[0], typeIdentifierArray[1]));
+// }
+//
+// reportItem.addPerformance(new COUNTER_Dataset_Performance(report_dateFormat.format(postgresFormat.parse(rs.getString(2))), report_dateFormat.format(endC.getTime()),
+// metricTypeValue[0] == true ? rs.getString(3) : null, metricTypeValue[1] == true ? rs.getString(4) : null, metricTypeValue[2] == true ? rs.getString(10) : null, metricTypeValue[3] == true ? rs.getString(11) : null));
+// reportItems.add(reportItem);
+//
+// endC.setTime(postgresFormat.parse(rs.getString(2)));
+// endC.add(Calendar.MONTH, 1);
+// lastDate = postgresFormat.format(endC.getTime());
+// //if (reportItem != null) {
+// //fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
+// }
+// }
+// /*
+// jedis.put(redis_key, "persistent", "false");
+// jedis.put(redis_key, "query", st.toString());
+// jedis.put(redis_key, "result", toJson(reportItems));
+// jedis.put(redis_key, "fetchMode", "3");
+// */
+// } catch (Exception e) {
+// log.error("Batch Item Report failed: ", e);
+// } finally {
+// DbUtils.closeQuietly(rs);
+// DbUtils.closeQuietly(st);
+// DbUtils.closeQuietly(connection);
+// }
+// }
+
private void fillWithZeros(Date from, Date to, COUNTER_Platform_Usage reportItem) {
SimpleDateFormat report_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
@@ -2612,4 +3119,33 @@ public class UsageStatsRepository {
return membersList;
}
+
+ public boolean checkIfDatacite(String repositoryIdentifer) {
+ PreparedStatement st = null;
+ Connection connection = null;
+ ResultSet rs = null;
+ boolean dataciteMember = false;
+
+ try {
+ connection = usageStatsDB.getConnection();
+ st = connection.prepareStatement("select distinct source from " + usagestatsImpalaDB + ".usage_stats where repository_id=?;");
+ st.setString(1, repositoryIdentifer);
+
+ rs = st.executeQuery();
+
+ while (rs.next()) {
+ if (rs.getString(1).equals("Datacite")) {
+ dataciteMember = true;
+ }
+ }
+
+ } catch (Exception e) {
+ log.error("No member found " + e);
+ } finally {
+ DbUtils.closeQuietly(rs);
+ DbUtils.closeQuietly(st);
+ DbUtils.closeQuietly(connection);
+ }
+ return dataciteMember;
+ }
}
diff --git a/src/main/java/eu/dnetlib/usagestats/services/SushiLiteServiceImpl.java b/src/main/java/eu/dnetlib/usagestats/services/SushiLiteServiceImpl.java
index 0101a05..3482c4e 100755
--- a/src/main/java/eu/dnetlib/usagestats/services/SushiLiteServiceImpl.java
+++ b/src/main/java/eu/dnetlib/usagestats/services/SushiLiteServiceImpl.java
@@ -316,7 +316,7 @@ public class SushiLiteServiceImpl implements SushiLiteService {
SUSHI_Report_List r4 = new SUSHI_Report_List("Platform Master Report PR", "PR", "5", "A customizable report summarizing activity across a provider’s platforms that allows the user to apply filters and select other configuration options for the report. ", "/PR");
SUSHI_Report_List r5 = new SUSHI_Report_List("Platform Usage Report", "PR_P1", "5", "Standard View of the Package Master Report that presents usage for the overall Platform broken down by Metric_Type.", "/PR_1");
SUSHI_Report_List r6 = new SUSHI_Report_List("Platform Item Report", "IR", "5", "COUNTER Item Master Report", "/IR");
- SUSHI_Report_List r7 = new SUSHI_Report_List("Datasets Report", "IR", "5", "COUNTER Datasets Report", "/DSR");
+ SUSHI_Report_List r7 = new SUSHI_Report_List("Datasets Report", "DSR", "5", "COUNTER Datasets Report", "/DSR");
reportSupportedList.add(r1);
reportSupportedList.add(r2);
@@ -596,6 +596,28 @@ public class SushiLiteServiceImpl implements SushiLiteService {
reportExceptions.add(new SUSHI_Error_Model("3021", "Warning", "Unspecified Date Arguments", "usagecounts.openaire.eu", "End Date set to default: " + new SimpleDateFormat("yyyy-MM-dd").format(endDateParsed)));
}
+
+ // Calucalte time difference
+ // in milliseconds
+ beginDateParsed = tryParse(beginDate);
+ Calendar temp = Calendar.getInstance();
+ temp.setTime(beginDateParsed);
+ temp.set(Calendar.DAY_OF_MONTH, temp.getActualMaximum(Calendar.DAY_OF_MONTH));
+ beginDateParsed = temp.getTime();
+
+
+ endDateParsed = tryParse(endDate);
+ Calendar temp1 = Calendar.getInstance();
+ temp1.setTime(endDateParsed);
+ temp1.set(Calendar.DAY_OF_MONTH, temp1.getActualMaximum(Calendar.DAY_OF_MONTH));
+ endDateParsed = temp1.getTime();
+
+ long difference_In_Time
+ = endDateParsed.getTime() - beginDateParsed.getTime();
+ long difference_In_Years = (difference_In_Time/ (1000 * 60 * 60 * 24));
+
+ if(difference_In_Years>365)
+ reportExceptions.add(new SUSHI_Error_Model("4000", "Notice", "Requested Period for more than a year not allowed", "usagecounts.openaire.eu", "Contact usagecounts@openaire.eu for longer period"));
// if (beginDateParsed == null) {
// reportExceptions.add(new SUSHI_Error_Model("3020", "Error", "Invalid Date Arguments", "usagecounts.openaire.eu", "Begin Date: " + beginDate + " is not a valid date"));
// }
@@ -809,7 +831,10 @@ public class SushiLiteServiceImpl implements SushiLiteService {
//reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
//}
} else if (!repoid.equals("")) {
- usageStatsRepository.executeBatchItemsDSR(reportItems, repoid, itemIdentifier, beginDateParsed, endDateParsed, metricType, granularity);
+ if(usageStatsRepository.checkIfDatacite(repoid))
+ usageStatsRepository.executeBatchItemsDSRDatacite(reportItems, repoid, itemIdentifier, beginDateParsed, endDateParsed, metricType, granularity);
+ else
+ usageStatsRepository.executeBatchItemsDSR(reportItems, repoid, itemIdentifier, beginDateParsed, endDateParsed, metricType, granularity);
if (reportItems.isEmpty()) {
reportExceptions.add(new SUSHI_Error_Model("3030", "Error", "usagecounts.openaire.eu", "No Usage Available for Requested Dates", "Service did not find any data"));
}
diff --git a/src/main/java/eu/dnetlib/usagestats/services/UsageStatsService.java b/src/main/java/eu/dnetlib/usagestats/services/UsageStatsService.java
old mode 100644
new mode 100755
index 23324dd..1e3ee05
--- a/src/main/java/eu/dnetlib/usagestats/services/UsageStatsService.java
+++ b/src/main/java/eu/dnetlib/usagestats/services/UsageStatsService.java
@@ -13,6 +13,7 @@ public interface UsageStatsService {
UsageStats getDatasourceClicks(String id);
UsageStats getProjectClicks(String id);
UsageStats getResultClicks(String id);
+ UsageStats getResultClicksByPID(String resultPID);
//UsageStats getOrganizationClicks(String id);
TotalStats getTotalStats();
List getMonthlyUsageStats();
diff --git a/src/main/java/eu/dnetlib/usagestats/services/UsageStatsServiceImpl.java b/src/main/java/eu/dnetlib/usagestats/services/UsageStatsServiceImpl.java
old mode 100644
new mode 100755
index 88cb3f6..e051089
--- a/src/main/java/eu/dnetlib/usagestats/services/UsageStatsServiceImpl.java
+++ b/src/main/java/eu/dnetlib/usagestats/services/UsageStatsServiceImpl.java
@@ -86,6 +86,24 @@ public class UsageStatsServiceImpl implements UsageStatsService {
return usageStatsRepository.executeUsageStats(query, values, "result");
}
+ @Override
+ public UsageStats getResultClicksByPID(String resultPID) {
+ String query = "SELECT 'views', s.repository_id, CASE WHEN s.source='OpenAIRE' THEN d.name ELSE concat(d.name,' - ',s.source) END, sum(count), sum(openaire) "
+ + "FROM (select distinct * from "+usagestatsImpalaDB+".views_stats) s, "+statsDB+".datasource d WHERE s.repository_id=d.id "
+ + "AND s.result_id in (select distinct id from "+ statsDB+".result_oids WHERE oid=?) GROUP BY s.source, s.repository_id, d.name "
+ + "UNION ALL SELECT 'downloads', s.repository_id, CASE WHEN s.source='OpenAIRE' THEN d.name ELSE concat(d.name,' - ',s.source) END, sum(count), sum(s.openaire) "
+ + "FROM (select distinct * from "+usagestatsImpalaDB+".downloads_stats) s, "+statsDB+".datasource d WHERE s.repository_id=d.id "
+ + "AND s.result_id in (select distinct id from "+ statsDB+".result_oids WHERE oid=?) GROUP BY s.source, s.repository_id, d.name "
+ + "UNION ALL SELECT 'pageviews', 'OpenAIRE id', 'OpenAIRE', sum(count), 0 FROM "+usagestatsImpalaDB+".pageviews_stats s "
+ + "WHERE result_id in (select distinct id from "+ statsDB+".result_oids WHERE oid=?);";
+
+ List values = new ArrayList<>();
+ values.add(resultPID);
+ values.add(resultPID);
+ values.add(resultPID);
+
+ return usageStatsRepository.executeUsageStats(query, values, "result");
+ }
@Override
public TotalStats getTotalStats() {
return usageStatsRepository.executeTotalStats();
diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties
index d20fcd2..fbd4efc 100755
--- a/src/main/resources/log4j.properties
+++ b/src/main/resources/log4j.properties
@@ -10,9 +10,9 @@ log4j.additivity.org.springframework = false
log4j.appender.R=org.apache.log4j.RollingFileAppender
#log4j.appender.R.File=/var/log/dnet/usageStatsAPI/usageStatsAPI_R5.log
#log4j.appender.R.File=/home/dimitris.pierrakos/Sushilite_R5/usageStatsAPI_R5.log
-#log4j.appender.R.File=/Users/dpie/Desktop/usageStatsAPI_R5.log
+log4j.appender.R.File=/Users/dpie/OneDrive/Research/Projects/OpenAIRE Usage Statistics Service/Code/code-repo.d4science.org/Sushilite-R5/usageStatsAPI_R5.log
#log4j.appender.R.File=/srv/springboot/9880/usageStatsAPI_R5.log
-log4j.appender.R.File=/home/dpie/Desktop/usageStatsAPI_R5.log
+#log4j.appender.R.File=/home/dpie/Desktop/usageStatsAPI_R5.log
loglog4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=10
log4j.appender.R.layout=org.apache.log4j.PatternLayout
@@ -20,10 +20,10 @@ log4j.appender.R.layout.ConversionPattern= %d %p %t [%c] - %m%n
log4j.appender.S=org.apache.log4j.RollingFileAppender
#log4j.appender.S.File=/var/log/dnet/usageStatsAPI/usageStatsAPI_R5-spring.log
#log4j.appender.S.File=/home/dimitris.pierrakos/Sushilite_R5/usageStatsAPI_R5-spring.log
-#log4j.appender.S.File=/Users/dpie/Desktop/usageStatsAPI_R5-spring.log
+log4j.appender.S.File=/Users/dpie/OneDrive/Research/Projects/OpenAIRE Usage Statistics Service/Code/code-repo.d4science.org/Sushilite-R5/usageStatsAPI_R5-spring.log
#log4j.appender.S.File=/Volumes/Zeus/dpie/Desktop/usageStatsAPI_R5-spring.log
#log4j.appender.S.File=/srv/springboot/9880/usageStatsAPI_R5-spring.log
-log4j.appender.S.File=/home/dpie/Desktop/usageStatsAPI_R5-spring.log
+#log4j.appender.S.File=/home/dpie/Desktop/usageStatsAPI_R5-spring.log
log4j.appender.S.MaxFileSize=10MB
log4j.appender.S.MaxBackupIndex=10
log4j.appender.S.layout=org.apache.log4j.PatternLayout
diff --git a/src/main/resources/static/error/404.html b/src/main/resources/static/error/404.html
old mode 100644
new mode 100755
diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html
old mode 100644
new mode 100755
diff --git a/src/main/resources/static/sushilite/AR1/index.html b/src/main/resources/static/sushilite/AR1/index.html
old mode 100644
new mode 100755
diff --git a/src/main/resources/static/sushilite/BR1/index.html b/src/main/resources/static/sushilite/BR1/index.html
old mode 100644
new mode 100755
diff --git a/src/main/resources/static/sushilite/BR2/index.html b/src/main/resources/static/sushilite/BR2/index.html
old mode 100644
new mode 100755
diff --git a/src/main/resources/static/sushilite/DSR/index.html b/src/main/resources/static/sushilite/DSR/index.html
old mode 100644
new mode 100755
diff --git a/src/main/resources/static/sushilite/IR/index.html b/src/main/resources/static/sushilite/IR/index.html
old mode 100644
new mode 100755
diff --git a/src/main/resources/static/sushilite/IR1/index.html b/src/main/resources/static/sushilite/IR1/index.html
old mode 100644
new mode 100755
diff --git a/src/main/resources/static/sushilite/JR1/index.html b/src/main/resources/static/sushilite/JR1/index.html
old mode 100644
new mode 100755
diff --git a/src/main/resources/static/sushilite/PR/index.html b/src/main/resources/static/sushilite/PR/index.html
old mode 100644
new mode 100755
diff --git a/src/main/resources/static/sushilite/PR_P1/index.html b/src/main/resources/static/sushilite/PR_P1/index.html
old mode 100644
new mode 100755
diff --git a/src/main/resources/static/sushilite/RR1/index.html b/src/main/resources/static/sushilite/RR1/index.html
old mode 100644
new mode 100755
diff --git a/src/main/resources/static/sushilite/index.html b/src/main/resources/static/sushilite/index.html
old mode 100644
new mode 100755
diff --git a/usageStatsAPI.properties b/usageStatsAPI.properties
old mode 100644
new mode 100755
index 8fd2cda..7337111
--- a/usageStatsAPI.properties
+++ b/usageStatsAPI.properties
@@ -12,7 +12,7 @@ spring.jackson.serialization.INDENT_OUTPUT=true
prod.statsdb=openaire_prod_stats
prod.usagestatsImpalaDB=openaire_prod_usage_stats
compression.max_number_of_records=100
-download.folder=/Users/dpie/Desktop/DownloadSushiReports
+download.folder=/Users/dpie/Desktop/DownloadSushiReports/
sushi-lite.server=http:://localhost/usagestats_r5
server.servlet.context-path=/usagestats_r5
#server.port=8080
diff --git a/usageStatsAPI_R5.properties b/usageStatsAPI_R5.properties
old mode 100644
new mode 100755
diff --git a/usageStatsAPI_local.properties b/usageStatsAPI_local.properties
old mode 100644
new mode 100755