7179e5272ebcef59572a1d5317d6297375567822
1 # -*- coding: utf-8 -*-
5 Munter Time Calculation
7 Wylark Mountaineering LLC
9 A rudimentary program which implements the Munter time calculation.
15 class InvalidUnitsException(Exception):
19 'uphill': { 'rate': 4, 'direction': '↑' },
20 'flat': { 'rate': 6, 'direction': '→' }, # or downhill on foot
21 'downhill': { 'rate': 10, 'direction': '↓' },
22 'bushwhacking': { 'rate': 2, 'direction': '↹' },
25 unit_choices
= ['metric', 'imperial']
26 travel_mode_choices
= rates
.keys()
28 def time_calc(distance
, elevation
, rate
, units
):
31 if units
not in unit_choices
:
32 raise InvalidUnitsException
36 if 'imperial' == units
:
38 distance
= (distance
* 1.609) # mi to km
39 elevation
= (elevation
* .305) # ft to m
41 unit_count
= distance
+ (elevation
/ 100.0)
43 retval
['time'] = (distance
+ (elevation
/ 100.0)) / rates
[rate
]['rate']
44 retval
['unit_count'] = unit_count
45 retval
['direction'] = rates
[rate
]['direction']
46 retval
['pace'] = rates
[rate
]['rate']
50 def print_ugly_estimate(est
):
51 hours
= int(est
['time'])
52 minutes
= int((est
['time'] - hours
) * 60)
53 print("{human_time}".format(
54 human_time
="{hours} hours {minutes} minutes".format(
58 def print_pretty_estimate(est
):
59 hours
= int(est
['time'])
60 minutes
= int((est
['time'] - hours
) * 60)
62 # NOTE: Below, the line with the unicode up arrow uses an alignment
63 # value of 31. In the future, consider using e.g. wcwidth
64 # library so that this is more elegant.
65 print("\n\t╒═══════════════════════════════╕")
66 print("\t╎▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒╎╮")
67 print("\t╎▒{:^29}▒╎│".format(''))
68 print("\t╎▒{pace_readable:^31}▒╎│".format(
69 pace_readable
="{units} {direction} @ {pace}".format(
70 units
=round(est
['unit_count']),
71 direction
=est
['direction'],
73 print("\t╎▒{human_time:^29}▒╎│".format(
74 human_time
="{hours} hours {minutes} minutes".format(
77 print("\t╎▒{:^29}▒╎│".format(''))
78 print("\t╎▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒╎│")
79 print("\t╘═══════════════════════════════╛│")
80 print("\t └───────────────────────────────┘\n")
83 parser
= argparse
.ArgumentParser(description
='Munter Time Calculation')
85 parser
.add_argument('--distance',
89 help='Distance (in km, by default)')
91 parser
.add_argument('--elevation',
95 help='Elevation change (in m, by default)')
97 parser
.add_argument('--travel-mode',
101 choices
=travel_mode_choices
, required
=False,
102 help='Travel mode (flat, by default)')
104 parser
.add_argument('--units',
109 choices
=unit_choices
,
110 help='Units of input values')
112 parser
.add_argument('--pretty',
121 parser
= get_parser()
122 opts
= parser
.parse_args()
124 distance
= opts
.distance
125 elevation
= opts
.elevation
127 travel_mode
= opts
.travel_mode
129 time_estimate
= time_calc(distance
, elevation
, travel_mode
, units
=units
)
132 print_pretty_estimate(time_estimate
)
134 print_ugly_estimate(time_estimate
)
138 if __name__
== "__main__":