Org-Agenda export to Org-Table

3

1

I'm using Org-mode is the log-book for my agricultural field trials and my Phd thesis in general.

Reporting field trials I would like to export the agenda views of trials to org-tables to get something like this as a final product: (Toy data)

| Trial   | Date   (Toy data) | Action                | DAE |
|---------+-------------------+-----------------------+-----|
| Trial A | <2013-02-21 Thu>  | Planting              |     |
| Trial A | <2013-03-03 Sun>  | Emergence             |  0  |
| Trial A | <2013-04-19 Fri>  | Fungicide Application |  7  |
| Trial A | <2013-05-20 Mon>  | Biomass Evaluation    |  50 |
| Trial A | <2013-06-21 Fri>  | Harvest               | 110 |
| Trial B | ...               | ...                   |     |
| ...     | ...               | ...                   |     |

From the C-a m (TAG search) I can get something like this here (real data):

  13pgSoja:   13pgSoja: Planting: Soybean <2012-11-06 Tue>        :NPW:2013:PG::
  13pgSoja:   13pgSoja: Emergence <2012-11-14 Thu>                :NPW:2013:PG::
  13pgSoja:   13pgSoja: Application 1 <2012-11-22 Thu 14:30-16:30> :NPW:2013:PG::
  13pgSoja:   13pgSoja: Evaluation: Control 1 <2012-11-28 Wed>    :NPW:2013:PG::
  13pgSoja:   13pgSoja: Evaluation: Biomass Weeds <2013-02-18 Mon> :NPW:2013:PG::
  13pgSoja:   13pgSoja: Evaluation: Biomass Soybean               :NPW:2013:PG::
  13pgSoja:   13pgSoja: Harvest <2013-03-25 Mon>                  :NPW:2013:PG::

Editing away unnecessary tags is not a problem, I get: (I added the header for the three first columns just to make clear my idea...)

Trial        Action                Date     
  13pgSoja: Planting: Soybean <2012-11-06 Tue>        
  13pgSoja: Emergence <2012-11-14 Thu>                
  13pgSoja: Application 1 <2012-11-22 Thu 14:30-16:30> 
  13pgSoja: Evaluation: Control 1 <2012-11-28 Wed>    
  13pgSoja: Evaluation: Biomass Weeds <2013-02-18 Mon> 
  13pgSoja: Evaluation: Biomass Soybean               
  13pgSoja: Harvest <2013-03-25 Mon>                  

Then converting this format to an org-table:

| Trial     | Action                      | Date             | DAE |
| 13pgSoja: | Planting: Soybean           | <2012-11-06 Tue> |     |
| 13pgSoja: | Emergence                   | <2012-11-14 Thu> |   0 |
| 13pgSoja: | Application 1               | <2012-11-22 Thu> |     |
| 13pgSoja: | Evaluation: Control 1       | <2012-11-28 Wed> |     |
| 13pgSoja: | Evaluation: Biomass Weeds   | <2013-02-18 Mon> |     |
| 13pgSoja: | Evaluation: Biomass Soybean | <2013-02-18 Mon> |     |
| 13pgSoja: | Harvest                     | <2013-03-25 Mon> | 130 |

The DAE stands for "Days after emergence". I would like to be able to calculate the "crop age" from the dates and sorting by date. Is the format from the agenda any good for calculations? This is actually an additional question...

Converting data to a table is a problem (converting without header, that I would add later). I would have to do the seperations all manually. Is there any easy way to export the agenda view into an org-table form? Is column view of org-agenda the right path?

mcg

Posted 2014-04-25T17:38:24.663

Reputation: 41

It's hard to see how the the tags you have relate to the table. I see data in the table that I don't see in the tags. Would you be able to provide small portion of data, and a equivalent table? – Alex McKenzie – 2014-04-25T19:09:30.223

Here you go Alex; added some more data and desired output table – mcg – 2014-04-25T20:57:48.527

Don't really see the required transformation, but awk is your friend (along with cut). By default, awk reads each line of an input file, splits it into fields using the delimiters or fixed length fields of your choice and then matches each line against successive patterns (that you specify). When a pattern matches, then the action associated with that pattern is invoked. It's perfect for restructuring and cleaning data. – Joe – 2014-05-06T06:13:57.347

Answers

1

I actually found a solution to my problem on the org-mode help pages. The links are http://orgmode.org/manual/Scope-of-column-definitions.html and http://orgmode.org/manual/Capturing-column-view.html.

Org column view as such is not exportable, but can be captured using dynamic blocks:

Example data:

* Trial A

** Planting
<2014-02-28 Fri>
** Emergence
<2014-03-10 Mon>
** Biomass evaluation
<2014-04-29 Tue>
** Harvest
<2014-05-28 Wed>

I wanted the item itself (%25ITEM) and the date (%TIMESTAMP) exported, so I set:

#+COLUMNS: %25ITEM %TIMESTAMP

Then one goes to the top header (Trial A) and uses: 

C-c C-x i  --- (org-insert-columns-dblock) ; I get


#+BEGIN: columnview :hlines 1 :id local
| ITEM                  | TIMESTAMP      |   |
|-----------------------+----------------+---|
| * Trial A             |                |   |
| ** Planting           | 2014-02-28 Fri |   |
| ** Emergence          | 2014-03-10 Mon |   |
| ** Biomass evaluation | 2014-04-29 Tue |   |
| ** Harvest            | 2014-05-28 Wed |   |
#+END:

(I added a third column) This I can easily be changed to the output I wanted (eliminating stars + changing headers). Adding a third column I can do the date calculations I want as well, with :

#+TBLFM: $3 = date(<$2>) - date(<2012-10-21>)

mcg

Posted 2014-04-25T17:38:24.663

Reputation: 41