Project

General

Profile

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 = "projectStats", path = "projectStats")
17
@Repository
18
public class ProjectRepo extends BaseRepository {
19

    
20
    private Logger log = Logger.getLogger(this.getClass());
21

    
22

    
23
    public UsageStats getClicks(String projectId) {
24

    
25
        String query = "select p.id, p.title, sum (ps.numberofviews) from project p, usagestats.projectsstats ps " +
26
                "where ps.projectid=p.id and p.id=? group by p.id, p.title;";
27

    
28
        List<String> values = new ArrayList<String>();
29
        values.add(projectId);
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 p.id, p.title , sum (ps.numberofviews) from project p, usagestats.projectsstats ps where " +
41
                "ps.projectid=p.id group by p.id, p.title order by  sum(ps.numberofviews)  desc limit 10;";
42

    
43
        return executeQuery(query);
44
    }
45

    
46

    
47
    public List<UsageStats> getMostPopularPubs(String projectId) {
48

    
49
        String query = "select r.id, r.title , sum(rs.numberofviews) from result r, usagestats.resultsstats rs, " +
50
                "project_results pr  where r.id=pr.result and pr.id=? and  rs.resultid=r.id group by r.id, r. title order by  sum(rs.numberofviews)  desc limit 10;";
51

    
52

    
53
        List<String> values = new ArrayList<String>();
54
        values.add(projectId);
55
        return executePreparedQuery(query, values);
56

    
57
    }
58

    
59

    
60
    public List<UsageStats> getPopularityOverTime(String projectId) {
61

    
62
        String query = "select ps.projectid, ps.timestamp_month , ps.numberofviews from usagestats.projectsstats ps " +
63
                " where   ps.projectid=?  order by ps.timestamp_month  desc ;";
64
        List<String> values = new ArrayList<String>();
65
        values.add(projectId);
66
        return executePreparedQuery(query, values);
67

    
68
    }
69

    
70

    
71
}
72

    
73

    
(4-4/5)