Revision 58437
Added by Dimitris Pierrakos about 4 years ago
PiwikDownloadLogs.java | ||
---|---|---|
65 | 65 |
public void GetOpenAIRELogs(String repoLogsPath, String portalLogPath, String portalMatomoID) throws Exception { |
66 | 66 |
|
67 | 67 |
Statement statement = ConnectDB.getConnection().createStatement(); |
68 |
ResultSet rs = statement.executeQuery("SELECT distinct piwik_id from public.datasource order by piwik_id;"); |
|
69 |
PreparedStatement st = ConnectDB.getConnection().prepareStatement("SELECT max(timestamp) FROM piwiklog WHERE source=? HAVING max(timestamp) is not null;"); |
|
70 |
|
|
68 |
|
|
69 |
ResultSet rs = statement.executeQuery("SELECT distinct piwik_id from public.datasource where piwik_id is not null order by piwik_id;"); |
|
71 | 70 |
while (rs.next()) { |
72 | 71 |
int siteId = rs.getInt(1); |
72 |
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYY-MM"); |
|
73 |
|
|
74 |
Calendar start = Calendar.getInstance(); |
|
75 |
start.set(Calendar.YEAR, 2016); |
|
76 |
start.set(Calendar.MONTH, Calendar.MARCH); |
|
77 |
//start.setTime(simpleDateFormat.parse("2016-01")); |
|
78 |
|
|
79 |
Calendar end = Calendar.getInstance(); |
|
80 |
end.add(Calendar.DAY_OF_MONTH, -1); |
|
81 |
|
|
82 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
83 |
PreparedStatement st = ConnectDB.DB_CONNECTION.prepareStatement("SELECT max(timestamp) FROM piwiklog WHERE source=? HAVING max(timestamp) is not null;"); |
|
73 | 84 |
st.setInt(1, siteId); |
85 |
|
|
74 | 86 |
ResultSet rs_date = st.executeQuery(); |
75 |
|
|
76 | 87 |
while (rs_date.next()) { |
77 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
78 |
Date dateMax = sdf.parse(rs_date.getString(1)); |
|
79 |
//Date dateMax = sdf.parse("2020-02-01"); |
|
80 |
Calendar start = Calendar.getInstance(); |
|
81 |
start.setTime(dateMax); |
|
82 |
Calendar end = Calendar.getInstance(); |
|
83 |
end.add(Calendar.DAY_OF_MONTH, -1); |
|
88 |
if (rs_date.getString(1) != null && !rs_date.getString(1).equals("null") && !rs_date.getString(1).equals("")) { |
|
89 |
start.setTime(sdf.parse(rs_date.getString(1))); |
|
90 |
} |
|
91 |
} |
|
92 |
rs_date.close(); |
|
84 | 93 |
|
85 |
for (Date date = start.getTime(); start.before(end); start.add(Calendar.DATE, 1), date = start.getTime()) {
|
|
86 |
log.info("Downloading logs for repoid " + siteId + " and for " + sdf.format(date));
|
|
94 |
for (Date date = start.getTime(); start.before(end); start.add(Calendar.DATE, 1), date = start.getTime()) { |
|
95 |
log.info("Downloading logs for repoid " + siteId + " and for " + sdf.format(date)); |
|
87 | 96 |
|
88 |
String period = "&period=day&date=" + sdf.format(date);
|
|
89 |
String outFolder = "";
|
|
90 |
//portal siteId = 109;
|
|
91 |
if (siteId == Integer.parseInt(portalMatomoID)) {
|
|
92 |
outFolder = portalLogPath;
|
|
93 |
} else {
|
|
94 |
outFolder = repoLogsPath;
|
|
95 |
}
|
|
96 |
FileSystem fs = FileSystem.get(new Configuration());
|
|
97 |
FSDataOutputStream fin = fs.create(new Path(outFolder + "/" + siteId + "_Piwiklog" + sdf.format((date)) + ".json"), true);
|
|
97 |
String period = "&period=day&date=" + sdf.format(date); |
|
98 |
String outFolder = ""; |
|
99 |
//portal siteId = 109; |
|
100 |
if (siteId == Integer.parseInt(portalMatomoID)) { |
|
101 |
outFolder = portalLogPath; |
|
102 |
} else { |
|
103 |
outFolder = repoLogsPath; |
|
104 |
} |
|
105 |
FileSystem fs = FileSystem.get(new Configuration()); |
|
106 |
FSDataOutputStream fin = fs.create(new Path(outFolder + "/" + siteId + "_Piwiklog" + sdf.format((date)) + ".json"), true); |
|
98 | 107 |
|
99 |
String baseApiUrl = getPiwikLogUrl() + APImethod + "&idSite=" + siteId + period + format + "&expanded=5&filter_limit=1000&token_auth=" + tokenAuth;
|
|
100 |
String content = "";
|
|
108 |
String baseApiUrl = getPiwikLogUrl() + APImethod + "&idSite=" + siteId + period + format + "&expanded=5&filter_limit=1000&token_auth=" + tokenAuth; |
|
109 |
String content = ""; |
|
101 | 110 |
|
102 |
int i = 0;
|
|
111 |
int i = 0; |
|
103 | 112 |
|
104 |
while (!content.equals("[]\n")) {
|
|
105 |
String apiUrl = baseApiUrl;
|
|
113 |
while (!content.equals("[]\n")) { |
|
114 |
String apiUrl = baseApiUrl; |
|
106 | 115 |
|
107 |
if (i > 0) {
|
|
108 |
apiUrl += "&filter_offset=" + (i * 1000);
|
|
109 |
}
|
|
116 |
if (i > 0) { |
|
117 |
apiUrl += "&filter_offset=" + (i * 1000); |
|
118 |
} |
|
110 | 119 |
|
111 |
content = getJson(apiUrl);
|
|
120 |
content = getJson(apiUrl); |
|
112 | 121 |
|
113 |
fin.write(content.getBytes());
|
|
122 |
fin.write(content.getBytes()); |
|
114 | 123 |
|
115 |
i++; |
|
116 |
} |
|
117 |
fin.close(); |
|
124 |
i++; |
|
118 | 125 |
} |
126 |
fin.close(); |
|
127 |
|
|
119 | 128 |
} |
129 |
|
|
120 | 130 |
} |
121 |
} |
|
122 | 131 |
} |
Also available in: Unified diff
New Workflow for Usage Stats