wow, more nice new scripts. time tracker lets different activities be tracked for...
authorChris Koeritz <fred@gruntose.com>
Sun, 18 Sep 2016 00:44:13 +0000 (20:44 -0400)
committerChris Koeritz <fred@gruntose.com>
Sun, 18 Sep 2016 00:44:13 +0000 (20:44 -0400)
scripts/system/time_tracker.sh [new file with mode: 0644]
scripts/unit_test/array_sifter_test.sh [deleted file]
scripts/unit_test/test_array_sifter.sh [new file with mode: 0644]
scripts/unit_test/test_assoc_array.sh
scripts/unit_test/test_time_tracker.sh [new file with mode: 0644]

diff --git a/scripts/system/time_tracker.sh b/scripts/system/time_tracker.sh
new file mode 100644 (file)
index 0000000..15e30db
--- /dev/null
@@ -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 (file)
index 26173f1..0000000
+++ /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 (file)
index 0000000..26173f1
--- /dev/null
@@ -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
+
+
index 49cf6eccc230252f8047cc9888a36b9f5ae5bdc0..8da0424889b4a0e24e3ae0c117f2dd1fcb381c4c 100644 (file)
@@ -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 (file)
index 0000000..9a90857
--- /dev/null
@@ -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
+