Using a time duration to print out data where every 2 seconds is a pixel

Discussion in 'Python' started by cjt22@bath.ac.uk, Sep 10, 2007.

  1. Guest

    Hi there, I wonder if any of you could tell me the best way to going
    about solving this little problem!

    I have a list of Step objects containing their start and finish times
    The steps are sorted so that they are in order of their step times
    The start and finish times are in string format of "%H:%S:%M" all on
    the same day

    I want to be able print out the Steps as a visual representation so
    that I can show
    1. The order the steps started
    2. The duration of the steps

    i.e. a print out such as:


    [ a ]
    [ b ]
    [ c ]

    so:
    [ stepName ] is the duration of the Step (i.e. 1 pixel for every 2
    seconds it lasted)
    [ a ] started first so it is printed first, [ b ] started x seconds
    later so it is printed y pixels tabbed away form the side etc etc

    Any help would be much appreciated.

    Another related question is that I can't seem to do arithmetic when
    the variables are in String format
    of %H:%M:%S or converted to type struct_time

    i.e.
    > startPoint = strptime(step.sTime, "%H:%S:%M")
    > finishPoint = strptime(step.fTime, "%H:%S:%M")
    > duration = finishPoint - startPoint


    generates a error:
    Type error: unsupport operand types for: 'time.struct_time' and
    'time.struct_time'

    trying to do time arithmetic when the times are stored in this format
    as strings also fails so any help regarding any of this would be muhc
    appreciated
     
    , Sep 10, 2007
    #1
    1. Advertising

  2. A.T.Hofkamp Guest

    On 2007-09-10, <> wrote:
    > I want to be able print out the Steps as a visual representation so
    > that I can show
    > 1. The order the steps started
    > 2. The duration of the steps
    >
    > i.e. a print out such as:
    >
    >
    > [ a ]
    > [ b ]
    > [ c ]


    This graph is commonly known as a Gantt Chart.
    The most common use case of such charts is project planning.

    The newest GNU plot program has support for these charts afaik.

    > Another related question is that I can't seem to do arithmetic when
    > the variables are in String format
    > of %H:%M:%S or converted to type struct_time


    True (but you already detected that).

    Either convert your struct_times to floats (time.mktime), or use a date/time
    module specialized in computing with dates and times.

    (I have seen references to a module called datetime, but I have never used such
    a module so no idea what it is or where to get it).


    Sincerely,
    Albert
     
    A.T.Hofkamp, Sep 10, 2007
    #2
    1. Advertising

  3. Re: Using a time duration to print out data where every 2 secondsis a pixel

    On Mon, 10 Sep 2007 15:48:44 +0200, A.T.Hofkamp wrote:

    > (I have seen references to a module called datetime, but I have never used such
    > a module so no idea what it is or where to get it).


    It's just an import away -- in the standard library. :)

    Ciao,
    Marc 'BlackJack' Rintsch
     
    Marc 'BlackJack' Rintsch, Sep 10, 2007
    #3
  4. Re: Using a time duration to print out data where every 2 secondsis a pixel

    On Mon, 2007-09-10 at 15:48 +0200, A.T.Hofkamp wrote:
    > I have seen references to a module called datetime, but I have never used such
    > module so no idea what it is or where to get it.


    You get it by using a non-ancient version of Python. It's been part of
    the standard library since Python 2.3.

    --
    Carsten Haese
    http://informixdb.sourceforge.net
     
    Carsten Haese, Sep 10, 2007
    #4
  5. Guest

    Thanks however I am still having a problem using the time module for
    arithmetic

    My string times are of values such as 09:55:17

    and I have code such as:

    >from time import *
    >startPoint = strptime(step.sTime, "%H:%S:%M")
    >finishPoint = strptime(step.fTime, "%H:%S:%M")


    >duration = mktime(startPoint) - mktime(finishPoint)


    but it generates the error

    >OverflowError: mktime argument out of range


    Cheers
     
    , Sep 10, 2007
    #5
  6. Guest

    On Sep 10, 3:57 pm, wrote:
    > Thanks however I am still having a problem using the time module for
    > arithmetic
    >
    > My string times are of values such as 09:55:17
    >
    > and I have code such as:
    >
    > >from time import *
    > >startPoint = strptime(step.sTime, "%H:%S:%M")
    > >finishPoint = strptime(step.fTime, "%H:%S:%M")
    > >duration = mktime(startPoint) - mktime(finishPoint)

    >
    > but it generates the error
    >
    > >OverflowError: mktime argument out of range

    >
    > Cheers


    Perhaps I need to import the datetime module?
     
    , Sep 10, 2007
    #6
  7. On Mon, 10 Sep 2007 07:57:58 -0700, declaimed the
    following in comp.lang.python:

    > >from time import *
    > >startPoint = strptime(step.sTime, "%H:%S:%M")
    > >finishPoint = strptime(step.fTime, "%H:%S:%M")

    >
    > >duration = mktime(startPoint) - mktime(finishPoint)

    >

    Ignoring the mktime() error, shouldn't those be reversed -- end
    times are larger than start times...

    > but it generates the error
    >
    > >OverflowError: mktime argument out of range

    >


    I suspect you will need to supply a full date... mktime() wants
    calendar date/time values, not some HMS value that is relative to an
    arbitrary zero. That is, if your data is in the form "9h 5m, 20s from
    start of effort" you need to supply a dummy day representing "start of
    effort" (midnight probably)

    Maybe look at the documentation for the datetime module -- in
    particular timedelta()

    >>> from datetime import timedelta
    >>> pStart = timedelta(hours=9, minutes=5, seconds=20)
    >>> pEnd = timedelta(hours=13, minutes=21, seconds=5)
    >>> dur = pEnd - pStart
    >>> print dur.days, dur.seconds, dur.microseconds

    0 15345 0
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
     
    Dennis Lee Bieber, Sep 10, 2007
    #7
  8. Guest

    On Sep 10, 6:39 pm, Dennis Lee Bieber <> wrote:
    > On Mon, 10 Sep 2007 07:57:58 -0700, declaimed the
    > following in comp.lang.python:
    >
    > > >from time import *
    > > >startPoint = strptime(step.sTime, "%H:%S:%M")
    > > >finishPoint = strptime(step.fTime, "%H:%S:%M")

    >
    > > >duration = mktime(startPoint) - mktime(finishPoint)

    >
    > Ignoring the mktime() error, shouldn't those be reversed -- end
    > times are larger than start times...
    >
    > > but it generates the error

    >
    > > >OverflowError: mktime argument out of range

    >
    > I suspect you will need to supply a full date... mktime() wants
    > calendar date/time values, not some HMS value that is relative to an
    > arbitrary zero. That is, if your data is in the form "9h 5m, 20s from
    > start of effort" you need to supply a dummy day representing "start of
    > effort" (midnight probably)
    >
    > Maybe look at the documentation for the datetime module -- in
    > particular timedelta()
    >
    > >>> from datetime import timedelta
    > >>> pStart = timedelta(hours=9, minutes=5, seconds=20)
    > >>> pEnd = timedelta(hours=13, minutes=21, seconds=5)
    > >>> dur = pEnd - pStart
    > >>> print dur.days, dur.seconds, dur.microseconds

    >
    > 0 15345 0
    > --
    > Wulfraed Dennis Lee Bieber KD6MOG
    >
    > HTTP://wlfraed.home.netcom.com/
    > (Bestiaria Support Staff: )
    > HTTP://www.bestiaria.com/


    Thanks for all the help, I will have a look at my errors today.

    Can I also ask does anyone know how I could plot the "gannt chart"
    looking representation of my data without having to install something
    such as gnu plot. i.e. how would I simply work out how to move a space
    accross the screen every 2 seconds, if a Step lasted 45 seconds for
    example how would I represent that in terms of a print out with
    spaces?

    I hope that makes sense!
     
    , Sep 11, 2007
    #8
  9. Tim Roberts Guest

    wrote:

    >Thanks however I am still having a problem using the time module for
    >arithmetic
    >
    >My string times are of values such as 09:55:17
    >
    >and I have code such as:
    >
    >>from time import *
    >>startPoint = strptime(step.sTime, "%H:%S:%M")
    >>finishPoint = strptime(step.fTime, "%H:%S:%M")


    Your conversion strings cannot be correct. Sure, there are international
    differences in rendering dates and times, but not even in Eastern
    WhereTheHeckIsStan do they encode hours, then seconds, then minutes.
    --
    Tim Roberts,
    Providenza & Boekelheide, Inc.
     
    Tim Roberts, Sep 11, 2007
    #9
  10. Guest

    On Sep 11, 8:58 am, Tim Roberts <> wrote:
    > wrote:
    > >Thanks however I am still having a problem using the time module for
    > >arithmetic

    >
    > >My string times are of values such as 09:55:17

    >
    > >and I have code such as:

    >
    > >>from time import *
    > >>startPoint = strptime(step.sTime, "%H:%S:%M")
    > >>finishPoint = strptime(step.fTime, "%H:%S:%M")

    >
    > Your conversion strings cannot be correct. Sure, there are international
    > differences in rendering dates and times, but not even in Eastern
    > WhereTheHeckIsStan do they encode hours, then seconds, then minutes.
    > --
    > Tim Roberts,
    > Providenza & Boekelheide, Inc.


    Sorry I meant %H:%M:%S just wrote it wrong! Any advice on how to print
    out the duration though would be much appreciated.
    I think I have now got the time conversion problems sorted thanks to
    the help from google groups!
     
    , Sep 11, 2007
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SXJ3YW5zeWFo?=
    Replies:
    4
    Views:
    2,495
    =?Utf-8?B?SXJ3YW5zeWFo?=
    Oct 30, 2007
  2. André Wagner

    Fastest pixel by pixel operation

    André Wagner, Mar 17, 2008, in forum: Java
    Replies:
    12
    Views:
    1,081
    Larry A Barowski
    Mar 19, 2008
  3. Michael Tan
    Replies:
    32
    Views:
    1,066
    Ara.T.Howard
    Jul 21, 2005
  4. Phrogz
    Replies:
    0
    Views:
    170
    Phrogz
    Aug 27, 2007
  5. Jian Lin
    Replies:
    4
    Views:
    194
    Phrogz
    Nov 9, 2009
Loading...

Share This Page