Control daily image views [closed]

3
  

I do not want the script ready, just know the best strategy.

Personally, I'm having a hard time figuring out how best to control the amount of daily views of a banner.

For example: I have a BD with 500 banners (name, link, image, days that will appear) but on each page of the site they only show 7 banners at a time.

How to do it:

  • All banners were viewed the same amount of times;
  • Just repeat one banner after all others have been shown;
  • Do not use random views

Each banner will appear a certain amount of days and then be erased.

The question is how to make it work !!!! Is it better to do via cookie, via script in DB, what is the best way?

    
asked by anonymous 03.02.2017 / 02:16

1 answer

0
  

[How to do that] All banners were viewed the same amount of times;

This would only be possible if there were a number of banner views multiple of the total number of banners, which is not practical in reality. I'm interpreting this as "banners views should be evenly distributed."

To solve this, basically you create a temporary table that stores the daily views of each banner. Then you increment in this temporary table a counter for each request of that image. At the next banner request, you get the least views. This ensures balance in distribution.

To remove expired banners, check at the beginning of each day if it is still valid.

Detailing a little more:

You can leave your structure in the DB more or less like this:

banner

| id | nome | link | imagem |     inicio | dias | ativo |
|----+------+------+--------+------------+------+-------|
|  0 | ...  | ...  | ...    | 2017-01-28 |   10 |     1 |
|  1 | ...  | ...  | ...    | 2017-01-31 |    3 |     0 |
|  2 | ...  | ...  | ...    | 2017-02-02 |   20 |     1 |


views_banner

| id | hoje |
|----+------|
|  0 |    3 |
|  2 |    2 |

For the mechanism that disables expired banners, you can schedule a script to run every day at midnight on the server (cron on Linux, Windows Task Scheduler, or an event in the database itself). It will do the following on each of the banner table lines that are active:

  • Be data_final the date of inicio plus the value of dias ;
  • If data_final is older than the current date, disable the banner (active = 0).
  • In addition, for the distribution engine, do the following in the same daily script:

  • Remove all records in views_banner ;
  • Enter all active banner ids in views_banner with column hoje=0 (this column represents the views the banner had on the day).
  • When you receive a request on link , do the following with the server-side technology of your choice:

  • Select any record that has the lowest value in the hoje column (there is no rule to resolve draws);
  • Increase the value hoje of this record;
  • Return the image for this banner.
  • 03.02.2017 / 04:06