Skip to content

Commit

Permalink
Eplanning: new prioritization metric for adunit sizes (#1648)
Browse files Browse the repository at this point in the history
* Eplanning: new prioritization metric for adunit sizes
  • Loading branch information
chino117 authored Jan 26, 2021
1 parent 56672f8 commit d61f2d5
Show file tree
Hide file tree
Showing 6 changed files with 459 additions and 7 deletions.
41 changes: 34 additions & 7 deletions adapters/eplanning/eplanning.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const sec = "ROS"
const dfpClientID = "1"
const requestTargetInventory = "1"

var priorityOrderForMobileSizesAsc = []string{"1x1", "300x50", "320x50", "300x250"}
var priorityOrderForDesktopSizesAsc = []string{"1x1", "970x90", "970x250", "160x600", "300x600", "728x90", "300x250"}

var cleanNameSteps = []cleanNameStep{
{regexp.MustCompile(`_|\.|-|\/`), ""},
{regexp.MustCompile(`\)\(|\(|\)|:`), "_"},
Expand Down Expand Up @@ -67,10 +70,11 @@ func (adapter *EPlanningAdapter) MakeRequests(request *openrtb.BidRequest, reqIn
spacesStrings := make([]string, 0, totalImps)
totalRequests := 0
clientID := ""
isMobile := isMobileDevice(request)

for i := 0; i < totalImps; i++ {
imp := request.Imp[i]
extImp, err := verifyImp(&imp)
extImp, err := verifyImp(&imp, isMobile)
if err != nil {
errors = append(errors, err)
continue
Expand Down Expand Up @@ -187,14 +191,18 @@ func (adapter *EPlanningAdapter) MakeRequests(request *openrtb.BidRequest, reqIn
return requests, errors
}

func isMobileDevice(request *openrtb.BidRequest) bool {
return request.Device != nil && (request.Device.DeviceType == openrtb.DeviceTypeMobileTablet || request.Device.DeviceType == openrtb.DeviceTypePhone || request.Device.DeviceType == openrtb.DeviceTypeTablet)
}

func cleanName(name string) string {
for _, step := range cleanNameSteps {
name = step.expression.ReplaceAllString(name, step.replacementString)
}
return name
}

func verifyImp(imp *openrtb.Imp) (*openrtb_ext.ExtImpEPlanning, error) {
func verifyImp(imp *openrtb.Imp, isMobile bool) (*openrtb_ext.ExtImpEPlanning, error) {
var bidderExt adapters.ExtImpBidder

if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
Expand All @@ -217,7 +225,7 @@ func verifyImp(imp *openrtb.Imp) (*openrtb_ext.ExtImpEPlanning, error) {
}
}

width, height := getSizeFromImp(imp)
width, height := getSizeFromImp(imp, isMobile)

if width == 0 && height == 0 {
impExt.SizeString = nullSize
Expand All @@ -232,17 +240,34 @@ func verifyImp(imp *openrtb.Imp) (*openrtb_ext.ExtImpEPlanning, error) {
return &impExt, nil
}

func getSizeFromImp(imp *openrtb.Imp) (uint64, uint64) {
func searchSizePriority(hashedFormats map[string]int, format []openrtb.Format, priorityOrderForSizesAsc []string) (uint64, uint64) {
for i := len(priorityOrderForSizesAsc) - 1; i >= 0; i-- {
if formatIndex, wasFound := hashedFormats[priorityOrderForSizesAsc[i]]; wasFound {
return format[formatIndex].W, format[formatIndex].H
}
}
return format[0].W, format[0].H
}

func getSizeFromImp(imp *openrtb.Imp, isMobile bool) (uint64, uint64) {
if imp.Banner.W != nil && imp.Banner.H != nil {
return *imp.Banner.W, *imp.Banner.H
}

if imp.Banner.Format != nil {
for _, format := range imp.Banner.Format {
hashedFormats := make(map[string]int, len(imp.Banner.Format))

for i, format := range imp.Banner.Format {
if format.W != 0 && format.H != 0 {
return format.W, format.H
hashedFormats[fmt.Sprintf("%dx%d", format.W, format.H)] = i
}
}

if isMobile {
return searchSizePriority(hashedFormats, imp.Banner.Format, priorityOrderForMobileSizesAsc)
} else {
return searchSizePriority(hashedFormats, imp.Banner.Format, priorityOrderForDesktopSizesAsc)
}
}

return 0, 0
Expand Down Expand Up @@ -278,12 +303,14 @@ func (adapter *EPlanningAdapter) MakeBids(internalRequest *openrtb.BidRequest, e
}}
}

isMobile := isMobileDevice(internalRequest)

bidResponse := adapters.NewBidderResponse()

spaceNameToImpID := make(map[string]string)

for _, imp := range internalRequest.Imp {
extImp, err := verifyImp(&imp)
extImp, err := verifyImp(&imp, isMobile)
if err != nil {
continue
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"mockBidRequest": {
"id": "test-request-id",
"device": {
"devicetype": 4
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 1,
"h": 1
}
]
},
"ext": {
"bidder": {
"ci": "12345"
}
}
}
]
},

"httpCalls": [
{
"expectedRequest": {
"uri": "http://rtb.e-planning.net/pbs/1/12345/1/FILE/ROS?e=300x250%3A300x250&ncb=1&ur=FILE",
"body": {}
},
"mockResponse": {
"status": 200,
"body": {
"sI": { "k": "12345" },
"sec": "ROS",
"sp": [
{
"k": "300x250",
"a": [{
"i": "123456789abcdef",
"pr": "0.5",
"adm": "<div>test</div>",
"crid": "abcdef123456789",
"id": "adid12345",
"w": 300,
"h": 250
}]
}
]
}
}
}
],

"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "123456789abcdef",
"impid": "test-imp-id",
"price": 0.5,
"adm": "<div>test</div>",
"adid": "adid12345",
"crid": "abcdef123456789",
"w": 300,
"h": 250
},
"type": "banner"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"mockBidRequest": {
"id": "test-request-id",
"device": {
"devicetype": 2
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 970,
"h": 250
},
{
"w": 300,
"h": 600
},
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"ci": "12345"
}
}
}
]
},

"httpCalls": [
{
"expectedRequest": {
"uri": "http://rtb.e-planning.net/pbs/1/12345/1/FILE/ROS?e=300x250%3A300x250&ncb=1&ur=FILE",
"body": {}
},
"mockResponse": {
"status": 200,
"body": {
"sI": { "k": "12345" },
"sec": "ROS",
"sp": [
{
"k": "300x250",
"a": [{
"i": "123456789abcdef",
"pr": "0.5",
"adm": "<div>test</div>",
"crid": "abcdef123456789",
"id": "adid12345",
"w": 300,
"h": 250
}]
}
]
}
}
}
],

"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "123456789abcdef",
"impid": "test-imp-id",
"price": 0.5,
"adm": "<div>test</div>",
"adid": "adid12345",
"crid": "abcdef123456789",
"w": 300,
"h": 250
},
"type": "banner"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"mockBidRequest": {
"id": "test-request-id",
"device": {
"devicetype": 4
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 1,
"h": 1
},
{
"w": 300,
"h": 50
},
{
"w": 320,
"h": 50
}
]
},
"ext": {
"bidder": {
"ci": "12345"
}
}
}
]
},

"httpCalls": [
{
"expectedRequest": {
"uri": "http://rtb.e-planning.net/pbs/1/12345/1/FILE/ROS?e=320x50%3A320x50&ncb=1&ur=FILE",
"body": {}
},
"mockResponse": {
"status": 200,
"body": {
"sI": { "k": "12345" },
"sec": "ROS",
"sp": [
{
"k": "320x50",
"a": [{
"i": "123456789abcdef",
"pr": "0.5",
"adm": "<div>test</div>",
"crid": "abcdef123456789",
"id": "adid12345",
"w": 320,
"h": 50
}]
}
]
}
}
}
],

"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "123456789abcdef",
"impid": "test-imp-id",
"price": 0.5,
"adm": "<div>test</div>",
"adid": "adid12345",
"crid": "abcdef123456789",
"w": 320,
"h": 50
},
"type": "banner"
}
]
}
]
}
Loading

0 comments on commit d61f2d5

Please sign in to comment.