Skip to content

Instantly share code, notes, and snippets.

@proustibat
Last active May 7, 2018 12:21
Show Gist options
  • Save proustibat/4c4b69a6fd30ad91347b564e53b76856 to your computer and use it in GitHub Desktop.
Save proustibat/4c4b69a6fd30ad91347b564e53b76856 to your computer and use it in GitHub Desktop.
read-results.sh
#!/usr/bin/env bash
## @file read-results.sh
## @author Jennifer Proust - proustibat@gmail.com
## @section DESCRIPTION Get all results of install-comparisons.sh script
set -o errexit || true
set -o errtrace
set -o nounset
set -o pipefail
#set -o xtrace
RESULTDIR="install-results"
RESULTFILE="results.txt"
COMPILERESULTFILE="compile-results.txt"
JSONFILE="compile-results.json"
NB=0
getUserTime() {
echo $(sed -n ${1}p $PROJECTDIR/$RESULTDIR/$RESULTFILE | awk '{print $1}')
}
PROJECTOBJECTS=()
getResults() {
PROJECTDIR=${1}
if [ -d "$PROJECTDIR/$RESULTDIR" ]; then
echo "$PROJECTDIR"
NB=$(( $NB + 1 ))
npm5UserTimeI1=$(getUserTime 17)
npm5UserTimeI2=$(getUserTime 21)
npm5UserTimeI3=$(getUserTime 25)
npm6UserTimeI1=$(getUserTime 35)
npm6UserTimeI2=$(getUserTime 39)
npm6UserTimeI3=$(getUserTime 43)
yarnUserTimeI1=$(getUserTime 53)
yarnUserTimeI2=$(getUserTime 57)
yarnUserTimeI3=$(getUserTime 61)
# FOR A SIMPLE TXT FILE
header="=================================\n$NB. `basename "$PROJECTDIR"`\n=================================\n"
npm5="NPM5: $npm5UserTimeI1 - $npm5UserTimeI2 - $npm5UserTimeI3\n"
npm6="NPM6: $npm6UserTimeI1 - $npm6UserTimeI2 - $npm6UserTimeI3\n"
yarn="YARN: $yarnUserTimeI1 - $yarnUserTimeI2 - $yarnUserTimeI3\n"
end="\n"
project_result="$header$npm5$npm6$yarn$end"
printf "\nRESULTS FILE GENERATED: \n"
printf "$project_result" | tee -a "$COMPILERESULTFILE"
# FOR A JSON
projectId="`basename "$PROJECTDIR"`"
projectObject="{\n\t\t\"id\": \"$projectId\",\n\t\t\"npm5\": [ \"$npm5UserTimeI1\", \"$npm5UserTimeI2\", \"$npm5UserTimeI3\" ],\n\t\t\"npm6\": [ \"$npm6UserTimeI1\", \"$npm6UserTimeI2\", \"$npm6UserTimeI3\" ],\n\t\t\"yarn\": [ \"$yarnUserTimeI1\", \"$yarnUserTimeI2\", \"$yarnUserTimeI3\" ]\n\t}"
PROJECTOBJECTS+=("$projectObject")
fi
}
createJSON() {
printf "\nJSON FILE GENERATED: \n"
printf "{\n\t\"projects\": [ " | tee -a "$JSONFILE"
for i in "${!PROJECTOBJECTS[@]}"; do
suffix=", "
if [ $(($i + 1)) = $NB ]; then
suffix=""
fi
printf "${PROJECTOBJECTS[$i]}$suffix" | tee -a "$JSONFILE"
done
printf " ]\n}\n" | tee -a "$JSONFILE"
}
# START
rm -rf "$COMPILERESULTFILE"
touch $COMPILERESULTFILE
for Pdepth1 in ${PWD}/* ; do
if [ -d "$Pdepth1" ]; then
getResults "${Pdepth1}"
for Pdepth2 in ${Pdepth1}/* ; do
if [ -d "$Pdepth2" ]; then
getResults "${Pdepth2}"
for Pdepth3 in ${Pdepth2}/* ; do
if [ -d "$Pdepth3" ]; then
getResults "${Pdepth3}"
fi
done
fi
done
fi
done
open "$COMPILERESULTFILE"
rm -rf "$JSONFILE"
touch "$JSONFILE"
createJSON
open "$JSONFILE"
@proustibat
Copy link
Author

git clone https://gist.github.com/4c4b69a6fd30ad91347b564e53b76856.git ic-compile && cp ic-compile/read-results.sh . && rm -rf ic-compile && bash read-results.sh && rm read-results.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment