Search in sources :

Example 1 with CostRecord

use of org.finos.waltz.schema.tables.records.CostRecord in project waltz by khartec.

the class DataScrambler method scrambleCosts.

private static void scrambleCosts(DSLContext tx) {
    Set<CostRecord> costRecords = tx.select().from(COST).fetchSet(r -> r.into(COST));
    int[] updates = costRecords.stream().map(r -> {
        BigDecimal max = new BigDecimal(10000);
        BigDecimal randFromDouble = new BigDecimal(Math.random());
        BigDecimal actualRandomDec = randFromDouble.multiply(max);
        BigDecimal newCost = actualRandomDec.setScale(2, RoundingMode.HALF_UP);
        r.setAmount(newCost);
        return r;
    }).collect(collectingAndThen(toSet(), d -> tx.batchUpdate(d).execute()));
    System.out.println(format("Updated %d cost records with a random value", IntStream.of(updates).sum()));
}
Also used : IntStream(java.util.stream.IntStream) ChangeInitiativeRecord(org.finos.waltz.schema.tables.records.ChangeInitiativeRecord) CostRecord(org.finos.waltz.schema.tables.records.CostRecord) Tables(org.finos.waltz.schema.Tables) Set(java.util.Set) DIConfiguration(org.finos.waltz.service.DIConfiguration) IOException(java.io.IOException) SetUtilities.asSet(org.finos.waltz.common.SetUtilities.asSet) ApplicationRecord(org.finos.waltz.schema.tables.records.ApplicationRecord) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) IOUtilities(org.finos.waltz.common.IOUtilities) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) String.format(java.lang.String.format) PersonRecord(org.finos.waltz.schema.tables.records.PersonRecord) BigDecimal(java.math.BigDecimal) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) DSLContext(org.jooq.DSLContext) Person(io.codearte.jfairy.producer.person.Person) Fairy(io.codearte.jfairy.Fairy) Collectors.toSet(java.util.stream.Collectors.toSet) RoundingMode(java.math.RoundingMode) CostRecord(org.finos.waltz.schema.tables.records.CostRecord) BigDecimal(java.math.BigDecimal)

Example 2 with CostRecord

use of org.finos.waltz.schema.tables.records.CostRecord in project waltz by khartec.

the class AssetCostGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    ApplicationService applicationService = ctx.getBean(ApplicationService.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    dsl.transaction(c -> {
        DSLContext tx = c.dsl();
        List<Application> apps = applicationService.findAll();
        List<CostRecord> appDevCosts = generateRecords(apps, WaltzUtilities.getOrCreateCostKind(tx, "Application Development", "APPLICATION_DEVELOPMENT"), 900_000);
        List<CostRecord> infraCosts = generateRecords(apps, WaltzUtilities.getOrCreateCostKind(tx, "Infrastructure", "INFRASTRUCTURE"), 50_000);
        List<CostRecord> cloudMigrationCosts = generateRecords(randomPickSome(apps, 0.4), WaltzUtilities.getOrCreateCostKind(tx, "Cloud Migration", "CLOUD"), 200_000);
        List<CostRecord> depreciationCosts = generateRecords(randomPickSome(apps, 0.6), WaltzUtilities.getOrCreateCostKind(tx, "Depreciation", "DEPRECIATION"), 100_000);
        tx.batchInsert(appDevCosts).execute();
        tx.batchInsert(infraCosts).execute();
        tx.batchInsert(cloudMigrationCosts).execute();
        tx.batchInsert(depreciationCosts).execute();
    });
    return null;
}
Also used : CostRecord(org.finos.waltz.schema.tables.records.CostRecord) DSLContext(org.jooq.DSLContext) Application(org.finos.waltz.model.application.Application) ApplicationService(org.finos.waltz.service.application.ApplicationService)

Aggregations

CostRecord (org.finos.waltz.schema.tables.records.CostRecord)2 DSLContext (org.jooq.DSLContext)2 Fairy (io.codearte.jfairy.Fairy)1 Person (io.codearte.jfairy.producer.person.Person)1 IOException (java.io.IOException)1 String.format (java.lang.String.format)1 BigDecimal (java.math.BigDecimal)1 RoundingMode (java.math.RoundingMode)1 Set (java.util.Set)1 Collectors.collectingAndThen (java.util.stream.Collectors.collectingAndThen)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 IntStream (java.util.stream.IntStream)1 IOUtilities (org.finos.waltz.common.IOUtilities)1 RandomUtilities.randomPick (org.finos.waltz.common.RandomUtilities.randomPick)1 SetUtilities.asSet (org.finos.waltz.common.SetUtilities.asSet)1 Application (org.finos.waltz.model.application.Application)1 Tables (org.finos.waltz.schema.Tables)1 ApplicationRecord (org.finos.waltz.schema.tables.records.ApplicationRecord)1 ChangeInitiativeRecord (org.finos.waltz.schema.tables.records.ChangeInitiativeRecord)1 PersonRecord (org.finos.waltz.schema.tables.records.PersonRecord)1