Search code examples
phpjquerytimercounter

Counter to increase over day based on target input, random increase


I'm looking for the functionality of the following 'widget': A website needs to display a value for 'number of calls' for example and this data is to represent the number of callers the company has had throughout the day.

However the problem is, there is no system in the company that logs this so data has to be falsified. Almost showing a representation of volumes, based on an overall target average.

The idea is to set a target number (i.e. 247) then over the course of the day (starting at 0) the number increases at intervals, adding a random number to the initial 0 until it reaches the target number at the end of the day. Once it gets to the target number (by 23:59) then at 00:00 the process starts again.

The number needs to be on going, so if a user visits the page they will see a number that is based on the time of day, rather than increase only on page views.

I wondered if anyone had any ideas on a solution for this? It's fairly niche.! I've taken a look at various plugins and script for timers and countdowns, but they don't quite work as required.

I was thinking jQuery, however not sure how this would work in terms of storing the data. I'll take your lead on this!

Many thanks.


Solution

  • function getCallLog()
    {
        $max_calls   = 245;  // SAVE THIS TO DATABASE AND CHANGE FOR EACH DAY. TO BE 100% FALSIFIED ;)
        $total_dayli= 24*60*60;
        $percent    = (date('H') *60 *60 + date('i') *60) / $total_dayli;
        $done       = $max_calls * $percent;        
        return CEIL($done);
    }
    

    All you have to do is change in daily bases the $max_cals variable and will work