Last active
December 17, 2015 03:09
-
-
Save thenaterhood/5541681 to your computer and use it in GitHub Desktop.
A quick and dirty shell script that compiles the RIT SE250T course's activity journals into a single file with a breakdown of times for each stage as well as total times for the project. See the code comments for more information.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Author: | |
# Nate Levesque <[email protected]> | |
# Language: | |
# Shell | |
# Description: | |
# Compiles the SE Activity journals into one file | |
# | |
# Usage: | |
# The program needs to be placed and run in the git working directory | |
# where the activities/projects are stored for the class. When run, | |
# it requests a filename to save a summary to, then runs through | |
# and finds all the Activity_Journal.txt files and pulls the estimated | |
# and calculated time values from them. | |
# | |
# The program was built quick and dirty and therefore isn't terribly | |
# robust. It assumes that the files are formatted exactly as the | |
# provided ones say they are supposed to be and that the time values | |
# are properly filled. If a time value contains something that is not | |
# a number, is missing or the HH MM values are separated by something | |
# other than a space, the program will probably have a problem with it. | |
# | |
# The program can be run with `bash compileJournals.sh`, or if executable | |
# permissions have been added, with simply ./compileJournals.sh | |
# | |
# Pull the system time so that we have a unique number to use | |
# with the files we throw in /tmp | |
systime=`date +%m%s` | |
# Calculates the total times for a given project journal file | |
# | |
# Parameters: | |
# path to the file | |
# value to grep for (i.e, 'Actual') | |
# | |
calcTotal(){ | |
# Iterate through all the reported times in the | |
# file and calculate the total minutes and hours | |
cat $1 | grep "$2" | while read p; do | |
stagehr=`echo $p | cut -d " " -f 3` | |
stagemin=`echo $p | cut -d " " -f 4 | cut -c 1-2` | |
minutes=$(( $minutes + $stagemin )) | |
hours=$(( $hours + $stagehr )) | |
total="$(($hours + $(($minutes/60)) )) $(( $minutes%60 ))" | |
# Store the total in a file so when the subshell exits | |
# it can still be retrieved | |
echo $total > /tmp/est$systime | |
done; | |
# Retrieve the value | |
total=`cat /tmp/est$systime` | |
# Remove the temp file | |
rm /tmp/est$systime | |
# Return the value | |
echo $total | |
} | |
# Iterate through all the Activity_Journal.txt files found | |
projects=0 | |
read -p "Where to save the breakdown: " fname | |
# Create a file (or clear it, if it exists) | |
>$fname | |
for file in `find ./ -name Activity_Journal.txt`; do | |
(( projects++ )) | |
# Create a header for the section with the name | |
echo "======================================" >> $fname; | |
cat $file | head -2 | tail -1 >> $fname; | |
echo "======================================" >> $fname; | |
# Calculate the totals for the file | |
estimate=$(calcTotal $file "Estimated Time") | |
echo "Estimated Time $estimate" >> /tmp/tot$systime | |
actual=$(calcTotal $file "Actual Time") | |
echo "Actual Time $actual" >> /tmp/tot$systime | |
# Output the stage breakdown and totals to the file | |
echo -e " Stage Type Time" >> $fname | |
echo -e "`cat $file | grep "Estimated" | cat -n`\n" >> $fname; | |
echo -e "`cat $file | grep "Actual" | cat -n `\n" >> $fname; | |
echo " Total" >> $fname | |
echo " Estimated $estimate" >> $fname | |
echo " Actual $actual" >> $fname | |
echo -e "\n\n" >> $fname | |
done | |
# Calculate the overall totals | |
totalEstimate=$(calcTotal "/tmp/tot$systime" "Estimated") | |
totalActual=$(calcTotal "/tmp/tot$systime" "Actual") | |
# Remove the temporary file for totals | |
rm /tmp/tot$systime | |
# Display time summary | |
echo "Calculated breakdown for $projects project(s)." | |
echo " Total estimated time $totalEstimate" | |
echo " Actual calculated time $totalActual" | |
echo "" | |
echo "Saved breakdown details to $fname." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment