Skip to content

Instantly share code, notes, and snippets.

@tanyuan
Last active February 21, 2016 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanyuan/efe7c5c9eb7ddc6bc45b to your computer and use it in GitHub Desktop.
Save tanyuan/efe7c5c9eb7ddc6bc45b to your computer and use it in GitHub Desktop.
Generate a CSV for experiment result.
#!/bin/bash
# Compute means of experiment data CSVs in a directory into a CSV.
# Example: ./generate-mean-csv.sh data/rawdata/vib-3/
# CSV directory
dir=$1
# Write CSV header
echo "Date,User Id,Gender,Age,vibtime,waitingtime,Data Count,Accuracy (%)"
# Get each CSV in the directory
for path in $dir*.csv; do
# Parse file name
# Get only the file name, not full path
file=$(basename $path)
# Example: EdgeVibExp-4-1-user-0006-f-22-date-2016-2-19-14-34-44.csv
vibtime=$(echo $file | cut -f2 -d-) # 4
waitingtime=$(echo $file | cut -f3 -d-) # 1
userid=$(echo $file | cut -f5 -d-) # 0006
gender=$(echo $file | cut -f6 -d-) # f
age=$(echo $file | cut -f7 -d-) # 22
year=$(echo $file | cut -f9 -d-) # 2016
month=$(echo $file | cut -f10 -d-) # 2
day=$(echo $file | cut -f11 -d-) # 19
# Get the total line number = data numbers
line_count=`wc -l < $path`
# Compute mean of the 3rd column
mean=`awk -v lines="${line_count}" -F"," '{x+=$3}END{x/=lines;x*=100;print x }' $path`
# Write in CSV format
echo "$year-$month-$day,$userid,$gender,$age,$vibtime,$waitingtime,$line_count,$mean"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment