Search in sources :

Example 1 with Tally

use of org.finos.waltz.model.tally.Tally in project waltz by khartec.

the class MeasurableRatingHarness method main.

public static void main(String[] args) throws ParseException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    MeasurableRatingDao measurableRatingDao = ctx.getBean(MeasurableRatingDao.class);
    MeasurableIdSelectorFactory measurableIdSelectorFactory = new MeasurableIdSelectorFactory();
    EntityReference direct = mkRef(MEASURABLE, 18310);
    EntityReference indirect = mkRef(MEASURABLE, 18064);
    IdSelectionOptions directOpts = IdSelectionOptions.mkOpts(direct, CHILDREN);
    IdSelectionOptions indirectOpts = IdSelectionOptions.mkOpts(indirect, CHILDREN);
    Select<Record1<Long>> directSelector = measurableIdSelectorFactory.apply(directOpts);
    Select<Record1<Long>> indirectSelector = measurableIdSelectorFactory.apply(indirectOpts);
    List<MeasurableRatingTally> directTallies = measurableRatingDao.statsForRelatedMeasurable(directSelector);
    List<MeasurableRatingTally> indirectTallies = measurableRatingDao.statsForRelatedMeasurable(indirectSelector);
    List<Tally<Long>> tallies = measurableRatingDao.tallyByMeasurableCategoryId(1L);
    System.out.println(tallies);
}
Also used : Tally(org.finos.waltz.model.tally.Tally) MeasurableRatingTally(org.finos.waltz.model.tally.MeasurableRatingTally) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MeasurableIdSelectorFactory(org.finos.waltz.data.measurable.MeasurableIdSelectorFactory) MeasurableRatingDao(org.finos.waltz.data.measurable_rating.MeasurableRatingDao) EntityReference(org.finos.waltz.model.EntityReference) MeasurableRatingTally(org.finos.waltz.model.tally.MeasurableRatingTally) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) Record1(org.jooq.Record1)

Example 2 with Tally

use of org.finos.waltz.model.tally.Tally in project waltz by khartec.

the class EntityStatisticSummaryDao method generateWithNoRollup.

public TallyPack<String> generateWithNoRollup(Long statisticId, EntityReference entityReference) {
    Condition condition = mkNoRollupCondition(newArrayList(statisticId), entityReference, esv.CURRENT.eq(true));
    Result<Record4<Long, String, String, Timestamp>> values = dsl.select(esv.STATISTIC_ID, esv.OUTCOME, esv.VALUE, max(esv.CREATED_AT).as(maxCreatedAtField)).from(esv).where(dsl.renderInlined(condition)).groupBy(esv.STATISTIC_ID, esv.OUTCOME, esv.VALUE).fetch();
    LocalDateTime maxCreatedAt = values.isNotEmpty() ? values.get(0).getValue(maxCreatedAtField).toLocalDateTime() : nowUtc();
    List<Tally<String>> tallies = values.stream().map(r -> ImmutableTally.<String>builder().count(Double.parseDouble(r.getValue(esv.VALUE))).id(r.getValue(esv.OUTCOME)).build()).collect(toList());
    return ImmutableTallyPack.<String>builder().entityReference(EntityReference.mkRef(EntityKind.ENTITY_STATISTIC, statisticId)).tallies(tallies).lastUpdatedAt(maxCreatedAt).build();
}
Also used : LocalDateTime(java.time.LocalDateTime) DSL(org.jooq.impl.DSL) EntityKind(org.finos.waltz.model.EntityKind) Tally(org.finos.waltz.model.tally.Tally) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) Duration(org.finos.waltz.model.Duration) ListUtilities.newArrayList(org.finos.waltz.common.ListUtilities.newArrayList) Function(java.util.function.Function) BigDecimal(java.math.BigDecimal) Tuple2(org.jooq.lambda.tuple.Tuple2) Future(java.util.concurrent.Future) org.jooq(org.jooq) TallyPack(org.finos.waltz.model.tally.TallyPack) Repository(org.springframework.stereotype.Repository) ImmutableTally(org.finos.waltz.model.tally.ImmutableTally) Unchecked(org.jooq.lambda.Unchecked) ENTITY_STATISTIC_VALUE(org.finos.waltz.schema.tables.EntityStatisticValue.ENTITY_STATISTIC_VALUE) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Date(java.sql.Date) DBExecutorPoolInterface(org.finos.waltz.data.DBExecutorPoolInterface) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) SQLDataType(org.jooq.impl.SQLDataType) DateTimeUtilities.nowUtc(org.finos.waltz.common.DateTimeUtilities.nowUtc) EntityReference(org.finos.waltz.model.EntityReference) ImmutableTallyPack(org.finos.waltz.model.tally.ImmutableTallyPack) Collections(java.util.Collections) Tally(org.finos.waltz.model.tally.Tally) ImmutableTally(org.finos.waltz.model.tally.ImmutableTally)

Example 3 with Tally

use of org.finos.waltz.model.tally.Tally in project waltz by khartec.

the class EntityStatisticSummaryDao method generateSummary.

private <T> TallyPack<String> generateSummary(Long statisticId, Select<Record1<Long>> appIdSelector, Field<T> aggregateField, Function<T, Double> toTally) {
    Condition condition = mkSummaryCondition(newArrayList(statisticId), appIdSelector, esv.CURRENT.eq(true));
    Result<Record3<String, T, Timestamp>> values = dsl.select(esv.OUTCOME, aggregateField, max(esv.CREATED_AT).as(maxCreatedAtField)).from(esv).where(dsl.renderInlined(condition)).groupBy(esv.OUTCOME).fetch();
    LocalDateTime maxCreatedAt = values.isNotEmpty() ? values.get(0).getValue(maxCreatedAtField).toLocalDateTime() : nowUtc();
    List<Tally<String>> tallies = values.stream().map(r -> ImmutableTally.<String>builder().count(toTally.apply(r.getValue(aggregateField))).id(r.getValue(esv.OUTCOME)).build()).collect(toList());
    return ImmutableTallyPack.<String>builder().entityReference(EntityReference.mkRef(EntityKind.ENTITY_STATISTIC, statisticId)).tallies(tallies).lastUpdatedAt(maxCreatedAt).build();
}
Also used : LocalDateTime(java.time.LocalDateTime) DSL(org.jooq.impl.DSL) EntityKind(org.finos.waltz.model.EntityKind) Tally(org.finos.waltz.model.tally.Tally) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) Duration(org.finos.waltz.model.Duration) ListUtilities.newArrayList(org.finos.waltz.common.ListUtilities.newArrayList) Function(java.util.function.Function) BigDecimal(java.math.BigDecimal) Tuple2(org.jooq.lambda.tuple.Tuple2) Future(java.util.concurrent.Future) org.jooq(org.jooq) TallyPack(org.finos.waltz.model.tally.TallyPack) Repository(org.springframework.stereotype.Repository) ImmutableTally(org.finos.waltz.model.tally.ImmutableTally) Unchecked(org.jooq.lambda.Unchecked) ENTITY_STATISTIC_VALUE(org.finos.waltz.schema.tables.EntityStatisticValue.ENTITY_STATISTIC_VALUE) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Date(java.sql.Date) DBExecutorPoolInterface(org.finos.waltz.data.DBExecutorPoolInterface) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) SQLDataType(org.jooq.impl.SQLDataType) DateTimeUtilities.nowUtc(org.finos.waltz.common.DateTimeUtilities.nowUtc) EntityReference(org.finos.waltz.model.EntityReference) ImmutableTallyPack(org.finos.waltz.model.tally.ImmutableTallyPack) Collections(java.util.Collections) Tally(org.finos.waltz.model.tally.Tally) ImmutableTally(org.finos.waltz.model.tally.ImmutableTally)

Aggregations

EntityReference (org.finos.waltz.model.EntityReference)3 Tally (org.finos.waltz.model.tally.Tally)3 BigDecimal (java.math.BigDecimal)2 Date (java.sql.Date)2 Timestamp (java.sql.Timestamp)2 LocalDateTime (java.time.LocalDateTime)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Future (java.util.concurrent.Future)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)2 DateTimeUtilities.nowUtc (org.finos.waltz.common.DateTimeUtilities.nowUtc)2 ListUtilities.newArrayList (org.finos.waltz.common.ListUtilities.newArrayList)2 DBExecutorPoolInterface (org.finos.waltz.data.DBExecutorPoolInterface)2 Duration (org.finos.waltz.model.Duration)2 EntityKind (org.finos.waltz.model.EntityKind)2 ImmutableTally (org.finos.waltz.model.tally.ImmutableTally)2 ImmutableTallyPack (org.finos.waltz.model.tally.ImmutableTallyPack)2