Control daily image views

Asked

Viewed 35 times

3

I don’t want the script ready, just know the best strategy.

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

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

How to make:

  • All banners were seen the same amount of times;
  • Only repeat a banner after all others have been shown;
  • Do not use random views

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

The question is how to make it work!!!! Will q is better to do via cookie, via BD script, which is the best way?

  • Not using "random views" means that banners should appear in a specific order?

1 answer

0

[How to make it] All banners were seen 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 "banner views should be evenly distributed".

To solve this, you basically create a temporary table that stores the daily views of each banner. Then you increment, in this temporary table, a counter to each request of this image. In the next banner request, you take the one with the least views. This ensures balance in the 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 on 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 engine that disables expired banners, you can program a script to run every day at midnight on the server (cron on Linux, Task Scheduler on Windows, or an event in the database itself). It will do the following on each of the banner table rows that are active:

  1. Be it data_final the date of inicio plus the value of dias;
  2. If data_final is older than the current date, disables the banner (active=0).

Also, for the distribution mechanism, do the following in the same daily script:

  1. Remove all records on views_banner;
  2. Enter all active banner ids in views_banner with the column hoje=0 (this column represents the views the banner had on the day).

Upon receiving a request on http://site.com/banner_rotativo, do the following with server-side technology of your preference:

  1. Select any record that has the lowest value in the column hoje (lack rule to solve ties);
  2. Increment the value hoje of that record;
  3. Return the image for this banner.
  • Is there any way to update the value of days original record when doing select? Something like select id, link, dias = dias - 1 from banners, but that this decrease in days was stored in the bank.

  • With SELECT is not possible as this statement is to recover data, not to change it. Use UPDATE to decrease. But in the logic of my answer, you should not decrease the column dias. Just add the days to the start date to see if it is still valid.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.