0

I'm using org-mode tables to record workouts and would like to calculate the pace I achieve on runs/cycling. I've read the org spreadsheets introduction and found a thread about calculating units but am unsure how to go about doing this.

Currently I have very crudely entered the length of the run/cycle in km and the time as minutes/seconds (min secs) and used a simple formula $6=($5 / $4) in the pace column but the calculation isn't coming out as I'd hoped, I include the column Should Be for reference...

| Date             | Activity | Distance | Time    | Pace                | Should Be      |
|------------------+----------+----------+---------+---------------------+----------------|
| <2020-06-21 Sun> | Run      | 10.75km  | 72m46s  | 6.6976744 m46s / km |  5.50 min/km   |
| <2020-06-19 Fri> | Run      | 6.56km   | 35m26s  | 5.3353659 m26s / km |  5.24 min/km   |
| <2020-06-16 Tue> | Run      | 6.47km   | 34m44s  | 5.2550232 m44s / km |  5.22 min/km   |
| <2020-06-13 Sat> | Run      | 8.03km   | 47m28s  | 5.8530511 m28s / km |  5.55 min/km   |
| <2020-06-11 Thu> | Cycle    | 22.23km  | 85m30s  | 3.8236617 m30s / km |  3.51 min/km   |

The calculating units thread doesn't describe how to handle time and I haven't yet found a method to do this.

Is it feasible? Or should I start considering using timestamps to calculate elapsed time and go from there?

3
  • You could use org-sbe to call a code block, and then handle units and parse strings in your preferred language to generate the new column.
    – mankoff
    Jun 21, 2020 at 19:14
  • The "Should Be" column seems to be wrong though: e.g. 72.75mins for 10.75km is about 6.77 min/km, not 5.50 min/km.
    – NickD
    Jun 21, 2020 at 21:36
  • @NickD Good spot, problem sits between screen and keyboard, it should have been 62min 46s.
    – slackline
    Jun 22, 2020 at 6:37

1 Answer 1

2

It just doesn't like how you've entered the time values. Here's one that works:

| Date             | Activity | Distance | Time              | Pace                | Should Be   |
|------------------+----------+----------+-------------------+---------------------+-------------|
| <2020-06-21 Sun> | Run      | 10.75km  | 72min + 46s       | 6.7689922 min / km  | 5.50 min/km |
| <2020-06-19 Fri> | Run      | 4.08mi   | 35min + 26s       | 8.6846405 min / mi  | 5.24 min/km |
| <2020-06-16 Tue> | Run      | 6.47km   | 34min + 44s       | 5.3683668 min / km  | 5.22 min/km |
| <2020-06-13 Sat> | Run      | 8.03km   | 47min + 28s       | 5.9111665 min / km  | 5.55 min/km |
| <2020-06-11 Thu> | Cycle    | 22.23km  | 1hr + 25min + 30s | 0.064102564 hr / km | 3.51 min/km |
#+TBLFM: $5=usimplify($4)/$3;L

usimplify is a function provided by the emacs calculator for simplifying units; it first does algebraic simplification and then combines compatible units. In this case it's primarily combining the hours, minutes, and seconds into a single value with a single unit. You can see the complete documentation in The GNU Emacs Calculator manual, chapter 11.1. This is also included with Emacs; use C-h i to open the info reader.

The Stack Exchange question/answer that you linked to (Org table: Calculate units provides an additional function that you can define:

(defmath uconvert (v u)
  "Convert value V to compatible unit U."
  (math-convert-units v u))

If you evaluate this in the *scratch* buffer with C-x e you'll be able to convert to any compatible units that you would like, more or less:

| Date             | Activity | Distance | Time              | Pace                          |
|------------------+----------+----------+-------------------+-------------------------------|
| <2020-06-21 Sun> | Run      | 10.75km  | 72min + 46s       | 6 min / km + 46.139535 s / km |
| <2020-06-19 Fri> | Run      | 4.08mi   | 35min + 26s       | 5 min / km + 23.783126 s / km |
| <2020-06-16 Tue> | Run      | 6.47km   | 34min + 44s       | 5 min / km + 22.102009 s / km |
| <2020-06-13 Sat> | Run      | 8.03km   | 47min + 28s       | 5 min / km + 54.669988 s / km |
| <2020-06-11 Thu> | Cycle    | 22.23km  | 1hr + 25min + 30s | 3 min / km + 50.769231 s / km |
#+TBLFM: $5=uconvert($4/$3, (min+s)/km);L

You can see that it converted it to an expression which is not quite what you wanted, but which is algebraically equivalent and is technically simpler. Too bad it's not really easier to read. If you want to keep uconvert around for future use, make sure to add it to your init file.

2
  • Brilliant, thank you. How does usimplify and ;L component work? Is it possible to format output as Xmin + Ys /km?
    – slackline
    Jun 22, 2020 at 6:39
  • Thanks for the update, thats really neat that Emacs can "magically" work out the units using unconvert.
    – slackline
    Jun 23, 2020 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.