結城タスクのログの研究
結城タスクには、プロジェクトにtouchした日をグラフで表示する機能がある。 コマンドの流れ
mkコマンド→touch_taskコマンド→update_graphコマンド
関連しそうなファイル
log.json - (自動更新)touch_taskコマンドで実行履歴を保存するファイル
graph.html - (自動更新)log.jsonをグラフとして可視化したファイル。update_graphコマンドで更新される。
graph-recent.html - (自動更新)graph.htmlを最近10日間だけに制限したファイル。update_graphコマンドで更新される。
code:touch_task.rb
require 'json'
JSON_FILENAME = "~/yukitask/log.json"
date = Time.now.strftime("%Y-%m-%d")
pwd = Dir.getwd
hash = { 'pwd' => pwd, 'date' => date }
ar = []
File::open(File.expand_path(JSON_FILENAME)) do |file|
ar = JSON.load(file)
ar << hash
end
File::open(File.expand_path(JSON_FILENAME), "w") do |file|
file.puts(JSON.pretty_generate(ar))
end
system("update_graph")
# vim: set filetype=ruby:
現在時刻と現在ディレクトリ名(=プロジェクト名)を取得して、ハッシュ(辞書)に保存。
arにログを保存したファイルからjsonを読み込む
arに、先ほど作成したハッシュを追加
arをログファイルに書き込む
update_graphを呼び出す
つまり、ログとして残されるデータは
作業ディレクトリ名(プロジェクト名)
その時刻
の二つ。そのデータを元にグラフが描画される。
ちなみに、mkコマンドは、touch_taskとmakeを行っているだけ。