Search in sources :

Example 1 with EntityStatisticService

use of com.khartec.waltz.service.entity_statistic.EntityStatisticService in project waltz by khartec.

the class EntityStatisticHarness method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    EntityStatisticValueDao dao = ctx.getBean(EntityStatisticValueDao.class);
    EntityStatisticService service = ctx.getBean(EntityStatisticService.class);
    /*
        select
  outcome,
  sum(CASE ISNUMERIC(value) when 1 then cast(value as BIGINT) else 0 end)
from entity_statistic_value
where statistic_id = 20010
GROUP BY outcome;
         */
    /*
        AggregateFunction<BigDecimal> summer = DSL.sum(DSL.cast(esv.VALUE, Long.class));

        dsl.select(esv.OUTCOME, summer)
                .from(esv)
                .where(esv.STATISTIC_ID.eq(20010L))
                .groupBy(esv.OUTCOME)
                .fetch()
                .forEach(System.out::println);

*/
    IdSelectionOptions selectionOptions = ImmutableIdSelectionOptions.builder().entityReference(EntityReference.mkRef(EntityKind.ORG_UNIT, 70)).scope(HierarchyQueryScope.CHILDREN).build();
    // count by value
    List<TallyPack<String>> countByValueTallyPacks = service.calculateHistoricStatTally(10100L, RollupKind.COUNT_BY_ENTITY, selectionOptions, Duration.WEEK);
    System.out.println(countByValueTallyPacks);
    // sum by value
    List<TallyPack<String>> sumByValueTallyPacks = service.calculateHistoricStatTally(20010L, RollupKind.SUM_BY_VALUE, selectionOptions, Duration.YEAR);
    System.out.println(sumByValueTallyPacks);
    // pre-computed
    List<TallyPack<String>> preComputedTallyPacks = service.calculateHistoricStatTally(11000L, RollupKind.NONE, selectionOptions, Duration.ALL);
    System.out.println(preComputedTallyPacks);
    System.out.println("done");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) TallyPack(com.khartec.waltz.model.tally.TallyPack) EntityStatisticValueDao(com.khartec.waltz.data.entity_statistic.EntityStatisticValueDao) DSLContext(org.jooq.DSLContext) EntityStatisticService(com.khartec.waltz.service.entity_statistic.EntityStatisticService)

Aggregations

EntityStatisticValueDao (com.khartec.waltz.data.entity_statistic.EntityStatisticValueDao)1 TallyPack (com.khartec.waltz.model.tally.TallyPack)1 EntityStatisticService (com.khartec.waltz.service.entity_statistic.EntityStatisticService)1 DSLContext (org.jooq.DSLContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1