Skip to content

Commit

Permalink
allow custom Ad structure
Browse files Browse the repository at this point in the history
  • Loading branch information
cxx24 committed Apr 21, 2024
1 parent 4ff7575 commit 7470c95
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 14 additions & 2 deletions rtb/core/ad_selector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ static auto chain_function(BidRequest &&req, Impression &&imp, Arg &&arg,

} // namespace detail

template <typename T>
concept is_vanilla_standard_ad = requires(T value) {
value.auth_bid_micros;
value.max_bid_micros;
};

template<typename BudgetManager, typename Ad>
class ad_selector {
public:
Expand All @@ -66,10 +72,16 @@ class ad_selector {
template<typename BidRequest, typename Impression, typename HeadArg , typename... Funcs>
auto select(BidRequest&& req, Impression&& imp, HeadArg&& head, Funcs... funcs) {
auto ads = detail::chain_function( std::forward<BidRequest>(req), std::forward<Impression>(imp), std::forward<HeadArg>(head), funcs...);
if(selection_algo) {
if (selection_algo) {
return selection_algo(ads);
} else {
if constexpr ( is_vanilla_standard_ad<Ad>) {
return algorithm::calculate_max_bid(ads);
} else {
// TODO: add compile time warning for using dummy algo
return std::unique_ptr<Ad>{};
}
}
return algorithm::calculate_max_bid(ads);
}

template<typename BudgetCache , typename CampaignId>
Expand Down
5 changes: 4 additions & 1 deletion rtb/core/bidder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ namespace vanilla {
bid.id = boost::uuids::to_string(bidid); // TODO check documentation
// Is it the same as response.bidid?
bid.impid = imp.id;
bid.price = ad.auth_bid_micros ? *ad.auth_bid_micros / 1000000.0 : ad.max_bid_micros / 1000000.0 ; // Not micros?
if constexpr (sizeof...(Processor) <= 0) {
bid.price =
ad.auth_bid_price ? *ad.auth_bid_price / 1000000.0 : ad.max_bid_micros / 1000000.0;
}
bid.w = ad.width;
bid.h = ad.height;
bid.adm = ad.code;
Expand Down

0 comments on commit 7470c95

Please sign in to comment.