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 proper MAS size ordering and mapping for rubiconLite adapter #6

Closed
wants to merge 1 commit into from
Closed
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
96 changes: 64 additions & 32 deletions src/adapters/rubiconLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,36 @@ import * as utils from 'src/utils';
import { ajax } from 'src/ajax';
import { STATUS } from 'src/constants';

function RubiconAdapter() {
var sizeMap = {
1:'468x60',
2:'728x90',
8:'120x600',
9:'160x600',
10:'300x600',
15:'300x250',
16:'336x280',
43:'320x50',
44:'300x50',
54:'300x1050',
55:'970x90',
57:'970x250',
58:'1000x90',
59:'320x80',
65:'640x480',
67:'320x480',
68:'1800x1000',
72:'320x320',
73:'320x160',
101:'480x320',
102:'768x1024',
113:'1000x300',
117:'320x100',
125:'800x250',
126:'200x600'
};
utils._each(sizeMap, (item, key) => sizeMap[item] = key);

var sizeMap = {
1:'468x60',
2:'728x90',
8:'120x600',
9:'160x600',
10:'300x600',
15:'300x250',
16:'336x280',
43:'320x50',
44:'300x50',
54:'300x1050',
55:'970x90',
57:'970x250',
58:'1000x90',
59:'320x80',
65:'640x480',
67:'320x480',
68:'1800x1000',
72:'320x320',
73:'320x160',
101:'480x320',
102:'768x1024',
113:'1000x300',
117:'320x100',
125:'800x250',
126:'200x600'
};
utils._each(sizeMap, (item, key) => sizeMap[item] = key);
function RubiconAdapter() {

function _callBids(bidderRequest) {
var bids = bidderRequest.bids || [];
Expand Down Expand Up @@ -82,15 +82,15 @@ function RubiconAdapter() {
// defaults
position = position || 'btf';

var parsedSizes = utils.parseSizesInput(bid.sizes);
var parsedSizes = RubiconAdapter.masSizeOrdering(bid.sizes);

// using array to honor ordering. if order isn't important (it shouldn't be), an object would probably be preferable
var queryString = [
'account_id', accountId,
'site_id', siteId,
'zone_id', zoneId,
'size_id', sizeMap[parsedSizes[0]],
'alt_size_ids', parsedSizes.slice(1).map(size => sizeMap[size]).join(','),
'size_id', parsedSizes[0],
'alt_size_ids', parsedSizes.slice(1).join(','),
'p_pos', position,
'rp_floor', '0.01',
'tk_flint', 'pbjs.lite',
Expand Down Expand Up @@ -175,4 +175,36 @@ function RubiconAdapter() {
};
}

RubiconAdapter.masSizeOrdering = function(sizes) {
const MAS_SIZE_PRIORITY = [15, 2, 9];

return utils.parseSizesInput(sizes)
// map sizes while excluding non-matches
.reduce((result, size) => {
let mappedSize = parseInt(sizeMap[size], 10);
if(mappedSize) {
result.push(mappedSize);
}
return result;
}, [])
.sort((first, second) => {
// sort by MAS_SIZE_PRIORITY priority order
let firstPriority = MAS_SIZE_PRIORITY.indexOf(first),
secondPriority = MAS_SIZE_PRIORITY.indexOf(second);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no priority among the 2, 9, and 15 sizes, so don't need to sort those. So could simplify the rest to:

       if(firstPriority !== -1) {
          return -1;
       }
       if(secondPriority !== -1) {
          return 1;
       }
      // and finally ascending order
      return first - second;

if(firstPriority > -1 || secondPriority > -1) {
if(firstPriority === -1) {
return 1;
}
if(secondPriority === -1) {
return -1;
}
return firstPriority - secondPriority;
}

// and finally ascending order
return first - second;
});
};

module.exports = RubiconAdapter;
30 changes: 30 additions & 0 deletions test/spec/adapters/rubiconLite_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,36 @@ describe('the rubiconLite adapter', () => {

});

describe('MAS mapping / ordering', () => {

let masSizeOrdering = RubiconAdapter.masSizeOrdering;

it('should not include values without a proper mapping', () => {
// two invalid sizes included: [42, 42], [1, 1]
let ordering = masSizeOrdering([[320, 50], [42, 42], [300, 250], [640, 480], [1, 1], [336, 280]]);

expect(ordering).to.deep.equal([15, 16, 43, 65]);
});

it('should sort values without any MAS priority sizes in regular ascending order', () => {
let ordering = masSizeOrdering([[320, 50], [640, 480], [336, 280], [200, 600]]);

expect(ordering).to.deep.equal([16, 43, 65, 126]);
});

it('should sort MAS priority sizes in the proper order w/ rest ascending', () => {
let ordering = masSizeOrdering([[320, 50], [160,600], [640, 480], [300, 250],[336, 280], [200, 600]]);
expect(ordering).to.deep.equal([15, 9, 16, 43, 65, 126]);

ordering = masSizeOrdering([[320, 50], [300, 250], [160,600], [640, 480],[336, 280], [200, 600], [728, 90]]);
expect(ordering).to.deep.equal([15, 2, 9, 16, 43, 65, 126]);

ordering = masSizeOrdering([[120, 600], [320, 50], [160,600], [640, 480],[336, 280], [200, 600], [728, 90]]);
expect(ordering).to.deep.equal([2, 9, 8, 16, 43, 65, 126]);
})

});

describe('callBids implementation', () => {

let rubiconAdapter;
Expand Down