From f483f33262889851f12f972fc1468d46058d20df Mon Sep 17 00:00:00 2001 From: EvgeniiMunin Date: Wed, 26 Jun 2024 18:38:00 +0200 Subject: [PATCH] filtering: fix update imp ext --- ...alTimeDataProcessedAuctionRequestHook.java | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/v1/GreenbidsRealTimeDataProcessedAuctionRequestHook.java b/extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/v1/GreenbidsRealTimeDataProcessedAuctionRequestHook.java index 0dff4d5c502..d3da6f33c57 100644 --- a/extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/v1/GreenbidsRealTimeDataProcessedAuctionRequestHook.java +++ b/extra/modules/greenbids-real-time-data/src/main/java/org/prebid/server/hooks/modules/greenbids/real/time/data/v1/GreenbidsRealTimeDataProcessedAuctionRequestHook.java @@ -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; @@ -114,7 +113,8 @@ public Future> 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 threshold = Arrays.asList(0.1, 0.9, 0.2); Map> impsBiddersFilterMap = new HashMap<>(); StreamSupport.stream(results.spliterator(), false) @@ -135,7 +135,7 @@ public Future> 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); @@ -149,6 +149,7 @@ public Future> call( List impsWithFilteredBidders = updateImps(bidRequest, impsBiddersFilterMap); BidRequest updatedBidRequest = bidRequest.toBuilder().imp(impsWithFilteredBidders).build(); + // update invocation result InvocationResult invocationResult = InvocationResultImpl.builder() .status(InvocationStatus.success) @@ -159,6 +160,14 @@ public Future> 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); } @@ -175,29 +184,23 @@ private Imp updateImp(Imp imp, Map bidderFilterMap) { } private ObjectNode updateImpExt(ObjectNode impExt, Map 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 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 entry: bidderFilterMap.entrySet()) { + String bidderName = entry.getKey(); + Boolean isKeptInAuction = entry.getValue(); + + if (!isKeptInAuction) { + bidderNode.remove(bidderName); + } + } } } - return bidderNode; + + return updatedExt; } private List extractThrottlingMessages(