-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fledgeForGpt: provide
bidfloor
in auction signals (#10393)
* fledgeForGpt: delay slot config to end of auction * currency utils * reducers * Set `prebid.bidfloor` and `prebid.bidfloorcur` in fledge auction signals --------- Co-authored-by: Patrick McCann <patmmccann@gmail.com>
- Loading branch information
1 parent
ca555d3
commit 7764e53
Showing
20 changed files
with
2,000 additions
and
1,589 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {getGlobal} from '../../src/prebidGlobal.js'; | ||
import {keyCompare} from '../../src/utils/reducers.js'; | ||
|
||
/** | ||
* Attempt to convert `amount` from the currency `fromCur` to the currency `toCur`. | ||
* | ||
* By default, when the conversion is not possible (currency module not present or | ||
* throwing errors), the amount is returned unchanged. This behavior can be | ||
* toggled off with bestEffort = false. | ||
*/ | ||
export function convertCurrency(amount, fromCur, toCur, bestEffort = true) { | ||
if (fromCur === toCur) return amount; | ||
let result = amount; | ||
try { | ||
result = getGlobal().convertCurrency(amount, fromCur, toCur); | ||
} catch (e) { | ||
if (!bestEffort) throw e; | ||
} | ||
return result; | ||
} | ||
|
||
export function currencyNormalizer(toCurrency = null, bestEffort = true, convert = convertCurrency) { | ||
return function (amount, currency) { | ||
if (toCurrency == null) toCurrency = currency; | ||
return convert(amount, currency, toCurrency, bestEffort); | ||
} | ||
} | ||
|
||
export function currencyCompare(get = (obj) => [obj.cpm, obj.currency], normalize = currencyNormalizer()) { | ||
return keyCompare(obj => normalize.apply(null, get(obj))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
export function simpleCompare(a, b) { | ||
if (a === b) return 0; | ||
return a < b ? -1 : 1; | ||
} | ||
|
||
export function keyCompare(key = (item) => item) { | ||
return (a, b) => simpleCompare(key(a), key(b)) | ||
} | ||
|
||
export function reverseCompare(compare = simpleCompare) { | ||
return (a, b) => -compare(a, b) || 0; | ||
} | ||
|
||
export function tiebreakCompare(...compares) { | ||
return function (a, b) { | ||
for (const cmp of compares) { | ||
const val = cmp(a, b); | ||
if (val !== 0) return val; | ||
} | ||
return 0; | ||
} | ||
} | ||
|
||
export function minimum(compare = simpleCompare) { | ||
return (min, item) => compare(item, min) < 0 ? item : min; | ||
} | ||
|
||
export function maximum(compare = simpleCompare) { | ||
return minimum(reverseCompare(compare)); | ||
} | ||
|
||
const cpmCompare = keyCompare((bid) => bid.cpm); | ||
const timestampCompare = keyCompare((bid) => bid.responseTimestamp); | ||
|
||
// This function will get highest cpm value bid, in case of tie it will return the bid with lowest timeToRespond | ||
export const getHighestCpm = maximum(tiebreakCompare(cpmCompare, reverseCompare(keyCompare((bid) => bid.timeToRespond)))) | ||
|
||
// This function will get the oldest hightest cpm value bid, in case of tie it will return the bid which came in first | ||
// Use case for tie: https://github.com/prebid/Prebid.js/issues/2448 | ||
export const getOldestHighestCpmBid = maximum(tiebreakCompare(cpmCompare, reverseCompare(timestampCompare))) | ||
|
||
// This function will get the latest hightest cpm value bid, in case of tie it will return the bid which came in last | ||
// Use case for tie: https://github.com/prebid/Prebid.js/issues/2539 | ||
export const getLatestHighestCpmBid = maximum(tiebreakCompare(cpmCompare, timestampCompare)) |
Oops, something went wrong.