reddit / emacs

How to record statistics for habits with org-habit?

mklsls · 2022-01-26 20:45
Hi all! I've started using `org-habit` this week. I can set my habits and see the nice colored consistency graph to track visually my habits. However, I would like to have a numeric record of this. For example, something for each habit, I am imagining something like the [statistics cookies](https://orgmode.org/manual/Breaking-Down-Tasks.html): Number of repetitions done / Number of repetitions scheduled Percent of repetitions done % Or even better, have some stats about how many repetitions I have done a habit in a row (similar to "don't break the chain"). I was wondering if it's possible to do it directly with the org-habit module or if something else is necessary. Thanks.
0lMon · 2022-01-26 22:00
Hej Hej, To my knowledge there is nothing build in. I started a while back a small project, it is working but it isn't finished. I created a project in my gitlab if you or someone wants to look at it: https://gitlab.com/OlMon/org-habit-report Cheers, OlMon
mklsls · 2022-01-26 23:33
It looks awesome! How does it work? I downloaded, but I can't load it with `use-package!` in doom. I think you need a `provide` at the end of the file. Also, just as a suggestion, I think you can refactor all the names without the `ol/` prefix. I think it's better for readability reasons. Thanks a lot!
0lMon · 2022-01-27 00:00
As I said it was something I wrote a time ago, I think this was my first attempt at writing elisp. It is not a complete package, so use-package will probably not work. The prefix was when I recall correctly is because I used some org-mode code. Look at the raw README.org file that is in the repo. This shows how to use it. Feel free to pick it up and create a PR, or fork it, or whatever!
vixrduol · 2022-01-27 03:07
I also wonder this, but I haven't been able to find anything. I have resorted to 3rd party resources for now.
OriginalMoment · 2022-01-27 19:45
What I do is I use org-clock and hooks to mostly automate the time tracking, and then I wrote a small python script which parses the data and outputs the results, which runs on startup in a codeblock (org-babel). I can share an example if some parts are confusing
mklsls · 2022-01-27 19:59
Please! It would be extremely helpful to understand your workflow. Thanks.
OriginalMoment · 2022-01-27 21:05
Cool; so, for example, I have this super basic snippet here ``` (defun fc-clock-in () (find-file "\~/Dropbox/todo.org") (condition-case nil (search-forward "TODO Org-fc") (error nil)) (condition-case nil (search-backward "TODO Org-fc") (error nil)) (org-clock-in)) (add-hook 'org-fc-before-review-hook 'fc-clock-in) (add-hook 'org-fc-after-review-hook 'org-clock-out) ``` Probably not the best way to find the "Org-fc" headline, but it works lmao (main problem is `org-clock-in` uses some notion of your cursor to determine what task to clock into, hence me more or less emulating the cursor movevment (afaik)) I have a bunch of little snippets like this to track time spent doing various things, as well as wrappers around certain things if the hooks aren't available. Then I have this in my `todo.org` ``` #+NAME: startup #+BEGIN_SRC emacs-lisp ;; updates the clock table every 5 minutes (defun dblock-update-curried () (org-dblock-update t)) (run-with-timer 0 300 'dblock-update-curried) #+END_SRC # Local Variables: # org-confirm-babel-evaluate: nil # eval: (progn (org-babel-goto-named-src-block "startup") (org-babel-execute-src-block)) # End: ``` Which updates a clocktable for all of my tasks for the day listed in whatever the scope of the clocktable is. I'm definitely new to emacs (around 2 months into switching to spacemacs from a very stripped down vim) so if anyone has any tips / ways to make this better (especially less brittle) I'm all ears The main pain point here is writing little snippets of elisp for anything you want to track; a cleaner, possibly more automated way of doing this would be awesome but right now I'm not aware of anything