ダイエット記録更新
はてなダイアリの書き方をhatena-modeからsimple-hatena-mode/はてダラに変更したので、両方の形式から体重、体脂肪を抽出してグラフ用のCSVを作成するscriptを書き直した。
ファイル中に XX kg YY %の数字XXを体重、YYを体脂肪率とします。
使い方
diet.shを実行し、gnuplotでweight.gpを読ませる
diet.sh
diet.shはhatena.csvを作成する。
gnuplot weight.gp
weight.gpはhatena.csvから体重のグラフを書く
diet.plはdiet.shから呼ばれる
diet.sh
#!/bin/bash # # translate hatena diary file to weight log # Time-stamp: <2008-10-13 23:11:24 fu7mu4> # this script needs convert script diet.pl OLDHATENADIARY="$HOME/.hatena" NEWHATENADIARY="$HOME/.hatena/fu7mu4/diary" WeightLog="$HOME/weight.log" # orignal data EucCodingCSV="$HOME/eucjp.csv" # date with euc-jp coding SJISCodingCSV="$HOME/hatena.csv" # date with sjis coding for hatena #GPDAT="$HOME/raw.dat" # date for GNUPLOT # make oroginal data from hatena-mode diary dir cd $OLDHATENADIARY || exit 1 grep ' kg ' ???????? > $WeightLog cd $HOME # make oroginal data from simple-hatena-mode diary dir cd $NEWHATENADIARY || exit 2 grep ' kg ' ????-??-??.txt >> $WeightLog cd $HOME # convert original data for hatena format diet.pl < $WeightLog > $EucCodingCSV nkf -s $EucCodingCSV > $SJISCodingCSV # convert to GNUPLOT format #grep -v '^,' $SJISCodingCSV > $GPDAT
diet.pl
#!/usr/bin/perl # -*- coding:euc-jp -*- # Time-stamp: <2009-04-11 20:12:26 fu7mu4> # convert hatena-diary to weight log csv # * V3 # + be able to read simple-hatena-mode-weight-log files # diet.pl < hatena-daiary-weight-log-file > euc-jp.csv # writing headder of CSV in English to use file widely print "Date,Weight,Rate,FatWeight\n"; while(<>){ chomp; @dat=split(/[:\/ ]/); # get dates,weight,rate from hatena diary format $dates=$dat[0]; #weight with format (20080102) year+month+day $weight=$dat[2]; #body weight $rate=$dat[4]; #fat-rate (percentage) # fixing values if their are not collect. if( $weight !~ /\d+\.?\d*/){ $weight = 0.0; } if( $rate !~ /\d+\.?\d+/){ $rate = 0.0; } # if( $dates !~ /\d{8}/){ # $dates="00000000"; # } # convert dates to year, month, day # print "dates:$dates\n"; if( $dates =~ /(\d\d\d\d)(\d\d)(\d\d)/){ ($year,$month,$day) = ( $dates =~ /(\d\d\d\d)(\d\d)(\d\d)/); } if( $dates =~ /(\d\d\d\d)-(\d\d)-(\d\d)/){ ($year,$month,$day) = ( $dates =~ /(\d\d\d\d)-(\d\d)-(\d\d)/); } # get fat-weight from weight and fat-rate $fat=$weight*$rate/100.0; if( $weight > 0.0 & $rate > 0.0 & $year > 2000 ){ print $year."/".$month."/".$day.",".$weight.",".$rate.",".$fat."\n"; } }
weight.gp
GNUTERMはMac OS XでAquaTermを使うからAquaになっている
LinuxならX11になる。
#!/opt/local/bin/gnuplot # # # G N U P L O T # Version 4.2 patchlevel 5 # last modified Mar 2009 # System: Darwin 9.8.0 # # Copyright (C) 1986 - 1993, 1998, 2004, 2007 - 2009 # Thomas Williams, Colin Kelley and many others # # Type `help` to access the on-line reference manual. # The gnuplot FAQ is available from http://www.gnuplot.info/faq/ # # Send bug reports and suggestions to <http://sourceforge.net/projects/gnuplot> # # set terminal aqua 0 title "Figure 0" size 846 594 font "Times-Roman,14" noenhanced solid # set output unset clip points set clip one unset clip two set bar 1.000000 set border 31 front linetype -1 linewidth 1.000 set xdata time set ydata set zdata set x2data set y2data set timefmt x "%Y/%m/%d" set timefmt y "%Y/%m/%d" set timefmt z "%Y/%m/%d" set timefmt x2 "%Y/%m/%d" set timefmt y2 "%Y/%m/%d" set timefmt cb "%Y/%m/%d" set boxwidth set style fill empty border set style rectangle back fc lt -3 fillstyle solid 1.00 border -1 set dummy x,y set format x "% g" set format y "% g" set format x2 "% g" set format y2 "% g" set format z "% g" set format cb "% g" set angles radians unset grid set key title "" set key inside right top vertical Right noreverse enhanced autotitles nobox set key noinvert samplen 4 spacing 1 width 0 height 0 unset label unset arrow set style increment default unset style line unset style arrow set style histogram clustered gap 2 title offset character 0, 0, 0 unset logscale set offsets 0, 0, 0, 0 set pointsize 1 set encoding default unset polar unset parametric unset decimalsign set view 60, 30, 1, 1 set view set samples 100, 100 set isosamples 10, 10 set surface unset contour set clabel '%8.3g' set mapping cartesian set datafile separator "," unset hidden3d set cntrparam order 4 set cntrparam linear set cntrparam levels auto 5 set cntrparam points 5 set size ratio 0 1,1 set origin 0,0 set style data points set style function lines set xzeroaxis linetype -2 linewidth 1.000 set yzeroaxis linetype -2 linewidth 1.000 set zzeroaxis linetype -2 linewidth 1.000 set x2zeroaxis linetype -2 linewidth 1.000 set y2zeroaxis linetype -2 linewidth 1.000 set ticslevel 0.5 set mxtics default set mytics default set mztics default set mx2tics default set my2tics default set mcbtics default set xtics border in scale 1,0.5 mirror norotate offset character 0, 0, 0 set xtics autofreq norangelimit set ytics border in scale 1,0.5 mirror norotate offset character 0, 0, 0 set ytics autofreq norangelimit set ztics border in scale 1,0.5 nomirror norotate offset character 0, 0, 0 set ztics autofreq norangelimit set nox2tics set noy2tics set cbtics border in scale 1,0.5 mirror norotate offset character 0, 0, 0 set cbtics autofreq norangelimit set title "" set title offset character 0, 0, 0 font "" norotate set timestamp bottom set timestamp "" set timestamp offset character 0, 0, 0 font "" norotate set rrange [ * : * ] noreverse nowriteback # (currently [0.00000:10.0000] ) set trange [ * : * ] noreverse nowriteback # (currently ["1999/12/31":"2000/01/01"] ) set urange [ * : * ] noreverse nowriteback # (currently ["1999/12/31":"2000/01/01"] ) set vrange [ * : * ] noreverse nowriteback # (currently [-5.00000:5.00000] ) set xlabel "" set xlabel offset character 0, 0, 0 font "" textcolor lt -1 norotate set x2label "" set x2label offset character 0, 0, 0 font "" textcolor lt -1 norotate set xrange [ * : * ] noreverse nowriteback # (currently ["1999/12/31":"2000/01/01"] ) set x2range [ * : * ] noreverse nowriteback # (currently [-10.0000:10.0000] ) set ylabel "" set ylabel offset character 0, 0, 0 font "" textcolor lt -1 rotate by 90 set y2label "" set y2label offset character 0, 0, 0 font "" textcolor lt -1 rotate by 90 set yrange [ * : * ] noreverse nowriteback # (currently [-10.0000:10.0000] ) set y2range [ * : * ] noreverse nowriteback # (currently [-10.0000:10.0000] ) set zlabel "" set zlabel offset character 0, 0, 0 font "" textcolor lt -1 norotate set zrange [ * : * ] noreverse nowriteback # (currently [-10.0000:10.0000] ) set cblabel "" set cblabel offset character 0, 0, 0 font "" textcolor lt -1 rotate by 90 set cbrange [ * : * ] noreverse nowriteback # (currently [-10.0000:10.0000] ) set zero 1e-08 set lmargin -1 set bmargin -1 set rmargin -1 set tmargin -1 set locale "C" set pm3d explicit at s set pm3d scansautomatic set pm3d interpolate 1,1 flush begin noftriangles nohidden3d corners2color mean set palette positive nops_allcF maxcolors 0 gamma 1.5 color model RGB set palette rgbformulae 7, 5, 15 set colorbox default set colorbox vertical origin screen 0.9, 0.2, 0 size screen 0.05, 0.6, 0 front bdefault set loadpath set fontpath set fit noerrorvariables # for Mac OS X GNUTERM = "aqua" plot 'hatena.csv' using 1:2 w l smooth sbezier, 'hatena.csv' using 1:2 # EOF