use of com.xrtb.common.Node in project XRTB by benmfaul.
the class TestNode method testOr.
@Test
public void testOr() throws Exception {
BidRequest br = new BidRequest(Configuration.getInputStream("SampleBids/atomx.txt"));
br.setExchange("atomx");
assertNotNull(br);
List ilist = new ArrayList();
Node a = new Node("site", "site.publisher.id", Node.EQUALS, "3456");
ilist.add(a);
a = new Node("site", "app.publisher.id", Node.EQUALS, "3456");
ilist.add(a);
Node node = new Node("ortest", null, Node.OR, ilist);
Boolean b = node.test(br);
assertTrue(b);
// reverse order
ilist = new ArrayList();
a = new Node("site", "app.publisher.id", Node.EQUALS, "3456");
ilist.add(a);
a = new Node("site", "site.publisher.id", Node.EQUALS, "3456");
ilist.add(a);
node = new Node("ortest", null, Node.OR, ilist);
b = node.test(br);
assertTrue(b);
// actual is second and bad
ilist = new ArrayList();
a = new Node("app", "app.publisher.id", Node.EQUALS, "3456");
ilist.add(a);
a = new Node("site", "site.publisher.id", Node.EQUALS, "666");
ilist.add(a);
node = new Node("ortest", null, Node.OR, ilist);
b = node.test(br);
assertFalse(b);
// actual is first and bad
ilist = new ArrayList();
a = new Node("site", "site.publisher.id", Node.EQUALS, "666");
ilist.add(a);
a = new Node("app", "app.publisher.id", Node.EQUALS, "3456");
ilist.add(a);
node = new Node("ortest", null, Node.OR, ilist);
b = node.test(br);
assertFalse(b);
}
use of com.xrtb.common.Node in project XRTB by benmfaul.
the class TestNode method testOperatorsInImpressions.
@Test
public void testOperatorsInImpressions() throws Exception {
BidRequest br = new BidRequest(Configuration.getInputStream("SampleBids/c1x.txt"));
br.setExchange("c1x");
assertNotNull(br);
/* Node node = new Node("=","imp.0.banner.tagid","EQUALS","14404-loge-300x25");
boolean b = node.test(br); // true means the constraint is satisfied.
assertTrue(b);
br = new BidRequest(Configuration.getInputStream("SampleBids/c1xMulti.txt"));
br.setExchange( "c1x" );
assertNotNull(br);
node = new Node("=","imp.0.banner.id","EQUALS","2");
b = node.test(br); // true means the constraint is satisfied.
assertFalse(b);
node = new Node("=","imp.1.banner.id","EQUALS","2");
b = node.test(br); // true means the constraint is satisfied.
assertTrue(b); */
br = new BidRequest(Configuration.getInputStream("SampleBids/c1xMulti.txt"));
ArrayList list = new ArrayList();
list.add("2");
Node node = new Node("=", "imp.*.banner.id", Node.INTERSECTS, list);
// true means the constraint is satisfied.
boolean b = node.test(br);
assertTrue(b);
}
use of com.xrtb.common.Node in project XRTB by benmfaul.
the class TestNode method testMemberOfBuiltin.
@Test
public void testMemberOfBuiltin() throws Exception {
BidRequest br = new BidRequest(Configuration.getInputStream("SampleBids/nexage.txt"));
assertNotNull(br);
String op = "MEMBER";
Node node = new Node("mimes", "imp.0.banner.mimes", op, "image/jpg");
boolean b = node.test(br);
assertTrue(b);
}
use of com.xrtb.common.Node in project XRTB by benmfaul.
the class CampaignProcessor method run.
public void run() {
boolean printNoBidReason = Configuration.getInstance().printNoBidReason;
int logLevel = 5;
StringBuilder err = null;
if (printNoBidReason || br.id.equals("123") || probe != null) {
err = new StringBuilder();
printNoBidReason = true;
if (br.id.equals("123"))
logLevel = 1;
}
if (flag != null) {
try {
flag.await();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
if (latch != null)
latch.countNull();
done = true;
return;
}
}
/**
* See if there is a creative that matches first
*/
if (camp == null) {
if (latch != null)
latch.countNull();
done = true;
return;
}
Node n = null;
try {
for (int i = 0; i < camp.attributes.size(); i++) {
n = camp.attributes.get(i);
if (n.test(br) == false) {
if (printNoBidReason)
if (probe != null) {
probe.process(br.getExchange(), camp.adId, "Global", new StringBuilder(n.hierarchy));
}
if (logLevel == 1)
Controller.getInstance().sendLog(logLevel, "CampaignProcessor:run:attribute-failed", camp.adId + ": " + n.hierarchy + " doesn't match the bidrequest");
done = true;
if (latch != null)
latch.countNull();
selected = null;
return;
}
}
} catch (Exception error) {
System.out.println("-----------> Campaign: " + camp.adId + ", ERROR IN NODE: " + n.name + ", Hierarchy = " + n.hierarchy);
System.out.println(br.toString());
error.printStackTrace();
selected = null;
done = true;
if (latch != null)
latch.countNull();
return;
}
// rec.add("nodes");
///////////////////////////
Map<String, String> capSpecs = new ConcurrentHashMap();
List<Creative> creatives = new ArrayList(camp.creatives);
Collections.shuffle(creatives);
StringBuilder xerr = new StringBuilder();
for (Creative create : creatives) {
if ((selected = create.process(br, capSpecs, camp.adId, err, probe)) != null) {
break;
} else {
if (probe != null) {
probe.process(br.getExchange(), camp.adId, create.impid, err);
if (printNoBidReason) {
xerr.append(camp.adId);
xerr.append("/");
xerr.append(create.impid);
xerr.append(" ===> ");
xerr.append(err);
xerr.append("\n");
}
err.setLength(0);
}
}
}
probe.incrementTotal(br.getExchange(), camp.adId);
err = xerr;
if (selected == null) {
if (latch != null)
latch.countNull();
if (printNoBidReason)
try {
Controller.getInstance().sendLog(logLevel, "CampaignProcessor:run:campaign:nothing matches", err.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
done = true;
if (err != null)
err.setLength(0);
return;
}
if (printNoBidReason) {
String str = "";
str += selected.impid + " ";
try {
Controller.getInstance().sendLog(logLevel, "CampaignProcessor:run:campaign:is-candidate", camp.adId + ", creatives = " + str);
} catch (Exception error) {
error.printStackTrace();
}
}
selected.capSpec = capSpecs.get(selected.creative.impid);
try {
if (printNoBidReason && logLevel == 1) {
Controller.getInstance().sendLog(logLevel, "CampaignProcessor:run:campaign:no match: ", err.toString());
}
} catch (Exception error) {
error.printStackTrace();
}
if (latch != null)
latch.countDown(selected);
if (probe != null) {
probe.process(br.getExchange(), camp.adId, selected.impid);
}
selected.campaign = this.camp;
probe.incrementBid(br.getExchange(), camp.adId);
done = true;
}
use of com.xrtb.common.Node 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;
}
Aggregations