org-mode 记录学习时间,用python数据可视化

前言

最近考研,上周末的时候感觉自己效率有所降低,于是改了下自己的学习记录的格式,每天按照格式记录学习时间,并且今天早上利用babel-python画了下饼状图,感觉自己真的有点自我感动的意思在学习里面了。。。

report-w13

我的两个文件

我用于记录自己的学习时间的文件 reviseJournal.org

#+TITLE: My revise journal from 2021-03-27 Sat
#+TAGS: Efficient Inefficient Distracted
#+TAGS: Math CS Engilsh EIE

* Why a new file?
The former revise journal is in a mess. A large amount of stuff were tucked into that file and a pity amount of useful messages could be find. So, It's time to change!

I restrict the context that could be write into this file.
- The "Subject" of this period of time. - With tag name
- "Efficient" or "Inefficient" - With tag name
- "Distraction trace" - With =- tag ::=
- "The Product" - with =- [ ] item=

Other contexts were not allowed!
* 2021

** 2021-W12

*** 2021-03-27 Saturday
**** 15:35 Algorithm                                        :Efficient:CS:
:LOGBOOK:
CLOCK: [2021-03-27 Sat 15:46]--[2021-03-27 Sat 16:55] =>  1:09
:END:
**** 19:15 Mathematics                                    :Efficient:Math:
:LOGBOOK:
CLOCK: [2021-03-27 Sat 19:15]--[2021-03-27 Sat 22:04] =>  2:49
:END:

- [X] Chapter 8 section 2 & 3

*** 2021-03-28 Sunday
**** 09:47 Mathematics                                   :Math:Distracted:
:LOGBOOK:
CLOCK: [2021-03-28 Sun 09:47]--[2021-03-28 Sun 11:35] =>  1:48
:END:

- [X] Chapter 8 -> section 4 and further more.
**** 14:30 Mathematics                                    :Math:Efficient:
:LOGBOOK:
CLOCK: [2021-03-28 Sun 14:32]--[2021-03-28 Sun 15:49] =>  1:17
:END:

- [ ] revise Chapter 3 -> By building a mind map
**** 16:10 Computer Science                                 :CS:Efficient:
:LOGBOOK:
CLOCK: [2021-03-28 Sun 16:10]--[2021-03-28 Sun 17:31] =>  1:21
:END:

- [ ] reviewing former knowledge and start Chapter 5.
**** 19:49 Mathematics                                  :Math:Inefficient:
:LOGBOOK:
CLOCK: [2021-03-28 Sun 19:52]--[2021-03-28 Sun 22:14] =>  2:22
:END:

- [X] Revise Chapter 3 -> Build a mind-map

** 2021-W13

*** 2021-03-29 Monday
**** 10:13 Mathematics                                    :Math:Efficient:
:LOGBOOK:
CLOCK: [2021-03-29 Mon 10:13]--[2021-03-29 Mon 11:40] =>  1:27
:END:
**** 14:52 Mathematics                                  :Inefficient:Math:
:LOGBOOK:
CLOCK: [2021-03-29 Mon 14:52]--[2021-03-29 Mon 16:30] =>  1:38
:END:
**** 16:59 Mathematics                                  :Math:Inefficient:
:LOGBOOK:
CLOCK: [2021-03-29 Mon 16:59]--[2021-03-29 Mon 17:35] =>  0:36
:END:

*** 2021-03-30 Tuesday
**** 15:29 Mathematics                                  :Math:Inefficient:
:LOGBOOK:
CLOCK: [2021-03-30 Tue 15:29]--[2021-03-30 Tue 17:42] =>  2:13
:END:

*** 2021-03-31 Wednesday
**** 15:46 Mathematics                                    :Math:Efficient:
:LOGBOOK:
CLOCK: [2021-03-31 Wed 16:08]--[2021-03-31 Wed 17:34] =>  1:26
:END:
**** 18:17 Mathematics                               :Math:Rush:Efficient:
:LOGBOOK:
CLOCK: [2021-03-31 Wed 18:17]--[2021-03-31 Wed 20:03] =>  1:46
:END:

- [ ] 二元函数的基本概念
**** 20:30 Mathematics                                    :Efficient:Math:
:LOGBOOK:
CLOCK: [2021-03-31 Wed 20:30]--[2021-03-31 Wed 21:08] =>  0:38
:END:
**** 21:22 Mathematics                                   :Math:Distracted:
:LOGBOOK:
CLOCK: [2021-03-31 Wed 21:22]--[2021-03-31 Wed 22:40] =>  1:18
:END:

*** 2021-04-01 Thursday
**** 14:51 Mathematics                                  :Math:Inefficient:
:LOGBOOK:
CLOCK: [2021-04-01 Thu 14:51]--[2021-04-01 Thu 15:24] =>  0:33
:END:

- 07:12:39 PM :: Go for toilet
**** 15:43 Mathematics                                  :Inefficient:Math:
:LOGBOOK:
CLOCK: [2021-04-01 Thu 15:43]--[2021-04-01 Thu 16:17] =>  0:34
:END:

- 07:12:49 PM :: Go for class

我进行数据分析的文件 export-report.org

#+TITLE: Report of my daily
* Math
#+BEGIN: clocktable :maxlevel 4 :scope ("~/Notes/Captures/reviseJournal.org") :indent nil :block thisweek :tags t :match "Math" :level t :header "#+NAME: mathReport\n"
#+NAME: mathReport
| File              |   L | Tags                  | Headline             | Time    |       |      |      |
|-------------------+-----+-----------------------+----------------------+---------+-------+------+------|
|                   | ALL |                       | *Total time*         | *12:09* |       |      |      |
|-------------------+-----+-----------------------+----------------------+---------+-------+------+------|
| reviseJournal.org |     |                       | *File time*          | *12:09* |       |      |      |
|                   |   1 |                       | 2021                 | 12:09   |       |      |      |
|                   |   2 |                       | 2021-W13             |         | 12:09 |      |      |
|                   |   3 |                       | 2021-03-29 Monday    |         |       | 3:41 |      |
|                   |   4 | Math, Efficient       | 10:13 Mathematics    |         |       |      | 1:27 |
|                   |   4 | Inefficient, Math     | 14:52 Mathematics    |         |       |      | 1:38 |
|                   |   4 | Math, Inefficient     | 16:59 Mathematics    |         |       |      | 0:36 |
|                   |   3 |                       | 2021-03-30 Tuesday   |         |       | 2:13 |      |
|                   |   4 | Math, Inefficient     | 15:29 Mathematics    |         |       |      | 2:13 |
|                   |   3 |                       | 2021-03-31 Wednesday |         |       | 5:08 |      |
|                   |   4 | Math, Efficient       | 15:46 Mathematics    |         |       |      | 1:26 |
|                   |   4 | Math, Rush, Efficient | 18:17 Mathematics    |         |       |      | 1:46 |
|                   |   4 | Efficient, Math       | 20:30 Mathematics    |         |       |      | 0:38 |
|                   |   4 | Math, Distracted      | 21:22 Mathematics    |         |       |      | 1:18 |
|                   |   3 |                       | 2021-04-01 Thursday  |         |       | 1:07 |      |
|                   |   4 | Math, Inefficient     | 14:51 Mathematics    |         |       |      | 0:33 |
|                   |   4 | Inefficient, Math     | 15:43 Mathematics    |         |       |      | 0:34 |
#+END: 

#+begin_src python :results file :exports results :tangle export-report.py :var data=mathReport tablename="report-w13"
import matplotlib.pyplot as plt
import datetime as dt
import pandas as pd

# some deifnitions
key = ["Efficient", "Inefficient", "Distracted"]
# key = ["Math", "CS", "English"]
DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
DAYS_Long = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

# Strip surplus stuff.
data = [column for column in data if column[1] == 3 or column[1] == 4]
data = [
    [[i for i in line[2].split(", ") if i in key] # strip other tags
         , line[3].split()[1], line[-1]
     ] for line in data
]

# turn it into list
current_day = -1
day_efforts = {}
for i in key:
    day_efforts[i] = 0
total_efforts = {i:day_efforts.copy() for i in DAYS}
for column in data:
    # column data looks like |(Efficient)|Mathematics|1:27|
    if column[-1] != "":
        current_effort = dt.datetime.strptime(column[-1], "%H:%M")
        current_key = column[0][0] # "Efficient"
        day_in_week = DAYS[current_day]
        total_efforts[day_in_week][current_key] += \
            current_effort.hour + current_effort.minute/60
    else:
        current_day = DAYS_Long.index(column[1])

# plot the table
FinalTime = pd.DataFrame.from_dict(total_efforts)
FT = FinalTime.transpose().reindex(DAYS)

for c in FT.columns:
    dropflag = False
    if sum(FT[c]) == 0:
        FT = FT.drop([c], axis=1)

ax = FT.plot.bar(ylabel="Hours", title=tablename)

filename = tablename + ".png"
plt.savefig(filename)

return(filename)

#+end_src

#+RESULTS:
[[file:report-w13.png]]

tangle 是为了将python代码保存下来,我打算有空用 noweb 代替,但是 not now.

后记

草草分享一下,希望能够帮助到需要的人吧。。。

我参考的对象

7 个赞

小白表示没有看懂,但是感觉很厉害、这bar图是在emacs里直接画的?

对,也不对。

我使用了 org-babel,它直接将org-clock-report的结果作为变量输入给python的代码块,然后python调用图形库绘制的,不是emacs自己的功能,但是也不能说没有用到emacs自己的功能。

你可以了解一下org-babel,因为我的图片主要是用来自己写每周总结的时候用,所以直接在org-mode里面生成会比较方便,至少比我参考的那个小哥的方法(在终端执行脚本,用emacsclient执行命令导出csv,再用python解析csv并且生成图表)要方便一些。。。

1 个赞

我大概知道了,有點像ipython,或者juytper notebook 之類的功能。 反正是炫酷。