Skip to content

Commit

Permalink
Use video.plcmt to Resolve Media Type (#3572)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoxaAntoxic authored Dec 4, 2024
1 parent f6276c9 commit 9cb9a83
Show file tree
Hide file tree
Showing 6 changed files with 303 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ private static ImpMediaType resolveBidAdjustmentVideoMediaType(String bidImpId,
.orElse(null);

if (bidImpVideo == null) {
return null;
return ImpMediaType.video_outstream;
}

final Integer placement = bidImpVideo.getPlacement();
return placement == null || Objects.equals(placement, 1)
? ImpMediaType.video
final Integer plcmt = bidImpVideo.getPlcmt();

return Objects.equals(placement, 1) || Objects.equals(plcmt, 1)
? ImpMediaType.video_instream
: ImpMediaType.video_outstream;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,33 @@ public AuctionParticipation enrichWithAdjustedBids(AuctionParticipation auctionP
return auctionParticipation.with(updatedBidderResponse);
}

private static ExtRequestBidAdjustmentFactors extBidAdjustmentFactors(BidRequest bidRequest) {
final ExtRequestPrebid prebid = PbsUtil.extRequestPrebid(bidRequest);
return prebid != null ? prebid.getBidadjustmentfactors() : null;
}

private static BigDecimal adjustPrice(BigDecimal priceAdjustmentFactor, BigDecimal price) {
return priceAdjustmentFactor != null && priceAdjustmentFactor.compareTo(BigDecimal.ONE) != 0
? price.multiply(priceAdjustmentFactor)
: price;
}

private BidderBid applyBidAdjustments(BidderBid bidderBid,
BidRequest bidRequest,
String bidder,
BidAdjustments bidAdjustments,
List<BidderError> errors) {
try {
final Price originalPrice = getOriginalPrice(bidderBid);

final ImpMediaType mediaType = ImpMediaTypeResolver.resolve(
bidderBid.getBid().getImpid(),
bidRequest.getImp(),
bidderBid.getType());

final Price priceWithFactorsApplied = applyBidAdjustmentFactors(
originalPrice,
bidderBid,
bidder,
bidRequest);
bidRequest,
mediaType);

final Price priceWithAdjustmentsApplied = applyBidAdjustmentRules(
priceWithFactorsApplied,
bidderBid,
bidder,
bidRequest,
bidAdjustments);
bidAdjustments,
mediaType,
bidderBid.getBid().getDealid());

return updateBid(originalPrice, priceWithAdjustmentsApplied, bidderBid, bidRequest);
} catch (PreBidException e) {
errors.add(BidderError.generic(e.getMessage()));
Expand Down Expand Up @@ -154,51 +152,54 @@ private Price getOriginalPrice(BidderBid bidderBid) {
return Price.of(StringUtils.stripToNull(bidCurrency), price);
}

private Price applyBidAdjustmentFactors(Price bidPrice, BidderBid bidderBid, String bidder, BidRequest bidRequest) {
private Price applyBidAdjustmentFactors(Price bidPrice,
String bidder,
BidRequest bidRequest,
ImpMediaType mediaType) {

final String bidCurrency = bidPrice.getCurrency();
final BigDecimal price = bidPrice.getValue();

final BigDecimal priceAdjustmentFactor = bidAdjustmentForBidder(bidder, bidRequest, bidderBid);
final BigDecimal priceAdjustmentFactor = bidAdjustmentForBidder(bidder, bidRequest, mediaType);
final BigDecimal adjustedPrice = adjustPrice(priceAdjustmentFactor, price);

return Price.of(bidCurrency, adjustedPrice.compareTo(price) != 0 ? adjustedPrice : price);
}

private BigDecimal bidAdjustmentForBidder(String bidder, BidRequest bidRequest, BidderBid bidderBid) {
private BigDecimal bidAdjustmentForBidder(String bidder, BidRequest bidRequest, ImpMediaType mediaType) {
final ExtRequestBidAdjustmentFactors adjustmentFactors = extBidAdjustmentFactors(bidRequest);
if (adjustmentFactors == null) {
return null;
}

final ImpMediaType mediaType = ImpMediaTypeResolver.resolve(
bidderBid.getBid().getImpid(),
bidRequest.getImp(),
bidderBid.getType());
final ImpMediaType targetMediaType = mediaType == ImpMediaType.video_instream ? ImpMediaType.video : mediaType;
return bidAdjustmentFactorResolver.resolve(targetMediaType, adjustmentFactors, bidder);
}

private static ExtRequestBidAdjustmentFactors extBidAdjustmentFactors(BidRequest bidRequest) {
final ExtRequestPrebid prebid = PbsUtil.extRequestPrebid(bidRequest);
return prebid != null ? prebid.getBidadjustmentfactors() : null;
}

return bidAdjustmentFactorResolver.resolve(mediaType, adjustmentFactors, bidder);
private static BigDecimal adjustPrice(BigDecimal priceAdjustmentFactor, BigDecimal price) {
return priceAdjustmentFactor != null && priceAdjustmentFactor.compareTo(BigDecimal.ONE) != 0
? price.multiply(priceAdjustmentFactor)
: price;
}

private Price applyBidAdjustmentRules(Price bidPrice,
BidderBid bidderBid,
String bidder,
BidRequest bidRequest,
BidAdjustments bidAdjustments) {

final Bid bid = bidderBid.getBid();
final String bidCurrency = bidPrice.getCurrency();
final BigDecimal price = bidPrice.getValue();

final ImpMediaType mediaType = ImpMediaTypeResolver.resolve(
bid.getImpid(),
bidRequest.getImp(),
bidderBid.getType());
BidAdjustments bidAdjustments,
ImpMediaType mediaType,
String dealId) {

return bidAdjustmentsResolver.resolve(
Price.of(bidCurrency, price),
bidPrice,
bidRequest,
bidAdjustments,
mediaType == null || mediaType == ImpMediaType.video ? ImpMediaType.video_instream : mediaType,
mediaType,
bidder,
bid.getDealid());
dealId);
}
}
Loading

0 comments on commit 9cb9a83

Please sign in to comment.