メモ置き場

メモ置き場です.開発したものや調べたことについて書きます.

[tex: ]

修論の進捗をグラフにしてみた

今月の頭に修論を提出した.
修論を何ページくらい書いたかグラフにすると面白くてやる気が出るかな〜と思い,コードを作って遊んでみた.


修論はgitで管理をしていたので,コミットごとにpdfファイルのページ数とコミット日時を取得しプロットする.コードはpythonで書いた.コードを使うには

  • gitで管理していること
  • pdfもgitで管理されていること
  • OS Xで動作させること(pdfinfoコマンドみたいなのが使えればなんでもいいと思う)
  • python3を使うこと

を満たす必要がある.コードの見た目にも目をつぶる必要もある.

import sys
import os
import subprocess
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import pandas as pd

def get_stdout(cmd):
      return subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).stdout.readlines()

#gitのコミット一覧を取得し,sha1とコミット日付をresultに入れる
git_command = 'git log --reverse '
git_command += "--date=format:'%Y/%m/%d %H:%M:%S'"
git_command += ' --format="%H,%cd"'
result = get_stdout(git_command)

commit_num = 1
pages = []
commits = []
dates = []
for l in result:
    log = l.decode("UTF-8")
    tmp = str(log).split(",")
    sha1 = tmp[0]
    date = tmp[1].strip()
    cmd = 'git checkout '
    cmd += '"%s"' %(sha1)
    cmd += ' >& /dev/null'
    os.system(cmd)
    page = 0
    #pdfinfoを使ってpdfのページ数を調べる
    if(os.path.exists("./my_mron.pdf")):
        pdf_cmd = 'pdfinfo my_mron.pdf | grep Pages'
        ret = get_stdout(pdf_cmd)
        tmp = str(ret[0].decode("UTF-8")).split(":")
        page = int(tmp[1].strip())

    pages.append(page)
    commits.append(commit_num)
    dates.append(date)

    commit_num += 1

#master branchへ戻しておく
os.system("git checkout master >& /dev/null")

#plotする
fig, ax = plt.subplots()
ax.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d'))
ax.xaxis.set_major_locator(mdates.AutoDateLocator(maxticks=4))
x = pd.to_datetime(dates)
plt.plot(x, pages)
plt.xlabel("Date")
plt.ylabel("Pages")
plt.show()

修論の進捗具合はこんな感じになった.最終的に90ページくらいかな.
f:id:okchan08:20190108230329p:plain

こうして遊んでいるうちに修論ができたのでした.めでたしめでたし*1

*1:ただし楽しいお正月については考えないものとする