2 Replies Latest reply on Jul 31, 2011 11:39 PM by Manystems-Arjen

    Realtime chart, any tips?

    Manystems-Arjen Level 1



      I'm working on a chart which needs to update itself but i'm not sure how to build it.

      The application receives a list of task objects (a lot say 1000).

      Every object contains a time on which the task should be done.


      I need to send a event as soon as a the current time is higher as the task end time minus a user configured amount of hours.

      So lets say the end time is 18:00 the user configures the amount of hours to 4 so when the end time of the task is higher then 14:00 an event should be sent.


      The amount of hours is not fixed the user can change this.


      When the task end time is higher then the configured time it should move from one view to another.


      So my solution for now is to loop every second over all tasks to do the check.


      Does anyone have a tip to do this more efficient?

      I was thinking on adding a timer in each task object so each task can sent its own event.

      But i'm not sure if this will improve my performance since there  can be over 1000 tasks.

        • 1. Re: Realtime chart, any tips?
          UbuntuPenguin Level 4

          >There can be thousands of tasks...So my solution for now is to loop every second over all tasks to do the check.


          No.  You just made a Wanted Dead Or Alive poster of a man named Application Performance...with Alive crossed out.


          You know that the tasks can be arranged so that time task( x ) is due comes before the tmie tasks( x + 1 ) is due (montonically increasing).  You can use this by ordering the tasks by the time they are due and sorting them into an array.  Then, you only check the first task ( taskArray[0] ) to see if it is due, if it is, you pop it off the array and handle your past due logic. This should change the time complexity of your application to O(1) when considering the dependency on the number of task as opposed to the O( MFG  ) you are rocking right now.


          I'm not sure about how the timer should be implemented.  I am a little wary about the amount of bookkeeping you have to do.  What happens when a new task is added (You have to resort your task array and reset the timer for the new first task), what about when a task time is changed, how do you go about resetting your timer, what if that task expires while the user is in the task time change UI ?


          If this answer was helpful please mark it as such.

          1 person found this helpful
          • 2. Re: Realtime chart, any tips?
            Manystems-Arjen Level 1

            Thanks for the tip, this sounds a lot better the the looping indeed:)

            I'll give it a try with the sorting.