Search in sources :

Example 1 with DataStatisticsEvent

use of org.hisp.dhis.datastatistics.DataStatisticsEvent in project dhis2-core by dhis2.

the class DataStatisticsController method saveEvent.

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void saveEvent(@RequestParam DataStatisticsEventType eventType, String favorite) {
    Date timestamp = new Date();
    String username = currentUserService.getCurrentUsername();
    DataStatisticsEvent event = new DataStatisticsEvent(eventType, timestamp, username, favorite);
    dataStatisticsService.addEvent(event);
}
Also used : DataStatisticsEvent(org.hisp.dhis.datastatistics.DataStatisticsEvent) Date(java.util.Date) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 2 with DataStatisticsEvent

use of org.hisp.dhis.datastatistics.DataStatisticsEvent in project dhis2-core by dhis2.

the class HibernateDataStatisticsEventStore method getFavoritesData.

@Override
public List<FavoriteStatistics> getFavoritesData(DataStatisticsEventType eventType, int pageSize, SortOrder sortOrder, String username) {
    Assert.notNull(eventType, "Data statistics event type cannot be null");
    Assert.notNull(sortOrder, "Sort order cannot be null");
    String sql = "select c.uid, views, c.name, c.created from ( " + "select favoriteuid as uid, count(favoriteuid) as views " + "from datastatisticsevent ";
    if (username != null) {
        sql += "where username = ? ";
    }
    sql += "group by uid) as events " + "inner join " + eventType.getTable() + " c on c.uid = events.uid " + "order by events.views " + sortOrder.getValue() + " " + "limit ?;";
    PreparedStatementSetter pss = (ps) -> {
        int i = 1;
        if (username != null) {
            ps.setString(i++, username);
        }
        ps.setInt(i++, pageSize);
    };
    return jdbcTemplate.query(sql, pss, (rs, i) -> {
        FavoriteStatistics stats = new FavoriteStatistics();
        stats.setPosition(i + 1);
        stats.setId(rs.getString("uid"));
        stats.setName(rs.getString("name"));
        stats.setCreated(rs.getDate("created"));
        stats.setViews(rs.getInt("views"));
        return stats;
    });
}
Also used : SortOrder(org.hisp.dhis.analytics.SortOrder) HibernateGenericStore(org.hisp.dhis.hibernate.HibernateGenericStore) DataStatisticsEventStore(org.hisp.dhis.datastatistics.DataStatisticsEventStore) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) DataStatisticsEventType(org.hisp.dhis.datastatistics.DataStatisticsEventType) HashMap(java.util.HashMap) DateUtils.asSqlDate(org.hisp.dhis.system.util.DateUtils.asSqlDate) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) List(java.util.List) Lists(com.google.common.collect.Lists) Map(java.util.Map) FavoriteStatistics(org.hisp.dhis.datastatistics.FavoriteStatistics) DataStatisticsEvent(org.hisp.dhis.datastatistics.DataStatisticsEvent) Assert(org.springframework.util.Assert) FavoriteStatistics(org.hisp.dhis.datastatistics.FavoriteStatistics) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter)

Example 3 with DataStatisticsEvent

use of org.hisp.dhis.datastatistics.DataStatisticsEvent in project dhis2-core by dhis2.

the class HibernateDataStatisticsEventStore method getDataStatisticsEventCount.

@Override
public Map<DataStatisticsEventType, Double> getDataStatisticsEventCount(Date startDate, Date endDate) {
    Map<DataStatisticsEventType, Double> eventTypeCountMap = new HashMap<>();
    final String sql = "select eventtype as eventtype, count(eventtype) as numberofviews " + "from datastatisticsevent " + "where timestamp between ? and ? " + "group by eventtype;";
    PreparedStatementSetter pss = (ps) -> {
        int i = 1;
        ps.setDate(i++, asSqlDate(startDate));
        ps.setDate(i++, asSqlDate(endDate));
    };
    jdbcTemplate.query(sql, pss, (rs, i) -> {
        eventTypeCountMap.put(DataStatisticsEventType.valueOf(rs.getString("eventtype")), rs.getDouble("numberofviews"));
        return eventTypeCountMap;
    });
    final String totalSql = "select count(eventtype) as total " + "from datastatisticsevent " + "where timestamp between ? and ?;";
    jdbcTemplate.query(totalSql, pss, (resultSet, i) -> {
        return eventTypeCountMap.put(DataStatisticsEventType.TOTAL_VIEW, resultSet.getDouble("total"));
    });
    return eventTypeCountMap;
}
Also used : SortOrder(org.hisp.dhis.analytics.SortOrder) HibernateGenericStore(org.hisp.dhis.hibernate.HibernateGenericStore) DataStatisticsEventStore(org.hisp.dhis.datastatistics.DataStatisticsEventStore) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) DataStatisticsEventType(org.hisp.dhis.datastatistics.DataStatisticsEventType) HashMap(java.util.HashMap) DateUtils.asSqlDate(org.hisp.dhis.system.util.DateUtils.asSqlDate) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) List(java.util.List) Lists(com.google.common.collect.Lists) Map(java.util.Map) FavoriteStatistics(org.hisp.dhis.datastatistics.FavoriteStatistics) DataStatisticsEvent(org.hisp.dhis.datastatistics.DataStatisticsEvent) Assert(org.springframework.util.Assert) DataStatisticsEventType(org.hisp.dhis.datastatistics.DataStatisticsEventType) HashMap(java.util.HashMap) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter)

Aggregations

Date (java.util.Date)3 DataStatisticsEvent (org.hisp.dhis.datastatistics.DataStatisticsEvent)3 Lists (com.google.common.collect.Lists)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 SortOrder (org.hisp.dhis.analytics.SortOrder)2 DataStatisticsEventStore (org.hisp.dhis.datastatistics.DataStatisticsEventStore)2 DataStatisticsEventType (org.hisp.dhis.datastatistics.DataStatisticsEventType)2 FavoriteStatistics (org.hisp.dhis.datastatistics.FavoriteStatistics)2 HibernateGenericStore (org.hisp.dhis.hibernate.HibernateGenericStore)2 DateUtils.asSqlDate (org.hisp.dhis.system.util.DateUtils.asSqlDate)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)2 PreparedStatementSetter (org.springframework.jdbc.core.PreparedStatementSetter)2 Assert (org.springframework.util.Assert)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1