Skip to content

Latest commit

 

History

History
113 lines (93 loc) · 7.51 KB

org-timeline-viewer-from-org-table.org

File metadata and controls

113 lines (93 loc) · 7.51 KB

Org Timeline Viewer from Org Tables

TL;DR

To view the visualization you need Python 3 with python libraries pandas, plotly. You can install those using pip3 install pandas plotly. Then you can evaluate all org-babel blocks doing C-c C-v C-b. Interactive graphic will appear on a browser window.

Insert test events from an Org-table

In this example, we will insert all our data on an org-table and pass it as a variable to pandas. To make the example as simple as possible, we will use the minimal number of columns and use the same names as the export created by org-batch-agenda-csv macro.

Default timestamp dataset

categoryheadtypetodotagsdatetimeextrapriority-lpriority-nagenda-day
timestamp-test1Closed taskpast-scheduledDONEtag22022-3-19Scheduled:10992022-3-19
timestamp-test1Closed tasktimestampDONEtag22022-3-2019:00......10002022-3-20
timestamp-test1Previous deadlinedeadlinetag22022-3-2023:59......Deadline:10002022-3-20
timestamp-test1Awesome event with time blocktimestamp2022-3-2222:00-23:3010002022-3-22
timestamp-test1Demo scheluded date with tagscheduledTODOtag12022-3-22Scheduled:10992022-3-22
timestamp-test1Previous deadlinedeadlinetag22022-3-202 d. ago:10022022-3-22
timestamp-test1Future deadline with timeupcoming-deadlinetag1:tag32022-3-22In 7 d.:9932022-3-22
timestamp-test1Not very future deadline with WAIT keywordupcoming-deadlineWAITtag1:tag32022-3-22In 12 d.:9882022-3-22
timestamp-test1Future scheduled datescheduledtag12022-3-23Scheduled:10992022-3-23
timestamp-test1Future deadline with timedeadlinetag1:tag32022-3-2913:00......Deadline:10002022-3-29
timestamp-test1Not very future deadline with WAIT keyworddeadlineWAITtag1:tag32022-4-313:00......Deadline:10002022-4-3
timestamp-test1Remote future appointmenttimestamptag1:tag42022-4-1510002022-4-15
timestamp-test1Far away scheduled datescheduledTODOtag12022-4-21Scheduled:10992022-4-21

Import Org-tables into pandas

After checking a couple of Stack Overflow articles, it seems quite simple to import a Org-table into pandas passing it as a variable to the pd.DataFrame function.

Given we are not reading using pd.read_csv to read the CSV, we must convert date and agenda-day to dates manually.

import pandas as pd
timeline = pd.DataFrame(tbl[1:], columns=tbl[0])
timeline['date'] = pd.to_datetime(timeline['date'])
timeline['agenda-day'] = pd.to_datetime(timeline['agenda-day'])

Workaround: Org doesn’t export end date, so we rename date as start_date, then add a day for the end_date.

Limitation: Dates must comply with ISO 8601 format. Right now, we can’t add any kind of intervals for times or dates. Pandas will complain and it won’t work.

timeline.set_index('head')
timeline.rename(columns={'head':'heading','category':'orgfile','date':'start_date'}, inplace=True)
timeline['end_date'] = timeline['start_date'] + pd.Timedelta(days=1)
# TODO Debug output to be removed in the future
timeline.head()

Display a cool interactive visualization

We will use python library plotly express to display a timeline that includes all given events. Visualization will open in a browser window.

# From plotly documentation
import plotly.express as px
fig = px.timeline(timeline, x_start = 'start_date', x_end ='end_date' ,y = 'heading',
              title='Org timeline viewer - 10 days',
              hover_data=['heading','start_date'],
              color='type')
fig.update_xaxes(rangeslider_visible=True)
fig.show()
None

Output reference from org-mode 9.5.2 source code

This is the output of org-batch-agenda-csv macro.

The output gives a line for each selected agenda item. Each item is a list of comma-separated values, like this:

category,head,type,todo,tags,date,time,extra,priority-l,priority-n

category The category of the item head The headline, without TODO kwd, TAGS and PRIORITY type The type of the agenda entry, can be todo selected in TODO match tagsmatch selected in tags match diary imported from diary deadline a deadline on given date scheduled scheduled on given date timestamp entry has timestamp on given date closed entry was closed on given date upcoming-deadline warning about deadline past-scheduled forwarded scheduled item block entry has date block including g. date todo The todo keyword, if any tags All tags including inherited ones, separated by colons date The relevant date, like 2007-2-14 time The time, like 15:00-16:50 extra String with extra planning info priority-l The priority letter if any was given priority-n The computed numerical priority agenda-day The day in the agenda where this is listed”

License

This software is licensed under GPLv3 license.