#! /bin/bash

###################################################################
###this program unzip the data and allow the user to choose the size
###of training and validation sets to put in respective folders
###This script should only run once, that's enough
###################################################################

#remove all the folders here
rm -rf faces
rm -rf nonfaces
rm -rf train
rm -rf test

#get data from zip
unzip faceTrainingData.zip

#get both pathFiles
find faces -type f | sort > facePath
find nonfaces -type f | sort > nonFacePath

#and their sizes
pSize=$(cat facePath | wc -l)
nSize=$(cat nonFacePath | wc -l)
echo -e "we have $pSize positives and $nSize negatives in the folder.\n"


#determine the size of the training set
echo -e "determine the training set. And all the rest will be for the validation set.\n"
read -p "how big is the positive training set? " train_pSize
pMarker=$(($train_pSize+1))
read -p "how big is the negative training set? " train_nSize
nMarker=$(($train_nSize+1))

#now you get both test and training pathFiles
sed -n 1,${train_pSize}p facePath | sort > positives.txt
sed -n 1,${train_nSize}p nonFacePath | sort > negatives.txt
sed -n ${pMarker},${pSize}p facePath | sort > test_positives.txt
sed -n ${nMarker},${nSize}p nonFacePath | sort > test_negatives.txt

echo -e "test negative $(cat test_negatives.txt | wc -l)"
echo -e "test positive $(cat test_positives.txt | wc -l)"
echo -e "positives $(cat positives.txt | wc -l)"
echo -e "negatives $(cat negatives.txt | wc -l)"

#create test folder
mkdir test
mkdir test/faces
mkdir test/nonfaces

for line in $(cat test_positives.txt)
do
	echo $line
	mv $line test/faces
done

for line in $(cat test_negatives.txt)
do
	echo $line
	mv $line test/nonfaces
done

#create train folder
mkdir train
mv faces train
mv nonfaces train

rm *.txt
rm *Path
