@Test void testGenerateWeightedMapForTarget() { assertEquals( ".group([0,1,3,6,7]).map({\"-0\":\"4\",\"0-1\":\"4\",\"1-3\":\"3\",\"3-6\":\"2\",\"6-7\":\"1\",\"7+\":\"1\"}, null, null).value();", categoryAlgorithmGenerator.groupCategoryValues(targetAttribute)); }
public String groupCategoryValues(Attribute attribute) { StringBuilder stringBuilder = new StringBuilder(); List<Category> sortedCategories = convertToCategory(attribute).stream() .filter(category -> category.getAmountWrapper() != null) .collect(Collectors.toList()); sortedCategories.sort( Comparator.comparingDouble(o -> o.getAmountWrapper().getAmount().getEstimatedValue())); List<Integer> sortedRangValues = getRangedValues(sortedCategories); Map<String, Category> categoryRangeBoundMap = createCategoryRangeBoundMap(sortedCategories); if (categoryRangeBoundMap.size() > 0) { if (stringBuilder.length() == 0) { stringBuilder.append(".group(["); } sortedRangValues.stream().forEach(value -> stringBuilder.append(value).append(',')); stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append("]).map({"); for (Entry<String, Category> entry : categoryRangeBoundMap.entrySet()) { stringBuilder .append("\"") .append(entry.getKey()) .append("\":\"") .append(entry.getValue().getCode()) .append("\","); } stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append("}, null, null).value();"); } return stringBuilder.toString(); }
OneToManyCategoryAlgorithmGenerator extends AbstractCategoryAlgorithmGenerator { public String groupCategoryValues(Attribute attribute) { StringBuilder stringBuilder = new StringBuilder(); List<Category> sortedCategories = convertToCategory(attribute).stream() .filter(category -> category.getAmountWrapper() != null) .collect(Collectors.toList()); sortedCategories.sort( Comparator.comparingDouble(o -> o.getAmountWrapper().getAmount().getEstimatedValue())); List<Integer> sortedRangValues = getRangedValues(sortedCategories); Map<String, Category> categoryRangeBoundMap = createCategoryRangeBoundMap(sortedCategories); if (categoryRangeBoundMap.size() > 0) { if (stringBuilder.length() == 0) { stringBuilder.append(".group(["); } sortedRangValues.stream().forEach(value -> stringBuilder.append(value).append(',')); stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append("]).map({"); for (Entry<String, Category> entry : categoryRangeBoundMap.entrySet()) { stringBuilder .append("\"") .append(entry.getKey()) .append("\":\"") .append(entry.getValue().getCode()) .append("\","); } stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append("}, null, null).value();"); } return stringBuilder.toString(); } }
OneToManyCategoryAlgorithmGenerator extends AbstractCategoryAlgorithmGenerator { public String groupCategoryValues(Attribute attribute) { StringBuilder stringBuilder = new StringBuilder(); List<Category> sortedCategories = convertToCategory(attribute).stream() .filter(category -> category.getAmountWrapper() != null) .collect(Collectors.toList()); sortedCategories.sort( Comparator.comparingDouble(o -> o.getAmountWrapper().getAmount().getEstimatedValue())); List<Integer> sortedRangValues = getRangedValues(sortedCategories); Map<String, Category> categoryRangeBoundMap = createCategoryRangeBoundMap(sortedCategories); if (categoryRangeBoundMap.size() > 0) { if (stringBuilder.length() == 0) { stringBuilder.append(".group(["); } sortedRangValues.stream().forEach(value -> stringBuilder.append(value).append(',')); stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append("]).map({"); for (Entry<String, Category> entry : categoryRangeBoundMap.entrySet()) { stringBuilder .append("\"") .append(entry.getKey()) .append("\":\"") .append(entry.getValue().getCode()) .append("\","); } stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append("}, null, null).value();"); } return stringBuilder.toString(); } OneToManyCategoryAlgorithmGenerator(DataService dataService); }
OneToManyCategoryAlgorithmGenerator extends AbstractCategoryAlgorithmGenerator { public String groupCategoryValues(Attribute attribute) { StringBuilder stringBuilder = new StringBuilder(); List<Category> sortedCategories = convertToCategory(attribute).stream() .filter(category -> category.getAmountWrapper() != null) .collect(Collectors.toList()); sortedCategories.sort( Comparator.comparingDouble(o -> o.getAmountWrapper().getAmount().getEstimatedValue())); List<Integer> sortedRangValues = getRangedValues(sortedCategories); Map<String, Category> categoryRangeBoundMap = createCategoryRangeBoundMap(sortedCategories); if (categoryRangeBoundMap.size() > 0) { if (stringBuilder.length() == 0) { stringBuilder.append(".group(["); } sortedRangValues.stream().forEach(value -> stringBuilder.append(value).append(',')); stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append("]).map({"); for (Entry<String, Category> entry : categoryRangeBoundMap.entrySet()) { stringBuilder .append("\"") .append(entry.getKey()) .append("\":\"") .append(entry.getValue().getCode()) .append("\","); } stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append("}, null, null).value();"); } return stringBuilder.toString(); } OneToManyCategoryAlgorithmGenerator(DataService dataService); @Override boolean isSuitable(Attribute targetAttribute, List<Attribute> sourceAttributes); @Override String generate(
      Attribute targetAttribute,
      List<Attribute> sourceAttributes,
      EntityType targetEntityType,
      EntityType sourceEntityType); String generateWeightedMap(Attribute attribute); String groupCategoryValues(Attribute attribute); }
OneToManyCategoryAlgorithmGenerator extends AbstractCategoryAlgorithmGenerator { public String groupCategoryValues(Attribute attribute) { StringBuilder stringBuilder = new StringBuilder(); List<Category> sortedCategories = convertToCategory(attribute).stream() .filter(category -> category.getAmountWrapper() != null) .collect(Collectors.toList()); sortedCategories.sort( Comparator.comparingDouble(o -> o.getAmountWrapper().getAmount().getEstimatedValue())); List<Integer> sortedRangValues = getRangedValues(sortedCategories); Map<String, Category> categoryRangeBoundMap = createCategoryRangeBoundMap(sortedCategories); if (categoryRangeBoundMap.size() > 0) { if (stringBuilder.length() == 0) { stringBuilder.append(".group(["); } sortedRangValues.stream().forEach(value -> stringBuilder.append(value).append(',')); stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append("]).map({"); for (Entry<String, Category> entry : categoryRangeBoundMap.entrySet()) { stringBuilder .append("\"") .append(entry.getKey()) .append("\":\"") .append(entry.getValue().getCode()) .append("\","); } stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append("}, null, null).value();"); } return stringBuilder.toString(); } OneToManyCategoryAlgorithmGenerator(DataService dataService); @Override boolean isSuitable(Attribute targetAttribute, List<Attribute> sourceAttributes); @Override String generate(
      Attribute targetAttribute,
      List<Attribute> sourceAttributes,
      EntityType targetEntityType,
      EntityType sourceEntityType); String generateWeightedMap(Attribute attribute); String groupCategoryValues(Attribute attribute);  }