Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Count Up Clock with custom increment & variable

  • 03-04-2014 10:58pm
    #1
    Closed Accounts Posts: 2,301 ✭✭✭


    Hi guys,

    So I really don't know where to start with this one. Basically I'd need some sort of count up clock that I could embed on a website.

    For every number, it must increase by 0.000002207 per second.

    I need to be able to change the number at a moments notice.

    For example

    1 = 0.000002207 every second
    2 = 0.000004414 every second
    5000 = 0.02207 every second
    100,000 = 0.4414 every second


    So if I set the value of the number to 100,000 I would have a count up clock on my website which would increase by 0.4414 every second.

    Any Ideas?

    Bare in mind, I'd need to be able to change this number easily and it would update straight away, so maybe a wordpress plugin?

    Thanks,


Comments

  • Closed Accounts Posts: 4,763 ✭✭✭Fenster


    To rephrase your question:

    You have a counter on your site that increments from zero at a /base/ rate of 0.000002207 per second, like so:
    1 sec: 0.000002207
    2 sec: 0.000004414
    3 sec: 0.000006621
    

    The amount it increases is controlled by a separate variable, right?

    So every second:
    var counter    = 0;
    var increment  = 0.000002207;
    var multiplier = 1;
    
    setInterval(function() {
        counter += increment * multiplier;
    }, 1000);
    

    Do you want the change to be retroactive, so if the variable changes, the count is entirely recalculated?
    Do you want this count to be absolute, calculated on the server, and the current increment fetched and displayed by the web browser?
    Or is s the count used in an application in the browser, and doesn't need to be calculated or stored remotely?


  • Closed Accounts Posts: 2,301 ✭✭✭The One Who Knocks


    Fenster wrote: »
    To rephrase your question:

    You have a counter on your site that increments from zero at a /base/ rate of 0.000002207 per second, like so:
    1 sec: 0.000002207
    2 sec: 0.000004414
    3 sec: 0.000006621
    

    The amount it increases is controlled by a separate variable, right?

    So every second:
    var counter    = 0;
    var increment  = 0.000002207;
    var multiplier = 1;
    
    setInterval(function() {
        counter += increment * multiplier;
    }, 1000);
    

    Do you want the change to be retroactive, so if the variable changes, the count is entirely recalculated?
    Do you want this count to be absolute, calculated on the server, and the current increment fetched and displayed by the web browser?
    Or is s the count used in an application in the browser, and doesn't need to be calculated or stored remotely?

    Yes I think that's correct,

    The variable that controls the amount in increases by would always be increasing, so I don't want it to be retroactive, just but to add itself to the last number without resetting.

    For example, let's say the increment is 2 and the variable is 1.
    1 sec: 2
    2 sec: 4
    3 sec: 6
    

    Then I change the variable to 5
    4 sec: 16
    5 sec: 26
    6 sec: 36
    

    So yeah it's multiplying the increment by the variable and adding the value of the last second.

    I think it would need to be absolute too, because I'd just be displaying it on my site. It would work in a similar way to those donation counters you see, for example:

    LHU2U6h.png

    So where do I start?

    Thanks,


  • Closed Accounts Posts: 4,763 ✭✭✭Fenster


    I am still confused by this since you do not word your question in a clear manner.
    var counter    = 0;
    var increment  = 0.000002207;
    var multiplier = 1;
    
    setInterval(function() {
        multiplier += 2;
        counter += increment * multiplier;
    }, 1000);
    

    The incremental amount is constant, but the multiplier increases, meaning the counter increases in a compound manner?


  • Closed Accounts Posts: 2,301 ✭✭✭The One Who Knocks


    Fenster wrote: »
    I am still confused by this since you do not word your question in a clear manner.
    var counter    = 0;
    var increment  = 0.000002207;
    var multiplier = 1;
    
    setInterval(function() {
        multiplier += 2;
        counter += increment * multiplier;
    }, 1000);
    

    The incremental amount is constant, but the multiplier increases, meaning the counter increases in a compound manner?

    Sorry if I'm not being clear, yep you're right, the increment amount is constant but the multiplier can change. I'd have to manually change it, and it would always be higher than the last multiplier. So say it started on 4, then I changed it to 10, then to 50, then to 123 etc.

    The important thing is it adds to the last value of the counter,

    so say it's an increment of 2 and a multiplier of 1

    1 sec = 2 (2x1) (increment x multiplier)
    2 sec = 4 ((2x1) + 2) ((increment x multiplier) + last value of sec)
    3 sec = 6 ((2x1) + 4) ((increment x multiplier) + last value of sec)

    then I manually change the multiplier to 2.

    4 sec = 10 ((2x2) + 6 ) ((increment x multiplier) + last value of sec)
    5 sec = 14 ((2x2) + 10) ((increment x multiplier) + last value of sec)

    Then I just have to find a way to display all of this.

    Does that make sense no?


  • Closed Accounts Posts: 4,763 ✭✭✭Fenster


    It would help if I knew what this counter is for. I'm trying to ken the appearance of an elephant through a secondhand description.


  • Advertisement
  • Closed Accounts Posts: 2,301 ✭✭✭The One Who Knocks


    Fenster wrote: »
    It would help if I knew what this counter is for. I'm trying to ken the appearance of an elephant through a secondhand description.

    Okay fair enough,

    The counter goes up in euro by the increment variable every second, and the multiplier variable is the number of users of a particular app.

    I want to display this as a counter on a website.

    Eg. 20,000 users = €0.04414 every second

    So I'd have a counter that displays in euro and increases by 0.04414 every second.


  • Closed Accounts Posts: 4,763 ✭✭✭Fenster


    Okay fair enough,

    The counter goes up in euro by the increment variable every second, and the multiplier variable is the number of users of a particular app.

    I want to display this as a counter on a website.

    Eg. 20,000 users = €0.04414 every second

    So I'd have a counter that displays in euro and increases by 0.04414 every second.

    This serves as a good pseudocode approximation. Get tally of users every second by however means. I assume the euro count will always increase, but by greater or lesser amounts dependent on the number of users.

    Figure users once per second, use that as multiplier.
    var users = 0;
    var euros = 0;
    var increment = 0.000002207;
    
    serInterval(function() {
        users  = getUserCount();
        euros += increment * users; 
    }, 1000);
    


  • Registered Users, Registered Users 2 Posts: 3,888 ✭✭✭ozmo


    I wouldn't write code that runs on the server and every second increments something by a tiny number like that.
    So many things can go wrong - and when money is involved people can get very upset.

    1) PCs timings can go off - disk defrags, big file copy etc - can all halt your process by a few seconds or more.

    2) Server restart or app crash or upgrade - and you loose all progress while its down- possibly hours.

    Lots and lots of other random reasons.


    Instead - maybe keep a record in a database of exactly each Request to change the multiplier. And write some code which when required will can query the database and work out the current total.
    So foreach(multiplier change) {total += work out the value of while at that multiplier value} + (time since last multiplier change * last multiplier value)

    You could optimise it by storing the current euros value with each change - so you only have to look at the value at the last multiplier change - and calculate to the whatever time it is now.

    But always you are calculating the time by summing the multiples of the value by the difference in time since the last update - not constantly doing lots of little adds.

    That way also you don't need a service constantly running on the server doing the adds every second - just a regular dotnet aspx/php/jsp or whatever webservice.

    Also - use cents? - the smaller the numbers the more likely rounding errors can happen.

    Good luck.

    “Roll it back”



Advertisement