예제 #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 AdGroupCriterion getRootNode(ArrayOfAdGroupCriterion adGroupCriterions) {
    AdGroupCriterion rootNode = null;

    for (AdGroupCriterion adGroupCriterion : adGroupCriterions.getAdGroupCriterions()) {
      if (((ProductPartition) adGroupCriterion.getCriterion()).getParentCriterionId() == null) {
        rootNode = adGroupCriterion;
        break;
      }
    }

    return rootNode;
  }
예제 #3
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);
  }
예제 #4
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);
    }
  }
예제 #5
0
  static void updateBranchAndLeafCriterion(long adGroupId, long rootId, long electronicsCriterionId)
      throws RemoteException, Exception {
    _partitionActions.getAdGroupCriterionActions().clear();

    AdGroupCriterion electronics = new BiddableAdGroupCriterion();
    electronics.setId(electronicsCriterionId);
    electronics.setAdGroupId(adGroupId);
    addPartitionAction(electronics, ItemAction.DELETE);

    BiddableAdGroupCriterion parent = new BiddableAdGroupCriterion();
    parent.setId(rootId);

    AdGroupCriterion electronicsSubdivision =
        addPartition(
            adGroupId,
            parent,
            new ProductCondition() {
              {
                setOperand("CategoryL1");
                setAttribute("Electronics");
              }
            },
            ProductPartitionType.SUBDIVISION,
            null,
            false);

    AdGroupCriterion brandC =
        addPartition(
            adGroupId,
            electronicsSubdivision,
            new ProductCondition() {
              {
                setOperand("Brand");
                setAttribute("Brand C");
              }
            },
            ProductPartitionType.UNIT,
            getFixedBid(0.35),
            false);

    AdGroupCriterion brandD =
        addPartition(
            adGroupId,
            electronicsSubdivision,
            new ProductCondition() {
              {
                setOperand("Brand");
                setAttribute("Brand D");
              }
            },
            ProductPartitionType.UNIT,
            getFixedBid(0.35),
            false);

    AdGroupCriterion otherElectronicBrands =
        addPartition(
            adGroupId,
            electronicsSubdivision,
            new ProductCondition() {
              {
                setOperand("Brand");
                setAttribute(null);
              }
            },
            ProductPartitionType.UNIT,
            getFixedBid(0.35),
            false);

    outputStatusMessage("Updating the electronics partition...\n");
    ApplyProductPartitionActionsResponse applyPartitionActionsResponse =
        applyPartitionActions(_partitionActions);

    ArrayOfAdGroupCriterion adGroupCriterions =
        getAdGroupCriterionsByIds(AccountId, adGroupId, null, CriterionType.PRODUCT_PARTITION);

    outputStatusMessage("The product partition group tree now has 12 nodes\n");
    printProductPartitions(adGroupCriterions);
  }