Add munter time calculation program
authorAlexander Vasarab <alexander@wylark.com>
Fri, 24 Mar 2017 17:47:14 +0000 (10:47 -0700)
committerAlexander Vasarab <alexander@wylark.com>
Sat, 6 Jun 2020 20:30:48 +0000 (13:30 -0700)
munter.py [new file with mode: 0755]

diff --git a/munter.py b/munter.py
new file mode 100755 (executable)
index 0000000..b7a7f72
--- /dev/null
+++ b/munter.py
@@ -0,0 +1,61 @@
+#! /usr/bin/env python
+
+# Munter Time Calculation
+#
+# Rudimentary program written by ALV to implement the Munter time calculation
+
+import sys
+import argparse
+
+class InvalidUnitsException(Exception):
+    pass
+
+rates = {
+    'uphill': 4,
+    'flat': 6, # or downhill on foot
+    'downhill': 10,
+    'bushwhacking': 2
+}
+
+unit_choices = ['metric', 'imperial']
+travel_mode_choices = rates.keys()
+
+def munter(distance, elevation, rate='flat', units='metric'):
+    if units not in unit_choices:
+        raise InvalidUnitsException
+
+    if 'imperial' == units:
+        # convert to metric
+        distance = (distance * 1.609) # mi to km
+        elevation = (elevation * .305) # ft to m
+
+    time = (distance + (elevation / 100.0)) / rates[rate]
+
+    return time
+
+def main():
+    parser = argparse.ArgumentParser(description='Munter Time Calculation')
+
+    parser.add_argument('--distance', '-d', type=float, required=True,
+        help='Distance (in km, by default)')
+    parser.add_argument('--elevation', '-e', type=float, required=True,
+        help='Elevation change (in m, by default)')
+    parser.add_argument('--travel-mode', '-t', type=str,
+        default='uphill', choices=travel_mode_choices, required=False,
+        help='Travel mode (flat, by default)')
+    parser.add_argument('--units', '-u', type=str, default='metric',
+        required=False,
+        choices=unit_choices,
+        help='Units of input values')
+    opts = parser.parse_args()
+
+    distance = opts.distance
+    elevation = opts.elevation
+    units = opts.units
+    travel_mode = opts.travel_mode
+
+    print("Estimated Time (in hours) = %8.2f"
+        % munter(distance, elevation, travel_mode, units=units))
+
+if __name__ == "__main__":
+    main()