I have a system that displays entries sorted by one of the three fields most popular today, this week, and this month. Each time a record is viewed, the score is increased by 1, changing the order.
So, if record 1 is new and is reviewed 10 times today, its ratings will be:
Today: 10 Week: 10 Month: 10
Current solution
Currently, I have only 3 fields associated with each entry, one for today is another this week and the other for this month. Each time a record is viewed, all three points are increased by 1.
At the end of the day, the dayβs score is reset to 0. At the end of the current week, the week indicator is 0 and at the end of the current month of the calendar, the month is set to 0.
Problem
Although this works and uses little space, it is not ideal for two reasons:
1) At the end of the current period (day, week, month) this value reset to 0 all at once means that at 00:00:00 every day the rating is all reset and everything is set to 0 daily for points, the same is true for the end week and end of month. At 00:00:00 on the 1st day of every month, all points are set to 0, losing all existing ranking data.
2) Since the end of the month usually falls within a week (Mon-Sun), monthly reset points during the week result in weekly points exceeding the monthly points.
Possible Solution
I could use a moving hourly counter for each hour of the month, which is used to calculate points for the current day, week, month based on the current hour indicator.
Array size = 31 * 24 = 744 int16 values
So, on the 1st at 4 a.m. the performance will be placed in the clock [4]
hours[4]++
Then, the statistics calculator will be used today as the sum of the last 24 values, and This Week's score will be equal to the sum of the last (24 * 7) values. Finally, this month would be the sum of the last (24 * 31) values.
Problem Solving
The main problem with solution 1 is the disk / memory requirements. I switched from using 3 32-bit values ββin my current solution to using 744 32-bit values. Even if I change them to 16, I'm still going to use a lot more memory per record
Memory per Entry = 3 * 4 bytes = 12 bytes (Existing) Memory per Entry = 744 * 2 = 1,488 bytes (possible solution)
With this solution, my memory usage for each record jumped 12400%!
Can someone suggest another solution that will satisfy the problems in my current solution, but without using 1.5 k per record?
Many thanks!