Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use video.plcmt to Resolve Media Type #3572

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading