1
|
/**
|
2
|
* Created by Glykeria Katsari on 2/20/2016.
|
3
|
*/
|
4
|
package eu.dnetlib.usagestats.repos;
|
5
|
|
6
|
|
7
|
import eu.dnetlib.usagestats.domain.UsageStats;
|
8
|
import org.apache.log4j.Logger;
|
9
|
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
10
|
import org.springframework.stereotype.Repository;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
|
15
|
|
16
|
@Repository
|
17
|
public class DatasourceRepo extends BaseRepository {
|
18
|
|
19
|
private Logger log = Logger.getLogger(this.getClass());
|
20
|
|
21
|
|
22
|
public UsageStats getClicks(String id) {
|
23
|
|
24
|
String query = "select d.id, d.name , sum (ds.numberofviews) from datasource d, usagestats.datasourcesstats ds " +
|
25
|
"where ds.datasourceid=d.id and d.id=? group by d.id, d.name;";
|
26
|
|
27
|
List<String> values = new ArrayList<String>();
|
28
|
values.add(id);
|
29
|
|
30
|
List<UsageStats> results = executePreparedQuery(query, values);
|
31
|
if (!results.isEmpty()) return results.get(0);
|
32
|
|
33
|
return new UsageStats();
|
34
|
|
35
|
}
|
36
|
|
37
|
|
38
|
public List<UsageStats> getMostPopular(String limit) {
|
39
|
String query = "select d.id, d.name , sum (ds.numberofviews) from datasource d, usagestats.datasourcesstats ds where " +
|
40
|
"ds.datasourceid=d.id group by d.id, d.name order by sum (ds.numberofviews) desc limit " + limit + " ;";
|
41
|
|
42
|
return executeQuery(query);
|
43
|
}
|
44
|
|
45
|
public List<UsageStats> getMostPopularPubs(String datasourceId) {
|
46
|
|
47
|
String query = "select r.id, r.title , sum(rs.numberofviews) from result r, usagestats.resultsstats rs, result_datasources rd where r.id=rd.id and rd.datasource=? and rs.resultid=r.id group by r.id, r. title order by sum(rs.numberofviews) desc limit 10;";
|
48
|
|
49
|
|
50
|
List<String> values = new ArrayList<String>();
|
51
|
values.add(datasourceId);
|
52
|
return executePreparedQuery(query, values);
|
53
|
|
54
|
}
|
55
|
|
56
|
|
57
|
public List<UsageStats> getMostPopularProjects(String datasourceId) {
|
58
|
|
59
|
String query = "select p.id, p.title, sum(ps.numberofviews) from project p, result_datasources rd, project_results pr , usagestats.projectsstats ps " +
|
60
|
" where rd.datasource=? and p.id=pr.id and pr.result=rd.id and ps.projectid=p.id " +
|
61
|
" group by p.id, p.title order by sum (ps.numberofviews) desc limit 10;";
|
62
|
List<String> values = new ArrayList<String>();
|
63
|
values.add(datasourceId);
|
64
|
return executePreparedQuery(query, values);
|
65
|
|
66
|
}
|
67
|
|
68
|
public List<UsageStats> getPopularityOverTime(String datasourceId) {
|
69
|
|
70
|
String query = "select ds.datasourceid, ds.timestamp_month , ds.numberofviews from usagestats.datasourcesstats ds " +
|
71
|
"where ds.datasourceid=? order by to_date(ds.timestamp_month,'MM/YYYY') ;";
|
72
|
List<String> values = new ArrayList<String>();
|
73
|
values.add(datasourceId);
|
74
|
return executePreparedQuery(query, values);
|
75
|
|
76
|
}
|
77
|
|
78
|
|
79
|
}
|
80
|
|
81
|
|