Tanita BC-601 Scale Script

I own a body scale called Tanita BC-601. Everyt ime I step on it all the data will be written to an SD card and they include a pretty pretty bad Windows software to analyze the data.

Besides the quality. Who wants to boot Windows just to read that data…

There is one file for every user on the SD card and they can be found on the card in TANITA/GRAPHV1/DATA The file are called DATA1.CSV for the first user, DATA2.CSV for the second user, …
You might think now the work is already done, because csv should be easy to deal with, but it’s not a real csv file

Let me show you the first lines:

cat TANITA/GRAPHV1/DATA/DATA1.CSV

{0,16,~0,2,~1,2,~2,3,~3,4,MO,"BC-601",DT,"13/02/2013",Ti,"18:59:39",Bt,0,GE,1,AG,31,Hm,174.0,AL,1,Wk,85.0,MI,28.1,FW,22.3,Fr,19.0,Fl,20.8,FR,19.6,FL,19.6,FT,24.5,mW,62.8,mr,3.8,ml,3.7,mR,10.9,mL,10.7,mT,33.7,bW,3.3,IF,7,rD,3018,rA,40,ww,55.3,CS,21
{0,16,~0,2,~1,2,~2,3,~3,4,MO,"BC-601",DT,"14/02/2013",Ti,"07:44:06",Bt,0,GE,1,AG,31,Hm,174.0,AL,1,Wk,84.0,MI,27.7,FW,23.9,Fr,19.4,Fl,21.9,FR,21.5,FL,21.1,FT,26.1,mW,60.7,mr,3.7,ml,3.6,mR,10.6,mL,10.5,mT,32.3,bW,3.2,IF,8,rD,2929,rA,45,ww,53.9,CS,13

So they put in keywords (DT) followed by the value (“2013/02/13”, 85.0, …). So it was needed to compare the data that I see on the device to the data I can see in the file, remove the unwanted information and descriptions and create a real csv file.

date; time; age; size; work; weight; bmi; visc_fat; fat_relative; fat_total; muscle; bones; calories; meta_age; water; arm_l; arm_r; leg_l; leg_r; trunk
13/02/2013; 18:59:39; 31; 174.0; 1; 85.0; 28.1; 7; 18.9550; 22.3; 62.8; 3.3; 3018; 40; 55.3; 19.0; 20.8; 19.6; 19.6; 24.5
14/02/2013; 07:44:06; 31; 174.0; 1; 84.0; 27.7; 8; 20.0760; 23.9; 60.7; 3.2; 2929; 45; 53.9; 19.4; 21.9; 21.1; 21.5; 26.1

So now we have a csv file which we could open in OpenOffice to create some charts. I also create some charts already in the script with gnuplot so you can get an quick overview as well.

#!/bin/bash

file=$1
output_csv="output.csv"

echo "date; time; age; size; work; weight; bmi; visc_fat; fat_relative; fat_total; muscle; bones; calories; meta_age; water; arm_l; arm_r; leg_l; leg_r; trunk" > $output_csv
while read line; do

  line2=$(echo $line | sed -e 's/,/;/g')
  #line2=$(echo $line | sed -e 's/,/;/g' -e 's/\./,/g')
  
  date=$(echo $line2 | cut -d ";" -f14 | tr -d "\"")
  time=$(echo $line2 | cut -d ";" -f16 | tr -d "\"")
  age=$(echo $line2 | cut -d ";" -f22)
  size=$(echo $line2 | cut -d ";" -f24)
  work=$(echo $line2 | cut -d ";" -f26)
  weight=$(echo $line2 | cut -d ";" -f28)
  bmi=$(echo $line2 | cut -d ";" -f30)
  visc_relative=$(echo $line2 | cut -d ";" -f58)
  fat_sum=$(echo $line2 | cut -d ";" -f32)
  fat_total=$(echo "scale=4; $weight/100*$fat_sum" | bc)
  muscle=$(echo $line2 | cut -d ";" -f44)
  bones=$(echo $line2 | cut -d ";" -f56)
  calories=$(echo $line2 | cut -d ";" -f60)
  meta_age=$(echo $line2 | cut -d ";" -f62)
  water=$(echo $line2 | cut -d ";" -f64)
  arm_l=$(echo $line2 | cut -d ";" -f34)
  arm_r=$(echo $line2 | cut -d ";" -f36)
  leg_l=$(echo $line2 | cut -d ";" -f40)
  leg_r=$(echo $line2 | cut -d ";" -f38)
  trunk=$(echo $line2 | cut -d ";" -f42)
  echo "$date; $time; $age; $size; $work; $weight; $bmi; $visc_relative; $fat_total; $fat_sum; $muscle; $bones; $calories; $meta_age; $water; $arm_l; $arm_r; $leg_l; $leg_r; $trunk" >> $output_csv
  echo "$date $time $age $size $work $weight $bmi $visc_relative $fat_total $fat_sum $muscle $bones $calories $meta_age $water $arm_l $arm_r $leg_l $leg_r $trunk" >> output.dat
  echo "$date; $time; $age; $size; $work; $weight; $bmi; $visc_relative; $fat_total; $fat_sum; $muscle; $bones; $calories; $meta_age; $water; $arm_l; $arm_r; $leg_l; $leg_r; $trunk" 

done < $file

~/homebrew/bin/gnuplot <<EOF
    set terminal png
    set timefmt "%d/%m/%Y"
    set xdata time
    set title "Weight"
    set output "weight.png"
    set style data linespoints
    set grid
    plot "output.dat" using 1:6 title "Weight"
EOF

~/homebrew/bin/gnuplot <<EOF
    set terminal png
    set timefmt "%d/%m/%Y"
    set xdata time
    set title "Fat"
    set output "fat.png"
    set style data linespoints
    set grid
    plot "output.dat" using 1:9 title "Fat (Percent)", \
    "output.dat" using 1:10 title "Fat (kg)" 
EOF

~/homebrew/bin/gnuplot <<EOF
    set terminal png
    set timefmt "%d/%m/%Y"
    set xdata time
    set title "Body"
    set output "body.png"
    set style data linespoints
    set grid
    plot "output.dat" using 1:11 title "Muscles (kg)", \
    "output.dat" using 1:15 title "Water (Percent)"
EOF

~/homebrew/bin/gnuplot <<EOF
    set terminal png
    set timefmt "%d/%m/%Y"
    set xdata time
    set title "Body Details"
    set output "body_details.png"
    set style data linespoints
    set grid
    plot "output.dat" using 1:16 title "Left Arm (Fat, Percent)", \
    "output.dat" using 1:17 title "Right Arm (Fat, Percent)", \
    "output.dat" using 1:18 title "Left Leg (Fat, Percent)", \
    "output.dat" using 1:18 title "Right Leg (Fat, Percent)", \
    "output.dat" using 1:18 title "Trunk (Fat, Percent)"
EOF

rm -f output.dat

echo "<html>
<body>
<h1>Weight</h1>
<img src=weight.png>

<h1>Fat</h1>
<img src=fat.png>

<h1>Body</h1>
<img src=body.png>

<h1>Body Details</h1>
<img src=body_details.png>

</body>
</html>" > index.html

To run the script you have to tell him where the data file is ./tanita_scale.sh TANITA/GRAPHV1/DATA/DATA1.CSV Afterwards you can look into the output.csv file or just open the index.html file to look at the charts.

Here’s an example how such a chart would look like:
I had vacation end of May… 😀

Tagged , ,