0

I have a bunch of timedelta objects.

  • I want to visualize them by showing them as bars on a common linear time axis (think something like Gantt charts).

  • The end product should be an SVG with a defined total width W (so a time axis with width W, and boxes above it, visualizing the timedeltas).

  • The solution should be as precise as possible.

What's the best way to do this?

So far, the best way I've come up with is to

  1. somehow extract an absolute numerical value from all timedelta objects (something like Unix Epoch time maybe)

  2. use the first and last timestamp to define the time range

  3. create a mapping function from the absolute, interpolating the values (something like this)

  4. map the absolute values onto the defined SVG width

  5. create the SVG objects using svgwrite

After googling for a bit, steps 1 and 2 seem problematic - I'm not even sure timedeltas have an absolute numeric value.

Zubo
  • 1,543
  • 2
  • 20
  • 26
  • #1 is answered with `timedelta.total_seconds`. The rest of the question is far too broad. – chepner Oct 08 '19 at 20:12
  • @chepner That would lose all precision beyond seconds, correct? AFAIK, timedeltas can have up to nanosecond precision. – Zubo Oct 08 '19 at 20:31
  • 1
    Microseconds, but yes, you would lose resolution. However, if the number of microseconds is relevant, you can just compute `1000000*(t.days*86400 + t.seconds) + t.microseconds` yourself to get the total duration in microseconds. (The documentation also mentions dividing `td / timedelta(microseconds=1)` for small intervals.) – chepner Oct 08 '19 at 20:35

0 Answers0