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

C

cjt22

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
 
A

A.T.Hofkamp

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
 
M

Marc 'BlackJack' Rintsch

(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
 
C

Carsten Haese

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.
 
C

cjt22

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
 
C

cjt22

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:


but it generates the error


Cheers

Perhaps I need to import the datetime module?
 
D

Dennis Lee Bieber

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

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()
0 15345 0
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
C

cjt22

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


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()


0 15345 0
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address 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!
 
T

Tim Roberts

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:

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.
 
C

cjt22

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.

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top