Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Using a time duration to print out data where every 2 seconds is a pixel

Reply
Thread Tools

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

 
 
cjt22@bath.ac.uk
Guest
Posts: n/a
 
      09-10-2007
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

 
Reply With Quote
 
 
 
 
A.T.Hofkamp
Guest
Posts: n/a
 
      09-10-2007
On 2007-09-10, http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      09-10-2007
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
 
Reply With Quote
 
Carsten Haese
Guest
Posts: n/a
 
      09-10-2007
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


 
Reply With Quote
 
cjt22@bath.ac.uk
Guest
Posts: n/a
 
      09-10-2007
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

 
Reply With Quote
 
cjt22@bath.ac.uk
Guest
Posts: n/a
 
      09-10-2007
On Sep 10, 3:57 pm, (E-Mail Removed) 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?

 
Reply With Quote
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      09-10-2007
On Mon, 10 Sep 2007 07:57:58 -0700, (E-Mail Removed) 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
(E-Mail Removed) (E-Mail Removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (E-Mail Removed))
HTTP://www.bestiaria.com/
 
Reply With Quote
 
cjt22@bath.ac.uk
Guest
Posts: n/a
 
      09-11-2007
On Sep 10, 6:39 pm, Dennis Lee Bieber <(E-Mail Removed)> wrote:
> On Mon, 10 Sep 2007 07:57:58 -0700, (E-Mail Removed) 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
> (E-Mail Removed) (E-Mail Removed)
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff: (E-Mail Removed))
> 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!

 
Reply With Quote
 
Tim Roberts
Guest
Posts: n/a
 
      09-11-2007
(E-Mail Removed) 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, (E-Mail Removed)
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
cjt22@bath.ac.uk
Guest
Posts: n/a
 
      09-11-2007
On Sep 11, 8:58 am, Tim Roberts <(E-Mail Removed)> wrote:
> (E-Mail Removed) 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, (E-Mail Removed)
> 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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can Ruby print out time difference (duration) readily? Jian Lin Ruby 4 11-09-2009 03:46 AM
Number of seconds as English duration Phrogz Ruby 0 08-27-2007 06:10 PM
Fuji FinePix S9000 9 Mega Pixel Camera Came Out 17 Mega Pixel? WannabeSomeone Digital Photography 5 11-14-2005 05:09 PM
Sporadic line drops every 20 seconds or so using Cisco 585 LRE twduff@gmail.com Cisco 2 09-25-2005 08:45 PM
1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds Michael Tan Ruby 32 07-21-2005 03:23 PM



Advertisments