mcastorina / graph-cli

Flexible command line tool to create graphs from CSV data
783 stars 29 forks source link

Time and Date for x-axis #55

Closed kzehnter closed 2 years ago

kzehnter commented 2 years ago

Hey, what is the best way to have time and date as the x-axis? I can adjust my csv to a format which is well supported. I want the data to be sorted by Date first and then Time. YY-MM-DD HH:MM would be nice but I can't find good examples here.

mcastorina commented 2 years ago

Hi! I think this is the flag you're looking for:

  --time-format-output FORMAT, -F FORMAT
                        display time format (using standard datetime values)

You can view a list of datetime values here. For your example I think that would be %y-%m-%d %H:%M.

The input date format will be guessed at runtime (for each row) which can be quite slow for large CSV files. You can use the --time-format-input flag to specify the format so no guessing will be done, if you like.

kzehnter commented 2 years ago

Thank you first of all, I wasn't sure how to use these flags but now I got that down.

Still with a lot of data like an entry a minute the date and time values overlap and I can't read anything. If I get rid of the date I can see the time well but then the graph gets super weird when the next day starts because it only sorts by time.

I need something that is readable but also works over a couple of days of data.

mcastorina commented 2 years ago

Hm.. here's a few other options to play with:

  --sort, -s            sort xcol values
  --resample FREQ, -r FREQ
                        resample values by FREQ and take the mean (default)
  --xscale SCALE        the x-axis scaling (default: auto)
  --xrange RANGE        the x-axis window (min:max) (default: auto)

xscale and xrange might not work well for time-series graphs though. If you have a sample CSV I can play around with it or possibly improve those options.

kzehnter commented 2 years ago

Okey, I've had time to play around with this again. I solved this by using:

graph --time-format-input "%y-%m-%d %H-%M" --time-format-output "%m:%d"

This way I don't clutter the x-axis but it still sorts data well by date.

Thank you for your help!

axzxc1236 commented 1 year ago

I would like to share my findings about --xrange and --xscale for time data

I want to have a label show up for every 10 minutes, so I use 600/86400 and get 0.0069444..... and use command line argument --xscale 0.0069444..., I successfully make it put a label for every 10 minutes.

--xrange parameter is "number of days since 1970-1-1", yesterday (2023-05-11) is 19488th day, so I use --xrange 19488:19489 and the graph cuts perfectly from 2023-05-11 00:00 to 2023-05-11 23:59 without any padding.

19488.5:19489 makes it graph between 2023-05-11 12:00 and 2023-05-11 23:59

I hope this finding helps someone.

mcastorina commented 1 year ago

@axzxc1236 thanks for sharing that! I wonder if we could have the program do that conversion in a more user friendly way..

axzxc1236 commented 1 year ago

Warning: In some cases datetime string with milliseconds str(datetime.datetime.now()) causes huge memory leak (it keeps ballooning).

Screenshot_20230609_094524