Commit 100520201

This commit is contained in:
Dimitris 2021-05-10 16:53:29 +03:00
parent 906c9ac35b
commit f02fc236f2
3 changed files with 159 additions and 774 deletions

View File

@ -116,7 +116,7 @@
<groupId>com.cloudera</groupId>
<artifactId>ImpalaJDBC41</artifactId>
<version>2.6.3</version>
<scope>runtime</scope>
<type>jar</type>
</dependency>
<dependency>

View File

@ -35,7 +35,6 @@ import java.security.MessageDigest;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
@ -828,775 +827,6 @@ public class UsageStatsRepository {
DbUtils.closeQuietly(connection);
}
}
//
// private void executeOpenaire(List<COUNTER_Platform_Usage> reportItems, String openaire,
// String repositoryIdentifier, String itemDataType, Date beginDate,
// Date endDate, String granularity) {
// 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;
//
// /*
// Calendar startCalendar = Calendar.getInstance();
// startCalendar.setTime(beginDate);
// Calendar endCalendar = Calendar.getInstance();
// endCalendar.setTime(endDate);
// int diffYear = endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR);
// int diffMonth = diffYear * 12 + endCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH);
// */
// try {
// connection = usageStatsDB.getConnection();
// if (repositoryIdentifier.equals("")) {
// if (itemDataType.equals("")) {
// //st = connection.prepareStatement("SELECT res.repository_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.ddate, oids.orid, res.downloads, res.views FROM (SELECT coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.result_id, vs.result_id) AS result_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? AND s.result_id=? GROUP BY s.repository_id, s.result_id, s.date) AS ds FULL OUTER JOIN (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? AND s.result_id=? GROUP BY s.repository_id, s.result_id, s.date) AS vs ON ds.result_id=vs.result_id AND ds.date=vs.date) AS res JOIN public.result r ON res.result_id=r.id JOIN public.datasource d ON d.id=res.repository_id JOIN public.result_classifications rc ON rc.id=r.id LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM public.result_pids pids WHERE pids.id=? AND type='doi' GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM public.result_oids oids WHERE oids.id=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.repository_id, res.ddate;");
// //st = connection.prepareStatement("SELECT res.repository_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.date, oids.orid, res.downloads, res.views FROM (SELECT us.repository_id, us.result_id, us.date, us.downloads, us.views FROM usage_stats us WHERE us.date>=? AND us.date<=? AND us.result_id=?) AS res JOIN public.result r ON res.result_id=r.id JOIN public.datasource d ON d.id=res.repository_id JOIN public.result_classifications rc ON rc.id=r.id LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM public.result_pids pids WHERE pids.id=? AND type='doi' GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM public.result_oids oids WHERE oids.id=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.repository_id, res.date;");
// st = connection.prepareStatement("SELECT distinct res.repository_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.`date`, oids.oid, res.downloads, res.views "
// + "FROM (SELECT us.repository_id, us.result_id, us.`date`, us.downloads, us.views FROM " + usagestatsImpalaDB + ".usage_stats us "
// + "WHERE us.`date`>=? AND us.`date`<=? AND us.result_id=?) AS res "
// + "JOIN " + statsDB + ".result r ON res.result_id=r.id "
// + "JOIN " + statsDB + ".datasource d ON d.id=res.repository_id "
// + "JOIN (select id, group_concat(type,',') as type FROM " + statsDB + ".result_classifications where id=? "
// + "GROUP by id) rc ON rc.id=r.id "
// + "LEFT JOIN (SELECT pids.id, group_concat(pids.pid, '#!#') AS pid FROM " + statsDB + ".result_pids pids "
// + "WHERE pids.id=? AND type='Digital Object Identifier' GROUP BY pids.id) AS pids ON pids.id=r.id "
// + "LEFT JOIN (SELECT id, group_concat(oids.oid, '#!#') AS oid FROM " + statsDB + ".result_oids oids "
// + "WHERE oids.id=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.repository_id, res.`date`;");
// st.setString(1, beginDateStr);
// st.setString(2, endDateStr);
// st.setString(3, openaire);
// //st.setString(4, beginDateStr);
// //st.setString(5, endDateStr);
// //st.setString(6, openaire);
// st.setString(4, openaire);
// st.setString(5, openaire);
// st.setString(6, openaire);
// } else {
// //st = connection.prepareStatement("SELECT res.repository_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.ddate, oids.orid, res.downloads, res.views FROM (SELECT coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.result_id, vs.result_id) AS result_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? AND s.result_id=? GROUP BY s.repository_id, s.result_id, s.date) AS ds FULL OUTER JOIN (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? AND s.result_id=? GROUP BY s.repository_id, s.result_id, s.date) AS vs ON ds.result_id=vs.result_id AND ds.date=vs.date) AS res JOIN public.result r ON res.result_id=r.id JOIN public.datasource d ON d.id=res.repository_id JOIN public.result_classifications rc ON rc.id=r.id AND rc.type=? LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM public.result_pids pids WHERE pids.id=? AND type='doi' GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM public.result_oids oids WHERE oids.id=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.repository_id, res.ddate;");
// st = connection.prepareStatement("SELECT distinct res.repository_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.`date`, oids.oid, res.downloads, "
// + "res.views FROM (SELECT us.repository_id, us.result_id, us.`date`, us.downloads, us.views FROM " + usagestatsImpalaDB + ".usage_stats us "
// + "WHERE us.`date`>=? AND us.`date`<=? AND us.result_id=?) AS res "
// + "JOIN " + statsDB + ".result r ON res.result_id=r.id "
// + "JOIN " + statsDB + ".datasource d ON d.id=res.repository_id "
// + "JOIN " + statsDB + ".result_classifications rc ON rc.id=r.id AND rc.type=? "
// + "LEFT JOIN (SELECT pids.id, group_concat(pids.pid, '#!#') AS pid "
// + "FROM " + statsDB + ".result_pids pids WHERE pids.id=? "
// + "AND type='Digital Object Identifier' GROUP BY pids.id) AS pids ON pids.id=r.id "
// + "LEFT JOIN (SELECT oids.id, group_concat(oids.oid, '#!#') AS oid "
// + "FROM " + statsDB + ".result_oids oids WHERE oids.id=? "
// + "GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.repository_id, res.`date`;");
// st.setString(1, beginDateStr);
// st.setString(2, endDateStr);
// st.setString(3, openaire);
// //st.setString(4, beginDateStr);
// //st.setString(5, endDateStr);
// //st.setString(6, openaire);
// st.setString(4, itemDataType);
// st.setString(5, openaire);
// st.setString(6, openaire);
// }
// } else {
// if (itemDataType.equals("")) {
// //st = connection.prepareStatement("SELECT res.repository_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.ddate, oids.orid, res.downloads, res.views FROM (SELECT coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.result_id, vs.result_id) AS result_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? AND s.result_id=? AND s.repository_id=? GROUP BY s.repository_id, s.result_id, s.date) AS ds FULL OUTER JOIN (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? AND s.result_id=? AND s.repository_id=? GROUP BY s.repository_id, s.result_id, s.date) AS vs ON ds.result_id=vs.result_id AND ds.date=vs.date) AS res JOIN public.result r ON res.result_id=r.id JOIN public.datasource d ON d.id=res.repository_id JOIN public.result_classifications rc ON rc.id=r.id LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM public.result_pids pids WHERE pids.id=? AND type='doi' GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM public.result_oids oids WHERE oids.id=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.repository_id, res.ddate;");
// st = connection.prepareStatement("SELECT distinct res.repository_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.`date`, oids.oid, res.downloads, res.views "
// + "FROM (SELECT us.repository_id, us.result_id, us.`date`, us.downloads, us.views "
// + "FROM " + usagestatsImpalaDB + ".usage_stats us WHERE us.`date`>=? AND us.`date`<=? AND us.result_id=? AND us.repository_id=?) AS res "
// + "JOIN " + statsDB + ".result r ON res.result_id=r.id JOIN " + statsDB + ".datasource d ON d.id=res.repository_id "
// + "JOIN (select id, group_concat(type,',') as type from " + statsDB + ".result_classifications where id=? group by id) rc ON rc.id=r.id "
// + "LEFT JOIN (SELECT pids.id, group_concat(pids.pid, '#!#') AS pid FROM " + statsDB + ".result_pids pids "
// + "WHERE pids.id=? AND type='Digital Object Identifier' GROUP BY pids.id) AS pids ON pids.id=r.id "
// + "LEFT JOIN (SELECT oids.id, group_concat(oids.oid, '#!#') AS oid FROM " + statsDB + ".result_oids oids "
// + "WHERE oids.id=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.repository_id, res.`date`;");
// st.setString(1, beginDateStr);
// st.setString(2, endDateStr);
// st.setString(3, openaire);
// st.setString(4, repositoryIdentifier);
// //st.setString(5, beginDateStr);
// //st.setString(6, endDateStr);
// //st.setString(7, openaire);
// //st.setString(8, repositoryIdentifier);
// st.setString(5, openaire);
// st.setString(6, openaire);
// st.setString(7, openaire);
// } else {
// //st = connection.prepareStatement("SELECT res.repository_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.ddate, oids.orid, res.downloads, res.views FROM (SELECT coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.result_id, vs.result_id) AS result_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? AND s.result_id=? AND s.repository_id=? GROUP BY s.repository_id, s.result_id, s.date) AS ds FULL OUTER JOIN (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? AND s.result_id=? AND s.repository_id=? GROUP BY s.repository_id, s.result_id, s.date) AS vs ON ds.result_id=vs.result_id AND ds.date=vs.date) AS res JOIN public.result r ON res.result_id=r.id JOIN public.datasource d ON d.id=res.repository_id JOIN public.result_classifications rc ON rc.id=r.id AND rc.type=? LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM public.result_pids pids WHERE pids.id=? AND type='doi' GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM public.result_oids oids WHERE oids.id=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.repository_id, res.ddate;");
// st = connection.prepareStatement("SELECT distinct res.repository_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.`date`, oids.oid, res.downloads,res.views "
// + "FROM (SELECT us.repository_id, us.result_id, us.`date`, us.downloads, us.views FROM " + usagestatsImpalaDB + ".usage_stats us "
// + "WHERE us.`date`>=? AND us.`date`<=? AND us.result_id=? AND us.repository_id=?) AS res "
// + "JOIN " + statsDB + ".result r ON res.result_id=r.id JOIN " + statsDB + ".datasource d ON d.id=res.repository_id "
// + "JOIN " + statsDB + ".result_classifications rc ON rc.id=r.id AND rc.type=?' "
// + "LEFT JOIN (SELECT pids.id, group_concat(pids.pid, '#!#') AS pid FROM " + statsDB + ".result_pids pids "
// + "WHERE pids.id=? AND type='Digital Object Identifier' GROUP BY pids.id) AS pids ON pids.id=r.id "
// + "LEFT JOIN (SELECT oids.id, group_concat(oids.oid, '#!#') AS oid "
// + "FROM " + statsDB + ".result_oids oids WHERE oids.id=? "
// + "GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.repository_id, res.`date`;");
// st.setString(1, beginDateStr);
// st.setString(2, endDateStr);
// st.setString(3, openaire);
// st.setString(4, repositoryIdentifier);
// //st.setString(5, beginDateStr);
// //st.setString(6, endDateStr);
// //st.setString(7, openaire);
// //st.setString(8, repositoryIdentifier);
// st.setString(5, itemDataType);
// st.setString(6, openaire);
// st.setString(7, openaire);
// }
// }
//
// rs = st.executeQuery();
// String repository = "";
// String lastDate = "";
// COUNTER_Platform_Usage reportItem = null;
// int ft_total = 0;
// int abstr = 0;
//
// if (granularity.equalsIgnoreCase("totals")) {
// while (rs.next()) {
// if (!rs.getString(1).equals(repository)) {
// if (reportItem != null) {
// reportItem.addPerformance(new COUNTER_Item_Performance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
// reportItems.add(reportItem);
// }
// repository = rs.getString(1);
// reportItem = new COUNTER_Platform_Usage(rs.getString(3), rs.getString(7), rs.getString(5), rs.getString(2), "");
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OpenAIRE", openaire));
// reportItem.addIdentifier(new COUNTER_Item_Identifier("URLs", rs.getString(4)));
// if (rs.getString(9) != null && !rs.getString(9).equals("")) {
// if (rs.getString(9).contains("#!#")) {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OAI", rs.getString(9).substring(0, rs.getString(9).indexOf("#!#"))));
// } else {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OAI", rs.getString(9)));
// }
// }
// if (rs.getString(6) != null && !rs.getString(6).equals("")) {
// if (rs.getString(6).contains("#!#")) {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("DOI", rs.getString(6).substring(0, rs.getString(6).indexOf("#!#"))));
// } else {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("DOI", rs.getString(6)));
// }
// }
// ft_total = 0;
// abstr = 0;
// }
// ft_total += rs.getInt(10);
// abstr += rs.getInt(11);
// }
// if (reportItem != null) {
// reportItem.addPerformance(new COUNTER_Item_Performance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
// reportItems.add(reportItem);
// }
// } else if (granularity.equalsIgnoreCase("monthly")) {
// Calendar endCal = Calendar.getInstance();
// endCal.setTime(postgresFormat.parse(endDateStr));
// endCal.add(Calendar.MONTH, 1);
// Date endDateForZeros = endCal.getTime();
// while (rs.next()) {
// if (!rs.getString(1).equals(repository)) {
// if (reportItem != null) {
// fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
// reportItems.add(reportItem);
// }
// repository = rs.getString(1);
// lastDate = beginDateStr;
// reportItem = new COUNTER_Platform_Usage(rs.getString(3), rs.getString(7), rs.getString(5), rs.getString(2), "");
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OpenAIRE", openaire));
// reportItem.addIdentifier(new COUNTER_Item_Identifier("URLs", rs.getString(4)));
// if (rs.getString(9) != null && !rs.getString(9).equals("")) {
// if (rs.getString(9).contains("#!#")) {
// String allOAIs = rs.getString(9);
// String[] oaiArray = allOAIs.split("#!#");
// for (int i = 0; i < oaiArray.length; i++) {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OAI", oaiArray[i]));
// }
// //reportItem.addIdentifier(new COUNTER_Item_Identifier("OAI", rs.getString(9).substring(0, rs.getString(9).indexOf("#!#"))));
//
// //reportItem.addIdentifier(new COUNTER_Item_Identifier("OAI", rs.getString(9).substring(0, rs.getString(9).indexOf("#!#"))));
// } else {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OAI", rs.getString(9)));
// }
// }
// if (rs.getString(6) != null && !rs.getString(6).equals("")) {
// if (rs.getString(6).contains("#!#")) {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("DOI", rs.getString(6).substring(0, rs.getString(6).indexOf("#!#"))));
// } else {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("DOI", rs.getString(6)));
// }
// }
// }
// fillWithZeros(postgresFormat.parse(lastDate), postgresFormat.parse(rs.getString(8)), reportItem);
// Calendar endC = Calendar.getInstance();
// endC.setTime(postgresFormat.parse(rs.getString(8)));
// endC.set(Calendar.DATE, endC.getActualMaximum(Calendar.DATE));
// if (reportItem != null) {
// reportItem.addPerformance(new COUNTER_Item_Performance(report_dateFormat.format(postgresFormat.parse(rs.getString(8))), report_dateFormat.format(endC.getTime()), rs.getString(10), rs.getString(11)));
// }
// endC.setTime(postgresFormat.parse(rs.getString(8)));
// endC.add(Calendar.MONTH, 1);
// lastDate = postgresFormat.format(endC.getTime());
// }
// if (reportItem != null) {
// fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
// reportItems.add(reportItem);
// }
// }
// } catch (Exception e) {
// log.error("Single Item Report failed: ", e);
// } finally {
// DbUtils.closeQuietly(rs);
// DbUtils.closeQuietly(st);
// DbUtils.closeQuietly(connection);
// }
// }
// public void executeRepo(List<COUNTER_Platform_Usage> reportItems,
// String repositoryIdentifier, String itemDataType, Date beginDate,
// Date endDate, String granularity) {
// 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 (repositoryIdentifier.equals("")) {
// if (itemDataType.equals("")) {
// //st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.ddate, res.downloads, res.views FROM (SELECT coalesce(ds.source, vs.source), coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? GROUP BY s.source, s.repository_id, s.date) AS ds FULL OUTER JOIN (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? GROUP BY s.source, s.repository_id, s.date) AS vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.date) AS res JOIN public.datasource d ON d.id=res.repository_id JOIN public.datasource_oids dois ON d.id=dois.id WHERE dois.orid LIKE 'opendoar%' ORDER BY d.id, d.name, res.ddate ASC;");
// st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.oid, res.`date`, res.downloads, res.views "
// + "FROM (SELECT us.source, us.repository_id, us.`date`, sum(us.downloads) AS downloads, sum(us.views) AS views "
// + "FROM " + usagestatsImpalaDB + ".usage_stats us WHERE us.`date`>=? AND us.`date`<=? GROUP BY us.source, us.repository_id, us.`date`) "
// + "AS res JOIN " + statsDB + ".datasource d ON d.id=res.repository_id "
// + "JOIN " + statsDB + ".datasource_oids dois ON d.id=dois.id WHERE dois.oid "
// + "LIKE 'opendoar%' ORDER BY d.id, d.name, res.`date` ASC;");
// st.setString(1, beginDateStr);
// st.setString(2, endDateStr);
// //st.setString(3, beginDateStr);
// //st.setString(4, endDateStr);
// } else {
// //st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.ddate, res.downloads, res.views FROM (SELECT coalesce(ds.source, vs.source), coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.downloads_stats s, result_classifications rc WHERE rc.id=s.result_id AND s.date>=? AND s.date<=? AND rc.type=? GROUP BY s.source, s.repository_id, s.date) AS ds FULL OUTER JOIN (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.views_stats s, public.result_classifications rc WHERE rc.id=s.result_id AND s.date>=? AND s.date<=? AND rc.type=? GROUP BY s.source, s.repository_id, s.date) AS vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.date) AS res JOIN public.datasource d ON d.id=res.repository_id JOIN public.datasource_oids dois ON d.id=dois.id WHERE dois.orid LIKE 'opendoar%' ORDER BY d.id, d.name, res.ddate ASC;");
// st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.oid, res.`date`, res.downloads, res.views "
// + "FROM (SELECT us.source, us.repository_id, us.`date`, sum(us.downloads) AS downloads, sum(us.views) AS views "
// + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc "
// + "WHERE rc.id=us.result_id AND us.`date`>=? AND us.`date`<=? AND rc.type=? "
// + "GROUP BY us.source, us.repository_id, us.`date`) AS res "
// + "JOIN " + statsDB + ".datasource d ON d.id=res.repository_id "
// + "JOIN " + statsDB + ".datasource_oids dois ON d.id=dois.id WHERE dois.oid LIKE 'opendoar%' "
// + "ORDER BY d.id, d.name, res.`date` ASC;");
// st.setString(1, beginDateStr);
// st.setString(2, endDateStr);
// st.setString(3, itemDataType);
// //st.setString(4, beginDateStr);
// //st.setString(5, endDateStr);
// //st.setString(6, itemDataType);
// }
// } else {
// if (itemDataType.equals("")) {
// //st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.ddate, res.downloads, res.views FROM (SELECT coalesce(ds.source, vs.source), coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? AND s.repository_id=? GROUP BY s.source, s.repository_id, s.date) AS ds FULL OUTER JOIN (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? AND s.repository_id=? GROUP BY s.source, s.repository_id, s.date) AS vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.date) AS res JOIN public.datasource d ON d.id=res.repository_id JOIN public.datasource_oids dois ON d.id=dois.id WHERE dois.orid LIKE 'opendoar%' ORDER BY d.id, d.name, res.ddate ASC;");
// st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.oid, res.`date`, res.downloads, res.views "
// + "FROM (SELECT us.source, us.repository_id, us.`date`, sum(us.downloads) AS downloads, sum(us.views) AS views "
// + "FROM " + usagestatsImpalaDB + ".usage_stats us WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? "
// + "GROUP BY us.source, us.repository_id, us.`date`) AS res "
// + "JOIN " + statsDB + ".datasource d ON d.id=res.repository_id "
// + "JOIN " + statsDB + ".datasource_oids dois ON d.id=dois.id "
// + "WHERE dois.oid LIKE 'opendoar%' ORDER BY d.id, d.name, res.`date` ASC;");
// st.setString(1, beginDateStr);
// st.setString(2, endDateStr);
// st.setString(3, repositoryIdentifier);
// //st.setString(4, beginDateStr);
// //st.setString(5, endDateStr);
// //st.setString(6, repositoryIdentifier);
// } else {
// //st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.ddate, res.downloads, res.views FROM (SELECT coalesce(ds.source, vs.source), coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.downloads_stats s, public.result_classifications rc WHERE rc.id=s.result_id AND s.date>=? AND s.date<=? AND rc.type=? AND s.repository_id=? GROUP BY s.source, s.repository_id, s.date) AS ds FULL OUTER JOIN (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.views_stats s, public.result_classifications rc WHERE rc.id=s.result_id AND s.date>=? AND s.date<=? AND rc.type=? AND s.repository_id=? GROUP BY s.source, s.repository_id, s.date) AS vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.date) AS res JOIN public.datasource d ON d.id=res.repository_id JOIN public.datasource_oids dois ON d.id=dois.id WHERE dois.orid LIKE 'opendoar%' ORDER BY d.id, d.name, res.ddate ASC;");
// st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.oid, res.`date`, res.downloads, res.views "
// + "FROM (SELECT us.source, us.repository_id, us.`date`, sum(us.downloads) AS downloads, sum(us.views) AS views "
// + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc "
// + "WHERE rc.id=us.result_id AND us.`date`>=? AND us.`date`<=? AND rc.type=? "
// + "AND us.repository_id=? GROUP BY us.source, us.repository_id, us.`date`) AS res "
// + "JOIN " + statsDB + ".datasource d ON d.id=res.repository_id "
// + "JOIN " + statsDB + ".datasource_oids dois ON d.id=dois.id "
// + "WHERE dois.oid LIKE 'opendoar%' ORDER BY d.id, d.name, res.`date` ASC;");
// st.setString(1, beginDateStr);
// st.setString(2, endDateStr);
// st.setString(3, itemDataType);
// st.setString(4, repositoryIdentifier);
// //st.setString(5, beginDateStr);
// //st.setString(6, endDateStr);
// //st.setString(7, itemDataType);
// //st.setString(8, repositoryIdentifier);
// }
// }
// //log.error("RR STATEMENT: " + st);
//
// /*
// String redis_key = MD5(st.toString());
//
// if (jedis.hasKey(redis_key, "result")) {
// reportItems.addAll(reportItemsFromJson((String) jedis.get(redis_key, "result")));
// st.close();
// connection.close();
// return;
// }
// */
// rs = st.executeQuery();
// String repository = "";
// String lastDate = "";
// COUNTER_Platform_Usage reportItem = null;
//
// /*
// Calendar startCalendar = Calendar.getInstance();
// startCalendar.setTime(beginDate);
// Calendar endCalendar = Calendar.getInstance();
// endCalendar.setTime(endDate);
// */
// int ft_total = 0;
// int abstr = 0;
// if (granularity.equalsIgnoreCase("totals")) {
// while (rs.next()) {
// if (!rs.getString(1).equals(repository)) {
// if (reportItem != null) {
// reportItem.addPerformance(new COUNTER_Item_Performance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
// reportItems.add(reportItem);
// }
// repository = rs.getString(1);
// reportItem = new COUNTER_Platform_Usage(null, rs.getString(2), "Platform", null, "");
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OpenAIRE", rs.getString(1)));
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OpenDOAR", rs.getString(4).substring(rs.getString(4).lastIndexOf(":") + 1)));
// reportItem.addIdentifier(new COUNTER_Item_Identifier("URL", rs.getString(3)));
// ft_total = 0;
// abstr = 0;
// }
// ft_total += rs.getInt(6);
// abstr += rs.getInt(7);
// }
// if (reportItem != null) {
// reportItem.addPerformance(new COUNTER_Item_Performance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
// reportItems.add(reportItem);
// }
// } else if (granularity.equalsIgnoreCase("monthly")) {
// Calendar endCal = Calendar.getInstance();
// endCal.setTime(postgresFormat.parse(endDateStr));
// endCal.add(Calendar.MONTH, 1);
// Date endDateForZeros = endCal.getTime();
// while (rs.next()) {
// if (!rs.getString(1).equals(repository)) {
// if (reportItem != null) {
// fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
// reportItems.add(reportItem);
// }
// repository = rs.getString(1);
// lastDate = beginDateStr;
// reportItem = new COUNTER_Platform_Usage(null, rs.getString(2), "Platform", null, "");
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OpenAIRE", rs.getString(1)));
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OpenDOAR", rs.getString(4).substring(rs.getString(4).lastIndexOf(":") + 1)));
// reportItem.addIdentifier(new COUNTER_Item_Identifier("URL", rs.getString(3)));
// }
// fillWithZeros(postgresFormat.parse(lastDate), postgresFormat.parse(rs.getString(5)), reportItem);
// Calendar endC = Calendar.getInstance();
// endC.setTime(postgresFormat.parse(rs.getString(5)));
// endC.set(Calendar.DATE, endC.getActualMaximum(Calendar.DATE));
// if (reportItem != null) {
// reportItem.addPerformance(new COUNTER_Item_Performance(report_dateFormat.format(postgresFormat.parse(rs.getString(5))), report_dateFormat.format(endC.getTime()), rs.getString(6), rs.getString(7)));
// }
// endC.setTime(postgresFormat.parse(rs.getString(5)));
// endC.add(Calendar.MONTH, 1);
// lastDate = postgresFormat.format(endC.getTime());
// }
// if (reportItem != null) {
// fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
// reportItems.add(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");
// */
// rs.close();
// st.close();
// connection.close();
// } catch (Exception e) {
// log.error("Repository Report failed: ", e);
// } finally {
// DbUtils.closeQuietly(rs);
// DbUtils.closeQuietly(st);
// DbUtils.closeQuietly(connection);
// }
// }
// public void executeJournal(List<COUNTER_Platform_Usage> reportItems,
// String repositoryIdentifier, String itemDataType, Date beginDate,
// Date endDate, String granularity) {
// 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 (repositoryIdentifier.equals("")) {
// if (itemDataType.equals("")) {
// //st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.ddate, res.downloads, res.views FROM (SELECT coalesce(ds.source, vs.source), coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? GROUP BY s.source, s.repository_id, s.date) AS ds FULL OUTER JOIN (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? GROUP BY s.source, s.repository_id, s.date) AS vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.date) AS res JOIN public.datasource d ON d.id=res.repository_id JOIN public.datasource_oids dois ON d.id=dois.id WHERE (d.type='Journal' OR d.type='Journal Aggregator/Publisher') ORDER BY d.id, d.name, res.ddate ASC;");
// st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.oid, res.`date`, res.downloads, res.views "
// + "FROM (SELECT us.source, us.repository_id, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views "
// + "FROM " + usagestatsImpalaDB + ".usage_stats us WHERE us.`date`>=? AND us.`date`<=? GROUP BY us.source, us.repository_id, us.`date`) AS res "
// + "JOIN " + statsDB + ".datasource d ON d.id=res.repository_id "
// + "JOIN " + statsDB + ".datasource_oids dois ON d.id=dois.id "
// + "WHERE (d.type='Journal' OR d.type='Journal Aggregator/Publisher') ORDER BY d.id, d.name, res.`date` ASC;");
// st.setString(1, beginDateStr);
// st.setString(2, endDateStr);
// //st.setString(3, beginDateStr);
// //st.setString(4, endDateStr);
// } else {
// //st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.ddate, res.downloads, res.views FROM (SELECT coalesce(ds.source, vs.source), coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.downloads_stats s, public.result_classifications rc WHERE rc.id=s.result_id AND s.date>=? AND s.date<=? AND rc.type=? GROUP BY s.source, s.repository_id, s.date) AS ds FULL OUTER JOIN (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.views_stats s, public.result_classifications rc WHERE rc.id=s.result_id AND s.date>=? AND s.date<=? AND rc.type=? GROUP BY s.source, s.repository_id, s.date) AS vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.date) AS res JOIN public.datasource d ON d.id=res.repository_id JOIN public.datasource_oids dois ON d.id=dois.id WHERE (d.type='Journal' OR d.type='Journal Aggregator/Publisher') ORDER BY d.id, d.name, res.ddate ASC;");
// st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.oid, res.`date`, res.downloads, res.views "
// + "FROM (SELECT us.source, us.repository_id, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views "
// + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc "
// + "WHERE rc.id=us.result_id AND us.`date`>=? AND us.`date`<=? AND rc.type=? "
// + "GROUP BY us.source, us.repository_id, us.`date`) AS res "
// + "JOIN " + statsDB + ".datasource d ON d.id=res.repository_id "
// + "JOIN " + statsDB + ".datasource_oids dois ON d.id=dois.id "
// + "WHERE (d.type='Journal' OR d.type='Journal Aggregator/Publisher') ORDER BY d.id, d.name, res.`date` ASC;");
// st.setString(1, beginDateStr);
// st.setString(2, endDateStr);
// st.setString(3, itemDataType);
// //st.setString(4, beginDateStr);
// //st.setString(5, endDateStr);
// //st.setString(6, itemDataType);
// }
// } else {
// if (itemDataType.equals("")) {
// //st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.ddate, res.downloads, res.views FROM (SELECT coalesce(ds.source, vs.source), coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? AND s.repository_id=? GROUP BY s.source, s.repository_id, s.date) AS ds FULL OUTER JOIN (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? AND s.repository_id=? GROUP BY s.source, s.repository_id, s.date) AS vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.date) AS res JOIN public.datasource d ON d.id=res.repository_id JOIN public.datasource_oids dois ON d.id=dois.id WHERE (d.type='Journal' OR d.type='Journal Aggregator/Publisher') ORDER BY d.id, d.name, res.ddate ASC;");
// st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.oid, res.`date`, res.downloads, res.views "
// + "FROM (SELECT us.source, us.repository_id, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views "
// + "FROM " + usagestatsImpalaDB + ".usage_stats us WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? "
// + "GROUP BY us.source, us.repository_id, us.`date`) AS res JOIN " + statsDB + ".datasource d ON d.id=res.repository_id "
// + "JOIN " + statsDB + ".datasource_oids dois ON d.id=dois.id "
// + "WHERE (d.type='Journal' OR d.type='Journal Aggregator/Publisher') ORDER BY d.id, d.name, res.`date` ASC;");
// st.setString(1, beginDateStr);
// st.setString(2, endDateStr);
// st.setString(3, repositoryIdentifier);
// //st.setString(4, beginDateStr);
// //st.setString(5, endDateStr);
// //st.setString(6, repositoryIdentifier);
// } else {
// //st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.ddate, res.downloads, res.views FROM (SELECT coalesce(ds.source, vs.source), coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.downloads_stats s, public.result_classifications rc WHERE rc.id=s.result_id AND s.date>=? AND s.date<=? AND rc.type=? AND s.repository_id=? GROUP BY s.source, s.repository_id, s.date) AS ds FULL OUTER JOIN (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.views_stats s, public.result_classifications rc WHERE rc.id=s.result_id AND s.date>=? AND s.date<=? AND rc.type=? AND s.repository_id=? GROUP BY s.source, s.repository_id, s.date) AS vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.date) AS res JOIN public.datasource d ON d.id=res.repository_id JOIN public.datasource_oids dois ON d.id=dois.id WHERE (d.type='Journal' OR d.type='Journal Aggregator/Publisher') ORDER BY d.id, d.name, res.ddate ASC;");
// st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.oid, res.`date`, res.downloads, res.views "
// + "FROM (SELECT us.source, us.repository_id, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views "
// + "FROM " + usagestatsImpalaDB + ".usage_stats us, " + statsDB + ".result_classifications rc WHERE rc.id=us.result_id "
// + "AND us.`date`>=?' AND us.`date`<=? AND rc.type=? AND us.repository_id=? "
// + "GROUP BY us.source, us.repository_id, us.`date`) AS res "
// + "JOIN " + statsDB + ".datasource d ON d.id=res.repository_id "
// + "JOIN " + statsDB + ".datasource_oids dois ON d.id=dois.id "
// + "WHERE (d.type='Journal' OR d.type='Journal Aggregator/Publisher') ORDER BY d.id, d.name, res.`date` ASC;");
// st.setString(1, beginDateStr);
// st.setString(2, endDateStr);
// st.setString(3, itemDataType);
// st.setString(4, repositoryIdentifier);
// //st.setString(5, beginDateStr);
// //st.setString(6, endDateStr);
// //st.setString(7, itemDataType);
// //st.setString(8, repositoryIdentifier);
// }
// }
// //log.error("RR STATEMENT: " + st);
//
// /*
// String redis_key = MD5(st.toString());
//
// if (jedis.hasKey(redis_key, "result")) {
// reportItems.addAll(reportItemsFromJson((String) jedis.get(redis_key, "result")));
// st.close();
// connection.close();
// return;
// }
// */
// rs = st.executeQuery();
// String repository = "";
// String lastDate = "";
// COUNTER_Platform_Usage reportItem = null;
//
// /*
// Calendar startCalendar = Calendar.getInstance();
// startCalendar.setTime(beginDate);
// Calendar endCalendar = Calendar.getInstance();
// endCalendar.setTime(endDate);
// */
// int ft_total = 0;
// int abstr = 0;
// if (granularity.equalsIgnoreCase("totals")) {
// while (rs.next()) {
// if (!rs.getString(1).equals(repository)) {
// if (reportItem != null) {
// reportItem.addPerformance(new COUNTER_Item_Performance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
// reportItems.add(reportItem);
// }
// repository = rs.getString(1);
// reportItem = new COUNTER_Platform_Usage(null, rs.getString(2), "Platform", null, "");
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OpenAIRE", rs.getString(1)));
// reportItem.addIdentifier(new COUNTER_Item_Identifier("ISSN", rs.getString(4).substring(rs.getString(4).lastIndexOf(":") + 1)));
// if (rs.getString(3) != null) {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("URL", rs.getString(3)));
// }
// ft_total = 0;
// abstr = 0;
// }
// ft_total += rs.getInt(6);
// abstr += rs.getInt(7);
// }
// if (reportItem != null) {
// reportItem.addPerformance(new COUNTER_Item_Performance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
// reportItems.add(reportItem);
// }
// } else if (granularity.equalsIgnoreCase("monthly")) {
// Calendar endCal = Calendar.getInstance();
// endCal.setTime(postgresFormat.parse(endDateStr));
// endCal.add(Calendar.MONTH, 1);
// Date endDateForZeros = endCal.getTime();
// while (rs.next()) {
// if (!rs.getString(1).equals(repository)) {
// if (reportItem != null) {
// fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
// reportItems.add(reportItem);
// }
// repository = rs.getString(1);
// lastDate = beginDateStr;
// reportItem = new COUNTER_Platform_Usage(null, rs.getString(2), "Platform", null, "");
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OpenAIRE", rs.getString(1)));
// reportItem.addIdentifier(new COUNTER_Item_Identifier("ISSN", rs.getString(4).substring(rs.getString(4).lastIndexOf(":") + 1)));
// if (rs.getString(3) != null) {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("URL", rs.getString(3)));
// }
// }
// fillWithZeros(postgresFormat.parse(lastDate), postgresFormat.parse(rs.getString(5)), reportItem);
// Calendar endC = Calendar.getInstance();
// endC.setTime(postgresFormat.parse(rs.getString(5)));
// endC.set(Calendar.DATE, endC.getActualMaximum(Calendar.DATE));
// if (reportItem != null) {
// reportItem.addPerformance(new COUNTER_Item_Performance(report_dateFormat.format(postgresFormat.parse(rs.getString(5))), report_dateFormat.format(endC.getTime()), rs.getString(6), rs.getString(7)));
// }
// endC.setTime(postgresFormat.parse(rs.getString(5)));
// endC.add(Calendar.MONTH, 1);
// lastDate = postgresFormat.format(endC.getTime());
// }
// if (reportItem != null) {
// fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
// reportItems.add(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");
// */
// rs.close();
// st.close();
// connection.close();
// } catch (Exception e) {
// log.error("Repository Report failed: ", e);
// } finally {
// DbUtils.closeQuietly(rs);
// DbUtils.closeQuietly(st);
// DbUtils.closeQuietly(connection);
// }
// }
// public void executeBatchItems(List<COUNTER_Platform_Usage> reportItems,
// String repositoryIdentifier, String itemDataType, Date beginDate,
// Date endDate, String granularity) {
// 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 (itemDataType.equals("")) {
// //st = connection.prepareStatement("SELECT res.result_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.ddate, oids.orid, res.downloads, res.views FROM (SELECT coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.result_id, vs.result_id) AS result_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? AND s.repository_id=? GROUP BY s.repository_id, s.result_id, s.date) AS ds FULL OUTER JOIN (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? AND s.repository_id=? GROUP BY s.repository_id, s.result_id, s.date) AS vs ON ds.result_id=vs.result_id AND ds.date=vs.date) AS res JOIN public.result r ON res.result_id=r.id JOIN public.datasource d ON d.id=res.repository_id JOIN public.result_classifications rc ON rc.id=r.id LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM public.result_pids pids, public.result_datasources rd WHERE rd.id=pids.id AND type='doi' AND rd.datasource=? GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM public.result_oids oids, public.result_datasources rd WHERE rd.id=oids.id AND rd.datasource=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.result_id, res.ddate;");
// //st = connection.prepareStatement("SELECT res.result_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.date, oids.orid, res.downloads, res.views FROM (SELECT us.repository_id, us.result_id, us.date, sum(us.downloads) as downloads, sum(us.views) as views FROM public.usage_stats us WHERE us.date>=? AND us.date<=? AND us.repository_id=? GROUP BY us.repository_id, us.result_id, us.date) AS res JOIN public.result r ON res.result_id=r.id JOIN public.datasource d ON d.id=res.repository_id JOIN public.result_classifications rc ON rc.id=r.id LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM public.result_pids pids, public.result_datasources rd WHERE rd.id=pids.id AND type='doi' AND rd.datasource=? GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM public.result_oids oids, public.result_datasources rd WHERE rd.id=oids.id AND rd.datasource=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.result_id, res.date;");
// st = connection.prepareStatement("SELECT distinct res.result_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.`date`, oids.oid, res.downloads, res.views "
// + "FROM (SELECT us.repository_id, us.result_id, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views FROM " + usagestatsImpalaDB + ".usage_stats us "
// + "WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? "
// + "GROUP BY us.repository_id, us.result_id, us.`date`) AS res JOIN " + statsDB + ".result r ON res.result_id=r.id "
// + "JOIN " + statsDB + ".datasource d ON d.id=res.repository_id "
// + "JOIN " + statsDB + ".result_classifications rc ON rc.id=r.id "
// + "LEFT JOIN (SELECT pids.id, group_concat(pids.pid, '#!#') AS pid "
// + "FROM " + statsDB + ".result_pids pids, " + statsDB + ".result_datasources rd "
// + "WHERE rd.id=pids.id AND type='Digital Object Identifier' AND rd.datasource=? "
// + "GROUP BY pids.id) AS pids ON pids.id=r.id "
// + "LEFT JOIN (SELECT oids.id, group_concat(oids.oid, '#!#') AS oid "
// + "FROM " + statsDB + ".result_oids oids, " + statsDB + ".result_datasources rd "
// + "WHERE rd.id=oids.id AND rd.datasource=? GROUP BY oids.id) "
// + "AS oids ON oids.id=r.id ORDER BY res.result_id, res.`date`;");
// st.setString(1, beginDateStr);
// st.setString(2, endDateStr);
// st.setString(3, repositoryIdentifier);
// //st.setString(4, beginDateStr);
// //st.setString(5, endDateStr);
// //st.setString(6, repositoryIdentifier);
// st.setString(4, repositoryIdentifier);
// st.setString(5, repositoryIdentifier);
// } else {
// //st = connection.prepareStatement("SELECT res.result_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.ddate, oids.orid, res.downloads, res.views FROM (SELECT coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.result_id, vs.result_id) AS result_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? AND s.repository_id=? GROUP BY s.repository_id, s.result_id, s.date) AS ds FULL OUTER JOIN (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? AND s.repository_id=? GROUP BY s.repository_id, s.result_id, s.date) AS vs ON ds.result_id=vs.result_id AND ds.date=vs.date) AS res JOIN public.result r ON res.result_id=r.id JOIN public.datasource d ON d.id=res.repository_id JOIN public.result_classifications rc ON rc.id=r.id LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM public.result_pids pids, result_datasources rd WHERE rd.id=pids.id AND type='doi' AND rd.datasource=? GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM public.result_oids oids, public.result_datasources rd WHERE rd.id=oids.id AND rd.datasource=? GROUP BY oids.id) AS oids ON oids.id=r.id WHERE rc.type=? ORDER BY res.result_id, res.ddate;");
// st = connection.prepareStatement("SELECT distinct res.result_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.`date`, oids.oid, res.downloads, res.views "
// + "FROM (SELECT us.repository_id, us.result_id, us.`date`, sum(us.downloads) as downloads, sum(us.views) as views "
// + "FROM " + usagestatsImpalaDB + ".usage_stats us WHERE us.`date`>=? AND us.`date`<=? AND us.repository_id=? "
// + "GROUP BY us.repository_id, us.result_id, us.`date`) AS res "
// + "JOIN " + statsDB + ".result r ON res.result_id=r.id JOIN " + statsDB + ".datasource d ON d.id=res.repository_id "
// + "JOIN " + statsDB + ".result_classifications rc ON rc.id=r.id "
// + "LEFT JOIN (SELECT pids.id, group_concat(pids.pid, '#!#') AS pid "
// + "FROM " + statsDB + ".result_pids pids, " + statsDB + ".result_datasources rd "
// + "WHERE rd.id=pids.id AND type='Digital Object Identifier' "
// + "AND rd.datasource=? GROUP BY pids.id) AS pids ON pids.id=r.id "
// + "LEFT JOIN (SELECT oids.id, group_concat(oids.oid, '#!#') AS oid "
// + "FROM " + statsDB + ".result_oids oids, " + statsDB + ".result_datasources rd "
// + "WHERE rd.id=oids.id AND rd.datasource=? GROUP BY oids.id) AS oids ON oids.id=r.id "
// + "WHERE rc.type=? ORDER BY res.result_id, res.`date`;");
// st.setString(1, beginDateStr);
// st.setString(2, endDateStr);
// st.setString(3, repositoryIdentifier);
// //st.setString(4, beginDateStr);
// //st.setString(5, endDateStr);
// //st.setString(6, repositoryIdentifier);
// st.setString(4, repositoryIdentifier);
// st.setString(5, repositoryIdentifier);
// st.setString(6, itemDataType);
// }
// //log.error("IR STATEMENT: " + st);
//
// /*
// String redis_key = MD5(st.toString());
//
// if (jedis.hasKey(redis_key, "result")) {
// reportItems.addAll(reportItemsFromJson((String) jedis.get(redis_key, "result")));
// st.close();
// connection.close();
// return;
// }
// */
// rs = st.executeQuery();
// String result = "";
// String lastDate = "";
// COUNTER_Platform_Usage reportItem = null;
//
// int ft_total = 0;
// int abstr = 0;
// if (granularity.equalsIgnoreCase("totals")) {
// while (rs.next()) {
// if (!rs.getString(1).equals(result)) {
// if (reportItem != null) {
// reportItem.addPerformance(new COUNTER_Item_Performance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
// reportItems.add(reportItem);
// }
// result = rs.getString(1);
// reportItem = new COUNTER_Platform_Usage(rs.getString(3), rs.getString(7), rs.getString(5), rs.getString(2), "");
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OpenAIRE", rs.getString(1)));
// reportItem.addIdentifier(new COUNTER_Item_Identifier("URLs", rs.getString(4)));
// if (rs.getString(9) != null && !rs.getString(9).equals("")) {
// if (rs.getString(9).contains("#!#")) {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OAI", rs.getString(9).substring(0, rs.getString(9).indexOf("#!#"))));
// } else {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OAI", rs.getString(9)));
// }
// }
// if (rs.getString(6) != null && !rs.getString(6).equals("")) {
// if (rs.getString(6).contains("#!#")) {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("DOI", rs.getString(6).substring(0, rs.getString(6).indexOf("#!#"))));
// } else {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("DOI", rs.getString(6)));
// }
// }
// ft_total = 0;
// abstr = 0;
// }
// ft_total += rs.getInt(10);
// abstr += rs.getInt(11);
// }
// if (reportItem != null) {
// reportItem.addPerformance(new COUNTER_Item_Performance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
// reportItems.add(reportItem);
// }
// } else if (granularity.equalsIgnoreCase("monthly")) {
// Calendar endCal = Calendar.getInstance();
// endCal.setTime(postgresFormat.parse(endDateStr));
// endCal.add(Calendar.MONTH, 1);
// Date endDateForZeros = endCal.getTime();
// while (rs.next()) {
// if (!rs.getString(1).equals(result)) {
// if (reportItem != null) {
// fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
// reportItems.add(reportItem);
// }
// result = rs.getString(1);
// lastDate = beginDateStr;
// reportItem = new COUNTER_Platform_Usage(rs.getString(3), rs.getString(7), rs.getString(5), rs.getString(2), "");
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OpenAIRE", rs.getString(1)));
// reportItem.addIdentifier(new COUNTER_Item_Identifier("URLs", rs.getString(4)));
// if (rs.getString(9) != null && !rs.getString(9).equals("")) {
// if (rs.getString(9).contains("#!#")) {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OAI", rs.getString(9).substring(0, rs.getString(9).indexOf("#!#"))));
// } else {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("OAI", rs.getString(9)));
// }
// }
// if (rs.getString(6) != null && !rs.getString(6).equals("")) {
// if (rs.getString(6).contains("#!#")) {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("DOI", rs.getString(6).substring(0, rs.getString(6).indexOf("#!#"))));
// } else {
// reportItem.addIdentifier(new COUNTER_Item_Identifier("DOI", rs.getString(6)));
// }
// }
// }
// fillWithZeros(postgresFormat.parse(lastDate), postgresFormat.parse(rs.getString(8)), reportItem);
// Calendar endC = Calendar.getInstance();
// endC.setTime(postgresFormat.parse(rs.getString(8)));
// endC.set(Calendar.DATE, endC.getActualMaximum(Calendar.DATE));
// if (reportItem != null) {
// reportItem.addPerformance(new COUNTER_Item_Performance(report_dateFormat.format(postgresFormat.parse(rs.getString(8))), report_dateFormat.format(endC.getTime()), rs.getString(10), rs.getString(11)));
// }
// endC.setTime(postgresFormat.parse(rs.getString(8)));
// endC.add(Calendar.MONTH, 1);
// lastDate = postgresFormat.format(endC.getTime());
// }
// if (reportItem != null) {
// fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
// reportItems.add(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 executeBatchItemsPR(List<COUNTER_Platform_Usage> reportItems,
String repositoryIdentifier, Date beginDate,
@ -1930,6 +1160,27 @@ public class UsageStatsRepository {
+ 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.setString(1, beginDateStr);
st.setString(2, endDateStr);
@ -1975,7 +1226,17 @@ public class UsageStatsRepository {
+ "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.setString(1, beginDateStr);
st.setString(2, endDateStr);
st.setString(3, repositoryIdentifier);
@ -2023,6 +1284,28 @@ public class UsageStatsRepository {
+ "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
//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);
@ -2091,6 +1374,27 @@ public class UsageStatsRepository {
+ "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
//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);
@ -2188,7 +1492,27 @@ public class UsageStatsRepository {
+ 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
//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);
@ -2232,7 +1556,26 @@ public class UsageStatsRepository {
+ "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
//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);
@ -2274,6 +1617,26 @@ public class UsageStatsRepository {
+ "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);
@ -2342,6 +1705,26 @@ public class UsageStatsRepository {
+ "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
//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);

View File

@ -11,7 +11,8 @@ 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=/srv/springboot/9880/usageStatsAPI_R5.log
#log4j.appender.R.File=/srv/springboot/9880/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
@ -21,7 +22,8 @@ log4j.appender.S=org.apache.log4j.RollingFileAppender
#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=/Volumes/Zeus/dpie/Desktop/usageStatsAPI_R5-spring.log
log4j.appender.S.File=/srv/springboot/9880/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.MaxFileSize=10MB
log4j.appender.S.MaxBackupIndex=10
log4j.appender.S.layout=org.apache.log4j.PatternLayout