Пример #1
0
  static AdGroupCriterion addPartition(
      long adGroupId,
      AdGroupCriterion parent,
      ProductCondition condition,
      ProductPartitionType partitionType,
      FixedBid bid,
      Boolean isNegative) {
    AdGroupCriterion adGroupCriterion = null;

    if (isNegative) {
      adGroupCriterion = new NegativeAdGroupCriterion();
    } else {
      adGroupCriterion = new BiddableAdGroupCriterion();
      ((BiddableAdGroupCriterion) adGroupCriterion).setCriterionBid(bid);
    }

    adGroupCriterion.setAdGroupId(adGroupId);

    ProductPartition criterion = new ProductPartition();
    criterion.setCondition(condition);
    criterion.setParentCriterionId((parent != null) ? parent.getId() : null);

    if (partitionType == ProductPartitionType.SUBDIVISION) {
      criterion.setPartitionType(ProductPartitionType.SUBDIVISION); // Branch
      adGroupCriterion.setId(_referenceId--);
    } else {
      criterion.setPartitionType(ProductPartitionType.UNIT); // Leaf
    }

    adGroupCriterion.setCriterion(criterion);

    addPartitionAction(adGroupCriterion, ItemAction.ADD);

    return adGroupCriterion;
  }
Пример #2
0
  static void printProductPartitions(ArrayOfAdGroupCriterion adGroupCriterions) {
    Map<Long, ArrayList<AdGroupCriterion>> childBranches =
        new HashMap<Long, ArrayList<AdGroupCriterion>>();
    AdGroupCriterion treeRoot = null;

    for (AdGroupCriterion adGroupCriterion : adGroupCriterions.getAdGroupCriterions()) {
      ProductPartition partition = (ProductPartition) adGroupCriterion.getCriterion();
      childBranches.put(adGroupCriterion.getId(), new ArrayList<AdGroupCriterion>());

      if (partition.getParentCriterionId() != null) {
        childBranches.get(partition.getParentCriterionId()).add(adGroupCriterion);
      } else {
        treeRoot = adGroupCriterion;
      }
    }

    printProductPartitionTree(treeRoot, childBranches, 0);
  }
  static BulkAdGroupProductPartition addPartition(
      long adGroupId,
      BulkAdGroupProductPartition parent,
      ProductCondition condition,
      ProductPartitionType partitionType,
      FixedBid bid,
      Boolean isNegative,
      java.lang.String clientId) {
    AdGroupCriterion adGroupCriterion = null;

    if (isNegative) {
      adGroupCriterion = new NegativeAdGroupCriterion();
    } else {
      adGroupCriterion = new BiddableAdGroupCriterion();
      ((BiddableAdGroupCriterion) adGroupCriterion).setCriterionBid(bid);
    }

    adGroupCriterion.setAdGroupId(adGroupId);

    ProductPartition criterion = new ProductPartition();
    criterion.setCondition(condition);
    criterion.setParentCriterionId(
        (parent != null && parent.getAdGroupCriterion() != null)
            ? parent.getAdGroupCriterion().getId()
            : null);

    if (partitionType == ProductPartitionType.SUBDIVISION) {
      criterion.setPartitionType(ProductPartitionType.SUBDIVISION); // Branch
      adGroupCriterion.setId(_referenceId--);
    } else {
      criterion.setPartitionType(ProductPartitionType.UNIT); // Leaf
    }

    adGroupCriterion.setCriterion(criterion);

    BulkAdGroupProductPartition partitionAction = new BulkAdGroupProductPartition();
    partitionAction.setAdGroupCriterion(adGroupCriterion);
    partitionAction.setClientId(clientId);
    _partitionActions.add(partitionAction);

    return partitionAction;
  }
  static void outputProductPartitions(
      List<BulkAdGroupProductPartition> bulkAdGroupProductPartitions) {
    Map<Long, ArrayList<BulkAdGroupProductPartition>> childBranches =
        new HashMap<Long, ArrayList<BulkAdGroupProductPartition>>();
    BulkAdGroupProductPartition treeRoot = null;

    for (BulkAdGroupProductPartition bulkAdGroupProductPartition : bulkAdGroupProductPartitions) {
      AdGroupCriterion adGroupCriterion = bulkAdGroupProductPartition.getAdGroupCriterion();
      if (adGroupCriterion != null) {
        ProductPartition partition = (ProductPartition) adGroupCriterion.getCriterion();
        childBranches.put(adGroupCriterion.getId(), new ArrayList<BulkAdGroupProductPartition>());

        if (partition.getParentCriterionId() != null) {
          childBranches.get(partition.getParentCriterionId()).add(bulkAdGroupProductPartition);
        } else {
          treeRoot = bulkAdGroupProductPartition;
        }
      }
    }

    // Outputs the tree root node and any children recursively
    outputProductPartitionTree(treeRoot, childBranches, 0);
  }
Пример #5
0
  static void printProductPartitionTree(
      AdGroupCriterion node, Map<Long, ArrayList<AdGroupCriterion>> childBranches, int treeLevel) {
    ProductPartition criterion = (ProductPartition) node.getCriterion();

    outputStatusMessage(
        String.format(
            "%" + ((treeLevel > 0) ? treeLevel * 4 : "") + "s%s\n",
            "",
            criterion.getPartitionType()));

    outputStatusMessage(
        String.format(
            "%" + ((treeLevel > 0) ? treeLevel * 4 : "") + "s%s%d\n",
            "",
            "ParentCriterionId: ",
            criterion.getParentCriterionId()));

    outputStatusMessage(
        String.format(
            "%" + ((treeLevel > 0) ? treeLevel * 4 : "") + "s%s%d\n", "", "Id: ", node.getId()));

    if (criterion.getPartitionType() == ProductPartitionType.UNIT) {
      if (node instanceof BiddableAdGroupCriterion) {
        outputStatusMessage(
            String.format(
                "%" + ((treeLevel > 0) ? treeLevel * 4 : "") + "s%s%.2f\n",
                "",
                "Bid amount: ",
                ((FixedBid) ((BiddableAdGroupCriterion) node).getCriterionBid())
                    .getBid()
                    .getAmount()));

      } else {
        if (node instanceof NegativeAdGroupCriterion) {
          outputStatusMessage(
              String.format("%" + treeLevel * 4 + "s%s\n", "", "Not bidding on this condition"));
        }
      }
    }

    String nullAttribute =
        (criterion.getParentCriterionId() != null) ? "(All Others)" : "(Tree Root)";

    outputStatusMessage(
        String.format(
            "%" + ((treeLevel > 0) ? treeLevel * 4 : "") + "s%s%s\n",
            "",
            "Attribute: ",
            (criterion.getCondition().getAttribute() == null)
                ? nullAttribute
                : criterion.getCondition().getAttribute()));

    outputStatusMessage(
        String.format(
            "%" + ((treeLevel > 0) ? treeLevel * 4 : "") + "s%s%s\n",
            "",
            "Condition: ",
            criterion.getCondition().getOperand()));

    for (AdGroupCriterion childNode : childBranches.get(node.getId())) {
      printProductPartitionTree(childNode, childBranches, treeLevel + 1);
    }
  }
  static void outputProductPartitionTree(
      BulkAdGroupProductPartition node,
      Map<Long, ArrayList<BulkAdGroupProductPartition>> childBranches,
      int treeLevel) {
    AdGroupCriterion adGroupCriterion = node.getAdGroupCriterion();

    ProductPartition criterion = (ProductPartition) adGroupCriterion.getCriterion();

    System.out.printf(
        "%" + ((treeLevel > 0) ? treeLevel * 4 : "") + "s%s\n", "", criterion.getPartitionType());

    System.out.printf(
        "%" + ((treeLevel > 0) ? treeLevel * 4 : "") + "s%s%d\n",
        "",
        "ParentCriterionId: ",
        criterion.getParentCriterionId());

    System.out.printf(
        "%" + ((treeLevel > 0) ? treeLevel * 4 : "") + "s%s%d\n",
        "",
        "Id: ",
        adGroupCriterion.getId());

    if (criterion.getPartitionType() == ProductPartitionType.UNIT) {
      if (adGroupCriterion instanceof BiddableAdGroupCriterion) {
        System.out.printf(
            "%" + ((treeLevel > 0) ? treeLevel * 4 : "") + "s%s%.2f\n",
            "",
            "Bid amount: ",
            ((FixedBid) ((BiddableAdGroupCriterion) adGroupCriterion).getCriterionBid())
                .getBid()
                .getAmount());

      } else {
        if (adGroupCriterion instanceof NegativeAdGroupCriterion) {
          System.out.printf("%" + treeLevel * 4 + "s%s\n", "", "Not bidding on this condition");
        }
      }
    }

    String nullAttribute =
        (criterion.getParentCriterionId() != null) ? "(All Others)" : "(Tree Root)";

    System.out.printf(
        "%" + ((treeLevel > 0) ? treeLevel * 4 : "") + "s%s%s\n",
        "",
        "Attribute: ",
        (criterion.getCondition().getAttribute() == null)
            ? nullAttribute
            : criterion.getCondition().getAttribute());

    System.out.printf(
        "%" + ((treeLevel > 0) ? treeLevel * 4 : "") + "s%s%s\n",
        "",
        "Condition: ",
        criterion.getCondition().getOperand());

    for (BulkAdGroupProductPartition childNode : childBranches.get(adGroupCriterion.getId())) {
      outputProductPartitionTree(childNode, childBranches, treeLevel + 1);
    }
  }