1
|
/**
|
2
|
* Created by eri_k 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
|
//@RepositoryRestResource(collectionResourceRel = "datasourceStats", path = "datasourceStats")
|
17
|
@Repository
|
18
|
public class DatasourceRepo extends BaseRepository {
|
19
|
|
20
|
private Logger log = Logger.getLogger(this.getClass());
|
21
|
|
22
|
|
23
|
public UsageStats getClicks(String id) {
|
24
|
|
25
|
String query = "select d.id, d.name , sum (ds.numberofviews) from datasource d, usagestats.datasourcesstats ds " +
|
26
|
"where ds.datasourceid=d.id and d.id=? group by d.id, d.name;";
|
27
|
|
28
|
List<String> values = new ArrayList<String>();
|
29
|
values.add(id);
|
30
|
|
31
|
List<UsageStats> results = executePreparedQuery(query, values);
|
32
|
if (!results.isEmpty()) return results.get(0);
|
33
|
|
34
|
return new UsageStats();
|
35
|
|
36
|
}
|
37
|
|
38
|
|
39
|
public List<UsageStats> getMostPopular() {
|
40
|
String query = "select d.id, d.name , sum (ds.numberofviews) from datasource d, usagestats.datasourcesstats ds where " +
|
41
|
"ds.datasourceid=d.id group by d.id, d.name order by sum (ds.numberofviews) desc limit 10;";
|
42
|
|
43
|
return executeQuery(query);
|
44
|
}
|
45
|
|
46
|
public List<UsageStats> getMostPopularPubs(String datasourceId) {
|
47
|
|
48
|
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;";
|
49
|
|
50
|
|
51
|
List<String> values = new ArrayList<String>();
|
52
|
values.add(datasourceId);
|
53
|
return executePreparedQuery(query, values);
|
54
|
|
55
|
}
|
56
|
|
57
|
|
58
|
public List<UsageStats> getMostPopularProjects(String datasourceId) {
|
59
|
|
60
|
String query = "select p.id, p.title, sum(ps.numberofviews) from project p, result_datasources rd, project_results pr , usagestats.projectsstats ps " +
|
61
|
" where rd.datasource=? and p.id=pr.id and pr.result=rd.id and ps.projectid=p.id " +
|
62
|
" group by p.id, p.title order by sum (ps.numberofviews) desc limit 10;";
|
63
|
List<String> values = new ArrayList<String>();
|
64
|
values.add(datasourceId);
|
65
|
return executePreparedQuery(query, values);
|
66
|
|
67
|
}
|
68
|
|
69
|
public List<UsageStats> getPopularityOverTime(String datasourceId) {
|
70
|
|
71
|
String query = "select ds.datasourceid, ds.timestamp_month , ds.numberofviews from usagestats.datasourcesstats ds " +
|
72
|
" where ds.datasourceid=? order by ds.timestamp_month desc ;";
|
73
|
List<String> values = new ArrayList<String>();
|
74
|
values.add(datasourceId);
|
75
|
return executePreparedQuery(query, values);
|
76
|
|
77
|
}
|
78
|
|
79
|
|
80
|
}
|
81
|
|
82
|
|