Skip to content

Commit

Permalink
filtering: fix update imp ext
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgeniiMunin committed Jun 26, 2024
1 parent 412e9f6 commit f483f33
Showing 1 changed file with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

Expand Down Expand Up @@ -114,7 +113,8 @@ public Future<InvocationResult<AuctionRequestPayload>> call(
long duration = (endTime - startTime); // in nanoseconds
System.out.println("Inference time: " + duration / 1000000.0 + " ms");

double threshold = 0.15;
//double threshold = 0.5;
List<Double> threshold = Arrays.asList(0.1, 0.9, 0.2);
Map<String, Map<String, Boolean>> impsBiddersFilterMap = new HashMap<>();

StreamSupport.stream(results.spliterator(), false)
Expand All @@ -135,7 +135,7 @@ public Future<InvocationResult<AuctionRequestPayload>> call(
ThrottlingMessage message = throttlingMessages.get(i);
String impId = message.getAdUnitCode();
String bidder = message.getBidder();
boolean isKeptInAuction = probas[i][1] > threshold;
boolean isKeptInAuction = probas[i][1] > threshold.get(i);

impsBiddersFilterMap.computeIfAbsent(impId, k -> new HashMap<>())
.put(bidder, isKeptInAuction);
Expand All @@ -149,6 +149,7 @@ public Future<InvocationResult<AuctionRequestPayload>> call(
List<Imp> impsWithFilteredBidders = updateImps(bidRequest, impsBiddersFilterMap);
BidRequest updatedBidRequest = bidRequest.toBuilder().imp(impsWithFilteredBidders).build();


// update invocation result
InvocationResult<AuctionRequestPayload> invocationResult = InvocationResultImpl.<AuctionRequestPayload>builder()
.status(InvocationStatus.success)
Expand All @@ -159,6 +160,14 @@ public Future<InvocationResult<AuctionRequestPayload>> call(
.payloadUpdate(payload -> AuctionRequestPayloadImpl.of(updatedBidRequest))
.build();

System.out.println(
"GreenbidsRealTimeDataProcessedAuctionRequestHook/call" + "\n" +
"impsBiddersFilterMap: " + impsBiddersFilterMap + "\n" +
"impsWithFilteredBidders: " + impsWithFilteredBidders + "\n" +
"updatedBidRequest: " + updatedBidRequest + "\n" +
"invocationResult: " + invocationResult
);

return Future.succeededFuture(invocationResult);
}

Expand All @@ -175,29 +184,23 @@ private Imp updateImp(Imp imp, Map<String, Boolean> bidderFilterMap) {
}

private ObjectNode updateImpExt(ObjectNode impExt, Map<String, Boolean> bidderFilterMap) {

ObjectNode bidderNode = Optional.ofNullable(impExt)
.map(ext -> extImpPrebid(ext.get("prebid")))
.map(ExtImpPrebid::getBidder)
.orElse(null);

//final JsonNode extPrebid = ext.path("prebid");
//final JsonNode impExtNode = imp.getExt();
//final JsonNode bidderExtNode = isNotEmptyOrMissedNode(impExtNode) ? impExtNode.get("bidder") : null;
//JsonNode bidderNode = extImpPrebid(impExt.get("prebid")).getBidder();

//final JsonNode extPrebid = ext.path("prebid");
//JsonNode bidderNode = extImpPrebid(ext.get("prebid")).getBidder();

for(Map.Entry<String, Boolean> entry: bidderFilterMap.entrySet()) {
String bidderName = entry.getKey();
Boolean isKeptInAuction = entry.getValue();

if (!isKeptInAuction & bidderNode != null) {
bidderNode.remove(bidderName);
ObjectNode updatedExt = impExt.deepCopy();
ObjectNode prebidNode = (ObjectNode) updatedExt.get("prebid");
if (prebidNode != null) {
ObjectNode bidderNode = (ObjectNode) prebidNode.get("bidder");
if (bidderNode != null) {
for(Map.Entry<String, Boolean> entry: bidderFilterMap.entrySet()) {
String bidderName = entry.getKey();
Boolean isKeptInAuction = entry.getValue();

if (!isKeptInAuction) {
bidderNode.remove(bidderName);
}
}
}
}
return bidderNode;

return updatedExt;
}

private List<ThrottlingMessage> extractThrottlingMessages(
Expand Down

0 comments on commit f483f33

Please sign in to comment.