Skip to content

Commit

Permalink
Added float precision check in floor price comparision (#3042)
Browse files Browse the repository at this point in the history
* Added float precision check in floor price comparision

* Fixed review comments
  • Loading branch information
pm-jaydeep-mohite authored Sep 5, 2023
1 parent 89f79e3 commit 4c10fac
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 11 deletions.
2 changes: 1 addition & 1 deletion floors/enforce.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func enforceFloorToBids(bidRequestWrapper *openrtb_ext.RequestWrapper, seatBids
}

bidPrice := rate * bid.Bid.Price
if reqImp.BidFloor > bidPrice {
if (bidPrice + floorPrecision) < reqImp.BidFloor {
rejectedBid := &entities.PbsOrtbSeatBid{
Currency: seatBid.Currency,
Seat: seatBid.Seat,
Expand Down
66 changes: 65 additions & 1 deletion floors/enforce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,71 @@ func TestEnforceFloorToBids(t *testing.T) {
},
expErrs: []error{},
},
{
name: "Bids with price less than bidfloor with floorsPrecision",
args: args{
bidRequestWrapper: func() *openrtb_ext.RequestWrapper {
bw := openrtb_ext.RequestWrapper{
BidRequest: &openrtb2.BidRequest{
ID: "some-request-id",
Imp: []openrtb2.Imp{
{ID: "some-impression-id-1", BidFloor: 1, BidFloorCur: "USD"},
{ID: "some-impression-id-2", BidFloor: 2, BidFloorCur: "USD"},
},
},
}
bw.RebuildRequest()
return &bw
}(),
seatBids: map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid{
"pubmatic": {
Bids: []*entities.PbsOrtbBid{
{Bid: &openrtb2.Bid{ID: "some-bid-1", Price: 0.998, ImpID: "some-impression-id-1"}},
{Bid: &openrtb2.Bid{ID: "some-bid-2", Price: 1.5, DealID: "deal_Id", ImpID: "some-impression-id-2"}},
},
Seat: "pubmatic",
Currency: "USD",
},
"appnexus": {
Bids: []*entities.PbsOrtbBid{
{Bid: &openrtb2.Bid{ID: "some-bid-11", Price: 0.8, ImpID: "some-impression-id-1"}},
{Bid: &openrtb2.Bid{ID: "some-bid-12", Price: 2.2, ImpID: "some-impression-id-2"}},
},
Seat: "appnexus",
Currency: "USD",
},
},
conversions: currency.Conversions(convert{}),
enforceDealFloors: false,
},
expEligibleBids: map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid{
"pubmatic": {
Bids: []*entities.PbsOrtbBid{
{Bid: &openrtb2.Bid{ID: "some-bid-1", Price: 0.998, ImpID: "some-impression-id-1"}},
{Bid: &openrtb2.Bid{ID: "some-bid-2", Price: 1.5, DealID: "deal_Id", ImpID: "some-impression-id-2"}},
},
Seat: "pubmatic",
Currency: "USD",
},
"appnexus": {
Bids: []*entities.PbsOrtbBid{
{Bid: &openrtb2.Bid{ID: "some-bid-12", Price: 2.2, ImpID: "some-impression-id-2"}},
},
Seat: "appnexus",
Currency: "USD",
},
},
expRejectedBids: []*entities.PbsOrtbSeatBid{
{
Seat: "appnexus",
Currency: "USD",
Bids: []*entities.PbsOrtbBid{
{Bid: &openrtb2.Bid{ID: "some-bid-11", Price: 0.8, ImpID: "some-impression-id-1"}},
},
},
},
expErrs: []error{},
},
{
name: "Bids with different currency with enforceDealFloor true",
args: args{
Expand Down Expand Up @@ -1154,7 +1219,6 @@ func TestUpdateEnforcePBS(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
got := updateEnforcePBS(tt.args.enforceFloors, tt.args.reqExt)
assert.Equal(t, tt.want, got, tt.name)

})
}
}
19 changes: 10 additions & 9 deletions floors/floors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ type Price struct {
}

const (
defaultCurrency string = "USD"
defaultDelimiter string = "|"
catchAll string = "*"
skipRateMin int = 0
skipRateMax int = 100
modelWeightMax int = 100
modelWeightMin int = 1
enforceRateMin int = 0
enforceRateMax int = 100
defaultCurrency string = "USD"
defaultDelimiter string = "|"
catchAll string = "*"
skipRateMin int = 0
skipRateMax int = 100
modelWeightMax int = 100
modelWeightMin int = 1
enforceRateMin int = 0
enforceRateMax int = 100
floorPrecision float64 = 0.01
)

// EnrichWithPriceFloors checks for floors enabled in account and request and selects floors data from dynamic fetched if present
Expand Down

0 comments on commit 4c10fac

Please sign in to comment.