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