Search in sources :

Example 6 with StatisticValuesEntity

use of org.orcid.statistics.jpa.entities.StatisticValuesEntity in project ORCID-Source by ORCID.

the class StatisticsManagerReadOnlyImpl method getLiveIds.

/**
 * Get the the latest live ids statistics
 *
 * @param locale
 * @return the latest statistics live ids statistics
 */
public String getLiveIds(Locale locale) {
    StatisticValuesEntity entity = getLatestStatistics(StatisticsEnum.KEY_LIVE_IDS.value());
    long amount = entity == null ? 0 : entity.getStatisticValue();
    NumberFormat nf = NumberFormat.getInstance(locale);
    return nf.format(amount);
}
Also used : StatisticValuesEntity(org.orcid.statistics.jpa.entities.StatisticValuesEntity) NumberFormat(java.text.NumberFormat)

Example 7 with StatisticValuesEntity

use of org.orcid.statistics.jpa.entities.StatisticValuesEntity in project ORCID-Source by ORCID.

the class StatisticsManagerReadOnlyImpl method getStatisticsTimelineModel.

/**
 * Get all entries with a given name;
 *
 * @param statisticName
 * @return all statistics values for the statistics name parameter
 */
public StatisticsTimeline getStatisticsTimelineModel(StatisticsEnum statisticName) {
    List<StatisticValuesEntity> list = statisticsDaoReadOnly.getStatistic(statisticName.value());
    if (list == null)
        return null;
    // convert to model
    StatisticsTimeline timeline = new StatisticsTimeline();
    timeline.setStatisticName(statisticName.value());
    Map<Long, Long> map = new TreeMap<Long, Long>();
    Map<Long, Date> generationDateMap = new HashMap<Long, Date>();
    for (StatisticValuesEntity entry : list) {
        if (!generationDateMap.containsKey(entry.getKey().getId())) {
            StatisticKeyEntity key = statisticsDaoReadOnly.getKey(entry.getKey().getId());
            Long time = key.getGenerationDate().getTime();
            map.put(time, entry.getStatisticValue());
            generationDateMap.put(key.getId(), key.getGenerationDate());
        } else {
            Date date = generationDateMap.get(entry.getKey().getId());
            map.put(date.getTime(), entry.getStatisticValue());
        }
    }
    timeline.setTimeline(map);
    return timeline;
}
Also used : StatisticValuesEntity(org.orcid.statistics.jpa.entities.StatisticValuesEntity) HashMap(java.util.HashMap) StatisticKeyEntity(org.orcid.statistics.jpa.entities.StatisticKeyEntity) StatisticsTimeline(org.orcid.jaxb.model.statistics.StatisticsTimeline) TreeMap(java.util.TreeMap) Date(java.util.Date)

Example 8 with StatisticValuesEntity

use of org.orcid.statistics.jpa.entities.StatisticValuesEntity in project ORCID-Source by ORCID.

the class StatisticsManagerReadOnlyImpl method getLatestStatisticsModel.

/**
 * Get the list of the latest statistics as a domain model
 *
 * @return a list that contains the latest set of statistics
 */
@Override
public StatisticsSummary getLatestStatisticsModel() {
    StatisticKeyEntity latestKey = statisticsDaoReadOnly.getLatestKey();
    if (latestKey == null)
        return null;
    List<StatisticValuesEntity> list = statisticsDaoReadOnly.getStatistic(latestKey.getId());
    if (list == null || list.size() == 0)
        return null;
    // convert to model
    StatisticsSummary summary = new StatisticsSummary();
    Map<String, Long> map = new TreeMap<String, Long>();
    for (StatisticValuesEntity entry : list) {
        map.put(entry.getStatisticName(), entry.getStatisticValue());
    }
    summary.setStatistics(map);
    summary.setDate(latestKey.getGenerationDate());
    return summary;
}
Also used : StatisticValuesEntity(org.orcid.statistics.jpa.entities.StatisticValuesEntity) StatisticsSummary(org.orcid.jaxb.model.statistics.StatisticsSummary) StatisticKeyEntity(org.orcid.statistics.jpa.entities.StatisticKeyEntity) TreeMap(java.util.TreeMap)

Aggregations

StatisticValuesEntity (org.orcid.statistics.jpa.entities.StatisticValuesEntity)8 StatisticKeyEntity (org.orcid.statistics.jpa.entities.StatisticKeyEntity)6 TreeMap (java.util.TreeMap)4 Date (java.util.Date)3 NumberFormat (java.text.NumberFormat)2 HashMap (java.util.HashMap)2 StatisticsSummary (org.orcid.jaxb.model.statistics.StatisticsSummary)2 StatisticsTimeline (org.orcid.jaxb.model.statistics.StatisticsTimeline)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Test (org.junit.Test)1 AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1 Transactional (org.springframework.transaction.annotation.Transactional)1