X-Git-Url: https://wylark.com/src/munter.git/blobdiff_plain/29ca1c8accc6dea9a53ac950eb756a6c7cbc9b6a..ac1b24e5ece40164f50b17a27dda73ddd4e41b11:/munter.py?ds=inline diff --git a/munter.py b/munter.py index b7a7f72..485db19 100755 --- a/munter.py +++ b/munter.py @@ -1,61 +1,9 @@ #! /usr/bin/env python +# -*- coding: utf-8 -*- -# Munter Time Calculation -# -# Rudimentary program written by ALV to implement the Munter time calculation - +"""Wrapper for running directly from the source code directory""" 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)) +from munter.munter import main if __name__ == "__main__": - main() + sys.exit(main())