From: Chris Koeritz Date: Sun, 18 Sep 2016 00:44:13 +0000 (-0400) Subject: wow, more nice new scripts. time tracker lets different activities be tracked for... X-Git-Tag: 2.140.90~442 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=bc201b9da42329ca2b122af0c7335b4ac0d67940;hp=d6b9b4e06ee566ba7c15039b479b2e95391d0e21;p=feisty_meow.git wow, more nice new scripts. time tracker lets different activities be tracked for duration, keeping them separate by name. the test for it just tries a random time duration and prints it out. other tests got cleaned or renamed too. --- diff --git a/scripts/system/time_tracker.sh b/scripts/system/time_tracker.sh new file mode 100644 index 00000000..15e30db7 --- /dev/null +++ b/scripts/system/time_tracker.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# some helpful functions for counting a named duration. + +# start tracking time for a named purpose, passed as the first parameter. +function start_time_tracking() +{ + local varname="$1"; shift + if [ -z "$varname" ]; then echo must pass variable name to start_time_tracking; return 1; fi + local startvar="${varname}_START" + eval $startvar="$(date +"%s")" +} + +# stop tracking the named time duration. +function end_time_tracking() +{ + local varname="$1"; shift + if [ -z "$varname" ]; then echo must pass variable name to end_time_tracking; return 1; fi + local endvar="${varname}_END" + eval $endvar="$(date +"%s")" +} + +# display the time taken for a named duration. +function show_tracked_duration() +{ + varname="$1"; shift + if [ -z "$varname" ]; then echo must pass variable name to end_time_tracking; return 1; fi + # calculate the time taken. + local startvar="${varname}_START" + local endvar="${varname}_END" + duration="$((${!endvar} - ${!startvar}))" + # separate it into hours and minutes. + minutes="$(($duration / 60))" + hours="$(($duration / 60))" + # subtract the hours from the minutes sum for modulo. + minutes="$(($minutes - $hours * 60))" + # fashion conceit, add zeroes. + if (($minutes < 10)); then minutes="0$minutes"; fi + if (($hours < 10)); then hours="0$hours"; fi + echo "Time taken for ${varname}: ${hours}:${minutes} hh:mm (a total of $duration seconds)" +} + + diff --git a/scripts/unit_test/array_sifter_test.sh b/scripts/unit_test/array_sifter_test.sh deleted file mode 100644 index 26173f19..00000000 --- a/scripts/unit_test/array_sifter_test.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -# -# tests the array sifter methods. - -source $FEISTY_MEOW_SCRIPTS/core/array_sifter.sh - -#demo 1 & 2 for test presence. -declare -a my_array=(peanuts sauce fish basil) - -test1=basil -test_presence my_array $test1 -if [ $? != 0 ]; then - echo "test1 did not find flag, but should have." -else - echo "test1 found expected flag." -fi - -test2=spoo -test_presence my_array $test2 -if [ $? != 0 ]; then - echo "test2 did not find flag, which is correct." -else - echo "test2 found flag when should not have." -fi - -############################################# - -#demo3 for sifting... - -declare -a sift_list=(ontrack selenium aggressive) -declare -a stripping=(selenium) -declare -a store_list=() - -sift_array "sift_list" "stripping" "store_list" -if [ ${store_list[0]} == "selenium" ]; then - echo "test3 found expected content in storage list." -else - echo "test3 was missing expected content in storage list." -fi -echo sift is now ${sift_list[*]} -if [ "${sift_list[*]}" == "ontrack aggressive" ]; then - echo "test3 found expected content in sifting list." -else - echo "test3 was missing expected content in sifting list." -fi - - diff --git a/scripts/unit_test/test_array_sifter.sh b/scripts/unit_test/test_array_sifter.sh new file mode 100644 index 00000000..26173f19 --- /dev/null +++ b/scripts/unit_test/test_array_sifter.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# +# tests the array sifter methods. + +source $FEISTY_MEOW_SCRIPTS/core/array_sifter.sh + +#demo 1 & 2 for test presence. +declare -a my_array=(peanuts sauce fish basil) + +test1=basil +test_presence my_array $test1 +if [ $? != 0 ]; then + echo "test1 did not find flag, but should have." +else + echo "test1 found expected flag." +fi + +test2=spoo +test_presence my_array $test2 +if [ $? != 0 ]; then + echo "test2 did not find flag, which is correct." +else + echo "test2 found flag when should not have." +fi + +############################################# + +#demo3 for sifting... + +declare -a sift_list=(ontrack selenium aggressive) +declare -a stripping=(selenium) +declare -a store_list=() + +sift_array "sift_list" "stripping" "store_list" +if [ ${store_list[0]} == "selenium" ]; then + echo "test3 found expected content in storage list." +else + echo "test3 was missing expected content in storage list." +fi +echo sift is now ${sift_list[*]} +if [ "${sift_list[*]}" == "ontrack aggressive" ]; then + echo "test3 found expected content in sifting list." +else + echo "test3 was missing expected content in sifting list." +fi + + diff --git a/scripts/unit_test/test_assoc_array.sh b/scripts/unit_test/test_assoc_array.sh index 49cf6ecc..8da04248 100644 --- a/scripts/unit_test/test_assoc_array.sh +++ b/scripts/unit_test/test_assoc_array.sh @@ -7,7 +7,7 @@ declare -A snuggles # make an associative array -snuggles=([book]=petunia "[muffets]=glasgow robbery") +snuggles=([book]=petunia [muffets]="glasgow robbery") # keys: book and muffets # values: (second part) diff --git a/scripts/unit_test/test_time_tracker.sh b/scripts/unit_test/test_time_tracker.sh new file mode 100644 index 00000000..9a908578 --- /dev/null +++ b/scripts/unit_test/test_time_tracker.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# tests out the time tracking methods. + +source $FEISTY_MEOW_SCRIPTS/system/time_tracker.sh + +echo testing time tracking... +start_time_tracking crungle + +sleep $(($RANDOM / 1000)) +sleep 2 + +end_time_tracking crungle + +echo ...done testing time tracking. + +show_tracked_duration crungle +