Merge branch 'develop' of https://zdv2.bktei.com/gitweb/ninfacyzga-01 into develop
authorSteven Baltakatei Sandoval <baltakatei@gmail.com>
Mon, 18 Oct 2021 06:46:27 +0000 (06:46 +0000)
committerSteven Baltakatei Sandoval <baltakatei@gmail.com>
Mon, 18 Oct 2021 06:46:27 +0000 (06:46 +0000)
.gitmodules [new file with mode: 0644]
TODO.org
doc/process_flow_diagram.odg [new file with mode: 0644]
exec/pimoroni/all-in-one-enviro-mini-bk.py [new symlink]
exec/unitproc/sleepRand.py [new file with mode: 0755]
lib/EVA-2020-02-2..pimoroni_enviroplus-python_bk [new submodule]

diff --git a/.gitmodules b/.gitmodules
new file mode 100644 (file)
index 0000000..b3520d3
--- /dev/null
@@ -0,0 +1,3 @@
+[submodule "lib/EVA-2020-02-2..pimoroni_enviroplus-python_bk"]
+       path = lib/EVA-2020-02-2..pimoroni_enviroplus-python_bk
+       url = https://zdv2.bktei.com/gitweb/EVA-2020-02-2.git
index aa1f1b5e4b878d7f380e7e452477c33432b50e08..cddc236f33281b975939b81c60b4b30687e18af0 100644 (file)
--- a/TODO.org
+++ b/TODO.org
@@ -52,6 +52,9 @@ Date Created: 2021-01-25T00:25Z
 
 Setting up time tracking via ~chrony~.
 
+** TODO Use ~age --version~ in creating ~VERSION~ output files
+~age~ as of ~beta7~ outputs its version using the ~--version~ option.
+
 * Finished Tasks
 ** DONE Remove unused executables
    CLOSED: [2021-01-25 Mon 00:07]
diff --git a/doc/process_flow_diagram.odg b/doc/process_flow_diagram.odg
new file mode 100644 (file)
index 0000000..5759d61
Binary files /dev/null and b/doc/process_flow_diagram.odg differ
diff --git a/exec/pimoroni/all-in-one-enviro-mini-bk.py b/exec/pimoroni/all-in-one-enviro-mini-bk.py
new file mode 120000 (symlink)
index 0000000..2711ecb
--- /dev/null
@@ -0,0 +1 @@
+../../lib/EVA-2020-02-2..pimoroni_enviroplus-python_bk/examples/all-in-one-enviro-mini-bk.py
\ No newline at end of file
diff --git a/exec/unitproc/sleepRand.py b/exec/unitproc/sleepRand.py
new file mode 100755 (executable)
index 0000000..016e9f3
--- /dev/null
@@ -0,0 +1,127 @@
+#!/usr/bin/env python3
+# Desc: Pauses a random amount of time. Random distribution is inverse gaussian.
+# Version: 0.0.6
+# Depends: python 3.7.3
+# Usage: ./sleepRand.py [-v] [-p P] SECONDS
+# Input: SECONDS: float seconds (mean of inverse gaussian distribution)
+#        P:       precision (lambda of inverse gaussian distribution)
+# Example: python3 sleepRand.py -vv -p 8.0 60.0
+
+import argparse;
+import math, time, random, sys;
+import logging;
+
+# Set up argument parser (see https://docs.python.org/3.7/library/argparse.html )
+parser = argparse.ArgumentParser(
+    description='Delay activity for a random number of seconds. Delays sampled from an inverse gaussian distribution.',
+    epilog="Author: Steven Baltakatei Sandoval. License: GPLv3+");
+parser.add_argument('-v','--verbose',
+                    action='count',
+                    dest='verbosity',
+                    default=0,
+                    help='Verbose output. (repeat for increased verbosity)');
+parser.add_argument('mean',
+                    action='store',
+                    metavar='SECONDS',
+                    nargs=1,
+                    default=1,
+                    type=float,
+                    help='Mean seconds of delay. Is the mean of the inverse gaussian distribution.');
+parser.add_argument('--precision','-p',
+                    action='store',
+                    metavar='P',
+                    nargs=1,
+                    default=[4.0],
+                    type=float,
+                    help='How concentrated delays are around the mean (default: 4.0). Must be a positive integer or floating point value. Is the lambda factor in the inverse gaussian distribution. High values (e.g. > 10.0) cause random delays to rarely stray far from MEAN. Small values (e.g. < 0.10) result in many small delays plus occasional long delays.');
+parser.add_argument('--upper','-u',
+                    action='store',
+                    metavar='U',
+                    nargs=1,
+                    default=[None],
+                    type=float,
+                    help='Upper bound for possible delays (default: no bound). Without bound, extremely high delays are unlikely but possible.');
+args = parser.parse_args();
+
+# Define functions
+def setup_logging(verbosity):
+    '''Sets up logging'''
+    # Depends: module: argparse
+    # Ref/Attrib: Haas, Florian; Configure logging with argparse; https://xahteiwi.eu/resources/hints-and-kinks/python-cli-logging-options/
+    base_loglevel = 30;
+    verbosity = min(verbosity, 2);
+    loglevel = base_loglevel - (verbosity * 10);
+    logging.basicConfig(level=loglevel,
+                        format='%(message)s');
+
+def randInvGau(mu, lam):
+    """Returns random variate of inverse gaussian distribution"""
+    # input: mu:  mean of inverse gaussian distribution
+    #        lam: shape parameter
+    # output: float sampled from inv. gaus. with range 0 to infinity, mean mu
+    # example: sample = float(randInvGau(1.0,4.0));
+    # Ref/Attrib: Michael, John R. "Generating Random Variates Using Transformations with Multiple Roots" https://doi.org/10.2307/2683801
+    nu = random.gauss(0,1);
+    y = nu ** 2;
+    xTerm1 = mu;
+    xTerm2 = mu ** 2 * y / (2 * lam);
+    xTerm3 = (- mu / (2 * lam)) * math.sqrt(4 * mu * lam * y + mu ** 2 * y ** 2);
+    x = xTerm1 + xTerm2 + xTerm3;
+    z = random.uniform(0.0,1.0);
+    if z <= (mu / (mu + x)):
+        return x;
+    else:
+        return (mu ** 2 / x);
+
+# Process input
+## Start up logger
+setup_logging(args.verbosity);
+logging.debug('DEBUG:Debug logging output enabled.');
+logging.debug('DEBUG:args.verbosity:' + str(args.verbosity));
+logging.debug('DEBUG:args:' + str(args));
+
+## Receive input arguments
+try:
+    ### Get desired mean
+    desMean = args.mean[0];    
+    logging.debug('DEBUG:Desired mean:' + str(desMean));
+    
+    ### Get lambda precision factor
+    lambdaFactor = args.precision[0];
+    logging.debug('DEBUG:Lambda precision factor:' + str(lambdaFactor));
+    
+    ### Get upper bound
+    if isinstance(args.upper[0], float):
+        logging.debug('DEBUG:args.upper[0] is float:' + str(args.upper[0]));
+        upperBound = args.upper[0];
+    elif args.upper[0] is None:
+        logging.debug('DEBUG:args.upper[0] is None:' + str(args.upper[0]));
+        upperBound = None;
+    else:
+        raise TypeError('Upper bound not set correctly.');
+    logging.debug('DEBUG:Upper bound:' + str(upperBound));
+    
+    ### Reject negative floats.
+    if desMean < 0:
+        logging.error('ERROR:Desired mean is negative:' + str(desMean));
+        raise ValueError('Negative number error.');
+    if lambdaFactor < 0:
+        logging.error('ERROR:Lambda precision factor is negative:' + str(lambdaFactor));
+        raise ValueError('Negative number error.');
+except ValueError:
+    sys.exit(1);
+
+# Calculate delay
+rawDelay = randInvGau(desMean, desMean * lambdaFactor);
+logging.debug('DEBUG:rawDelay(seconds):' + str(rawDelay));
+if isinstance(upperBound,float):
+    delay = min(upperBound, rawDelay);
+elif upperBound is None:
+    delay = rawDelay;
+logging.debug('DEBUG:delay(seconds)   :' + str(delay));
+
+# Sleep
+time.sleep(float(delay));
+
+# Author: Steven Baltakatei Sandoal
+# License: GPLv3+
diff --git a/lib/EVA-2020-02-2..pimoroni_enviroplus-python_bk b/lib/EVA-2020-02-2..pimoroni_enviroplus-python_bk
new file mode 160000 (submodule)
index 0000000..3905a56
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit 3905a56d4fce040f05b3e37a8771581f45d6c828