NYCPHP Meetup

NYPHP.org

[nycphp-talk] Bnner Rotation

tedd tedd at sperling.com
Mon Mar 6 19:40:34 EST 2006


>Hello,
>This is a logic issue and may be considered Off-Topic, but since I'm 
>using PHP for this project and I know this list is full of very 
>smart people, there is no better place to ask for help.
>
>I have a page where three *different* banners ads should be 
>displayed. I have a pool of tens of banner ads from which the 3 
>banners should be picked.  Each banner in the pool has a *weight* 
>value which indicates how often a banner should be displayed 
>relatively to other banners within a period of one month  (i.e. a 
>banner with weight = 2 should be displayed twice as often as a 
>banner with weight = 1).
>The set of three banners to be displayed should be rotated every 
>hour (cron job). The amount of impressions is not important.  The 
>banners in the pool and their weight values will be changed manually 
>every month.
>
>Well this is how it should work. However I'm not too sure how to 
>come up with an algorithm that will perform the hourly rotations.
>I usually try to solve all my problems myself, but this time I have 
>2 other deadlines by the end of today, I have a flu and this thing 
>must be ready by Wednesday morning.
>The stress and the sickness screw with my head and I can't come up 
>with any logical solutions.
>
>Any suggestions and help are greatly appreciated!
>Cheers,
>Olaf

Olaf:

I'm not the smart one, but I got looks instead. Let's look at your problem.

A month has a finite value. The number of banners you have is also 
finite. You also have banners that have weight, which mean that they 
appear more often than those with less weight. However, a banner with 
a weight of two really can be thought of as two like-banners.

For example, banner A has a weight of 1 -- banner B has a weight of 2 
-- banner C has a weight of 4 -- banner D has a weight of 3. Now, how 
do you show them?

While you have 4 banners, you can look at it like you have ten banners, namely:

ABBCCCDDD

Now, take all the banners you need to show in one month (ten) and 
divide the month by that value.

The end result is that you have to show each banner for a duration of 
3 days. "A" get 3 days, "B" get 3 days, the next "B" gets 3 days and 
so on. You might want to mix it up, but I wouldn't use a rand 
function, nor chron -- but rather just schedule the banners display 
beforehand. If you need to use rand, then have their banner values in 
an array and remove them from selection as they are used. That way 
you KNOW that each banner has been shown the "agreed" amount of times.

In any event, that's what I would do, your mileage may vary.

tedd
-- 
--------------------------------------------------------------------------------
http://sperling.com



More information about the talk mailing list