Search in sources :

Example 1 with Impression

use of com.xrtb.pojo.Impression in project XRTB by benmfaul.

the class MyReader method doInternal.

/**
	 * Take the internal protobuf and convert to JSON.
	 * @throws Exception on JSON or protobuf errors.
	 */
void doInternal() throws Exception {
    impressions = new ArrayList<Impression>();
    root = BidRequest.factory.objectNode();
    // Add this to the log
    byte[] bytes = internal.toByteArray();
    String str = new String(Base64.encodeBase64(bytes));
    root.put("protobuf", str);
    root.put("at", internal.getAt().getNumber());
    ProtocolStringList list = internal.getBadvList();
    root.put("badv", getAsStringList(BidRequest.factory.arrayNode(), list));
    if (internal.hasTmax())
        root.put("tmax", internal.getTmax());
    root.put("id", internal.getId());
    makeSiteOrApp();
    makeDevice();
    makeImpressions();
    makeUser();
    rootNode = (JsonNode) root;
    setup();
}
Also used : Impression(com.xrtb.pojo.Impression) ProtocolStringList(com.google.protobuf.ProtocolStringList)

Example 2 with Impression

use of com.xrtb.pojo.Impression in project XRTB by benmfaul.

the class CampaignSelector method getMaxConnections.

public BidResponse getMaxConnections(BidRequest br) throws Exception {
    // Don't proces if there was an error forming the original bid request.
    if (br.notABidRequest())
        return null;
    // The impression we selected
    Impression impression;
    // RunRecord record = new RunRecord("Campaign-Selector");
    if (br.blackListed)
        return null;
    long xtime = System.currentTimeMillis();
    Campaign test = null;
    SelectedCreative select = null;
    int kount = 0;
    List<Campaign> list = new ArrayList<Campaign>(config.campaignsList);
    Collections.shuffle(list);
    List<SelectedCreative> candidates = new ArrayList();
    boolean exchangeIsAdx = br.getExchange().equals("adx");
    while (kount < list.size()) {
        try {
            test = list.get(kount);
        } catch (Exception error) {
            Controller.getInstance().sendLog(3, "CampaignSelector:getMaxConnections", "Campaign was stale, in the selection list");
            return null;
        }
        if (test.isAdx == exchangeIsAdx) {
            CampaignProcessor p = new CampaignProcessor(test, br, null, null);
            // executor.execute(p);
            p.run();
            select = p.getSelectedCreative();
            if (select != null) {
                if (Configuration.getInstance().multibid)
                    candidates.add(select);
                else
                    break;
            }
        }
        kount++;
    }
    if (select == null && candidates.size() == 0)
        return null;
    xtime = System.currentTimeMillis() - xtime;
    // BidResponse winner = br.buildNewBidResponse(select.getCampaign(),
    // select.getCreative(), (int)xtime);
    BidResponse winner = null;
    if (!Configuration.getInstance().multibid)
        winner = br.buildNewBidResponse(select.getImpression(), select.getCampaign(), select.getCreative(), select.getPrice(), select.getDealId(), (int) xtime);
    else {
        winner = br.buildNewBidResponse(select.getImpression(), candidates, (int) xtime);
    }
    winner.capSpec = select.capSpec;
    try {
        if (Configuration.getInstance().printNoBidReason)
            Controller.getInstance().sendLog(Configuration.getInstance().logLevel, "CampaignProcessor:run:campaign-selected-winner", select.campaign.adId + "/" + select.creative.impid);
    } catch (Exception error) {
    }
    return winner;
}
Also used : Campaign(com.xrtb.common.Campaign) ArrayList(java.util.ArrayList) Impression(com.xrtb.pojo.Impression) BidResponse(com.xrtb.pojo.BidResponse)

Example 3 with Impression

use of com.xrtb.pojo.Impression in project XRTB by benmfaul.

the class CampaignSelector method getSpecific.

/**
	 * Creates a forced bid response on the specified bid request. owner,
	 * campaign and creative.
	 * 
	 * @param br
	 *            BidRequest. The request from the exchange.
	 * @param owner
	 *            String. The account owner of the campaign.
	 * @param campaignName
	 *            String. The campaign adid.
	 * @param creativeName
	 *            String. The creative id in the campaign.
	 * @return BidResponse. The response from the
	 */
public BidResponse getSpecific(BidRequest br, String owner, String campaignName, String creativeName) throws Exception {
    long xtime = System.currentTimeMillis();
    Campaign camp = null;
    Creative creative = null;
    for (Campaign c : config.campaignsList) {
        if (c.owner.equals(owner) && c.adId.equals(campaignName)) {
            camp = c;
            break;
        }
    }
    if (camp == null) {
        System.out.println("Can't find specification " + owner + "/" + campaignName);
        return null;
    }
    for (Creative cr : camp.creatives) {
        if (cr.impid.equals(creativeName)) {
            creative = cr;
            break;
        }
    }
    if (creative == null) {
        System.out.println("Can't find creative " + creative + " for " + owner + "/" + campaignName);
        return null;
    }
    String h = creative.strH;
    String w = creative.strW;
    int oldH = creative.h;
    int oldW = creative.w;
    Impression imp = br.getImpression(0);
    creative.strW = "" + imp.w;
    creative.strH = "" + imp.h;
    creative.w = imp.w;
    creative.h = imp.h;
    try {
        for (int i = 0; i < camp.attributes.size(); i++) {
            Node n = camp.attributes.get(i);
            if (n.test(br) == false) {
                if (Configuration.getInstance().printNoBidReason)
                    Controller.getInstance().sendLog(5, "CampaignProcessor:run:attribute-failed", camp.adId + "/" + creative.impid + ": " + n.hierarchy + " doesn't match the bidrequest");
                creative.strH = h;
                creative.strW = w;
                creative.w = oldW;
                creative.h = oldH;
                // don't bid
                return null;
            }
        }
    } catch (Exception error) {
        error.printStackTrace();
    }
    xtime = System.currentTimeMillis() - xtime;
    BidResponse winner = br.buildNewBidResponse(imp, camp, creative, creative.price, null, (int) xtime);
    creative.strH = h;
    creative.strW = w;
    creative.w = oldW;
    creative.h = oldH;
    return winner;
}
Also used : Campaign(com.xrtb.common.Campaign) Creative(com.xrtb.common.Creative) Node(com.xrtb.common.Node) Impression(com.xrtb.pojo.Impression) BidResponse(com.xrtb.pojo.BidResponse)

Example 4 with Impression

use of com.xrtb.pojo.Impression in project XRTB by benmfaul.

the class Creative method process.

/**
	 * Process the bid request against this creative.
	 * 
	 * @param br
	 *            BidRequest. Returns true if the creative matches.
	 * @param errorString
	 *            StringBuilder. The string to hold any campaign failure
	 *            messages
	 * @return boolean. Returns true of this campaign matches the bid request,
	 *         ie eligible to bid
	 */
public SelectedCreative process(BidRequest br, Map<String, String> capSpecs, String adId, StringBuilder errorString, Probe probe) {
    int n = br.getImpressions();
    StringBuilder sb = new StringBuilder();
    Impression imp;
    if (br.checkNonStandard(this, errorString) != true) {
        return null;
    }
    for (int i = 0; i < n; i++) {
        imp = br.getImpression(i);
        SelectedCreative cr = xproc(br, adId, imp, capSpecs, errorString, probe);
        if (cr != null) {
            if (isCapped(br, capSpecs)) {
                sb.append("This creative is capped for " + capSpecification);
                if (errorString != null) {
                    probe.process(br.getExchange(), adId, impid, sb);
                    errorString.append(sb);
                }
                return null;
            }
            cr.setImpression(imp);
            return cr;
        }
    }
    return null;
}
Also used : SelectedCreative(com.xrtb.bidder.SelectedCreative) Impression(com.xrtb.pojo.Impression)

Example 5 with Impression

use of com.xrtb.pojo.Impression in project XRTB by benmfaul.

the class Creative method createSample.

/**
	 * Creates a sample of the ADM field, useful for testing your ad markup to
	 * make sure it works.
	 * 
	 * @param camp
	 *            Campaign. The campaign to use with this creative.
	 * @return String. The ad markup HTML.
	 */
public String createSample(Campaign camp) {
    BidRequest request = new Nexage();
    String page = null;
    String str = null;
    File temp = null;
    Impression imp = new Impression();
    imp.w = 666;
    imp.h = 666;
    BidResponse br = null;
    try {
        if (this.isVideo()) {
            br = new BidResponse(request, imp, camp, this, "123", 1.0, null, 0);
            imp.video = new Video();
            imp.video.linearity = this.videoLinearity;
            imp.video.protocol.add(this.videoProtocol);
            imp.video.maxduration = this.videoDuration + 1;
            imp.video.minduration = this.videoDuration - 1;
            str = br.getAdmAsString();
            /**
				 * Read in the stubbed video page and patch the VAST into it
				 */
            page = new String(Files.readAllBytes(Paths.get("web/videostub.html")), StandardCharsets.UTF_8);
            page = page.replaceAll("___VIDEO___", "http://localhost:8080/vast/onion270.xml");
        } else if (this.isNative()) {
            // br = new BidResponse(request, camp, this,"123",0);
            // request.nativead = true;
            // request.nativePart = new NativePart();
            // str = br.getAdmAsString();
            page = "<html><title>Test Creative</title><body><img src='images/under-construction.gif'></img></body></html>";
        } else {
            br = new BidResponse(request, imp, camp, this, "123", 1.0, null, 0);
            str = br.getAdmAsString();
            page = "<html><title>Test Creative</title><body><xmp>" + str + "</xmp>" + str + "</body></html>";
        }
        page = page.replaceAll("\\{AUCTION_PRICE\\}", "0.2");
        page = page.replaceAll("\\$", "");
        temp = File.createTempFile("test", ".html", new File("www/temp"));
        temp.deleteOnExit();
        Files.write(Paths.get(temp.getAbsolutePath()), page.getBytes());
    } catch (Exception error) {
        error.printStackTrace();
    }
    return "temp/" + temp.getName();
}
Also used : Video(com.xrtb.pojo.Video) Impression(com.xrtb.pojo.Impression) BidResponse(com.xrtb.pojo.BidResponse) File(java.io.File) BidRequest(com.xrtb.pojo.BidRequest) Nexage(com.xrtb.exchanges.Nexage)

Aggregations

Impression (com.xrtb.pojo.Impression)5 BidResponse (com.xrtb.pojo.BidResponse)3 Campaign (com.xrtb.common.Campaign)2 ProtocolStringList (com.google.protobuf.ProtocolStringList)1 SelectedCreative (com.xrtb.bidder.SelectedCreative)1 Creative (com.xrtb.common.Creative)1 Node (com.xrtb.common.Node)1 Nexage (com.xrtb.exchanges.Nexage)1 BidRequest (com.xrtb.pojo.BidRequest)1 Video (com.xrtb.pojo.Video)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1