2 # -*- coding: utf-8 -*-
6 Munter Time Calculation
8 Wylark Mountaineering LLC
12 A rudimentary program which implements the Munter time calculation.
18 class InvalidUnitsException(Exception):
22 'uphill': { 'rate': 4, 'direction': '↑' },
23 'flat': { 'rate': 6, 'direction': '→' }, # or downhill on foot
24 'downhill': { 'rate': 10, 'direction': '↓' },
25 'bushwhacking': { 'rate': 2, 'direction': '↹' },
28 unit_choices
= ['metric', 'imperial']
29 travel_mode_choices
= rates
.keys()
31 def time_calc(distance
, elevation
, rate
, units
):
34 if units
not in unit_choices
:
35 raise InvalidUnitsException
39 if 'imperial' == units
:
41 distance
= (distance
* 1.609) # mi to km
42 elevation
= (elevation
* .305) # ft to m
44 unit_count
= distance
+ (elevation
/ 100.0)
46 retval
['time'] = (distance
+ (elevation
/ 100.0)) / rates
[rate
]['rate']
47 retval
['unit_count'] = unit_count
48 retval
['direction'] = rates
[rate
]['direction']
49 retval
['pace'] = rates
[rate
]['rate']
53 def print_ugly_estimate(est
):
54 hours
= int(est
['time'])
55 minutes
= int((est
['time'] - hours
) * 60)
56 print("{human_time}".format(
57 human_time
="{hours} hours {minutes} minutes".format(
61 def print_pretty_estimate(est
):
62 hours
= int(est
['time'])
63 minutes
= int((est
['time'] - hours
) * 60)
65 # NOTE: Below, the line with the unicode up arrow uses an alignment
66 # value of 31. In the future, consider using e.g. wcwidth
67 # library so that this is more elegant.
68 print("\n\t╒═══════════════════════════════╕")
69 print("\t╎▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒╎╮")
70 print("\t╎▒{:^29}▒╎│".format(''))
71 print("\t╎▒{pace_readable:^31}▒╎│".format(
72 pace_readable
="{units} {direction} @ {pace}".format(
73 units
=round(est
['unit_count']),
74 direction
=est
['direction'],
76 print("\t╎▒{human_time:^29}▒╎│".format(
77 human_time
="{hours} hours {minutes} minutes".format(
80 print("\t╎▒{:^29}▒╎│".format(''))
81 print("\t╎▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒╎│")
82 print("\t╘═══════════════════════════════╛│")
83 print("\t └───────────────────────────────┘\n")
86 parser
= argparse
.ArgumentParser(description
='Munter Time Calculation')
88 parser
.add_argument('--distance',
92 help='Distance (in km, by default)')
94 parser
.add_argument('--elevation',
98 help='Elevation change (in m, by default)')
100 parser
.add_argument('--travel-mode',
104 choices
=travel_mode_choices
, required
=False,
105 help='Travel mode (flat, by default)')
107 parser
.add_argument('--units',
112 choices
=unit_choices
,
113 help='Units of input values')
115 parser
.add_argument('--pretty',
124 parser
= get_parser()
125 opts
= parser
.parse_args()
127 distance
= opts
.distance
128 elevation
= opts
.elevation
130 travel_mode
= opts
.travel_mode
132 time_estimate
= time_calc(distance
, elevation
, travel_mode
, units
=units
)
135 print_pretty_estimate(time_estimate
)
137 print_ugly_estimate(time_estimate
)
141 if __name__
== "__main__":