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);
}
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();
}
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();
}
Aggregations