forked from bradrisse/pyBallistics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_rich.py
299 lines (253 loc) · 12.9 KB
/
example_rich.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
import math
import argparse
import configparser
import os.path
import sys, logging
from rich.console import Console
from rich.table import Table
from bdc import calcBDC
from utils import get_incline_compensation
from utils import get_cant_compensation
from utils import fps_to_mps
from utils import inchToCm
#logLevel=logging.DEBUG
#logLevel=logging.INFO
#logLevel=logging.WARNING
# If logLevel is unset, we will only display the most serious messages.
try:
logLevel
except NameError:
logLevel=logging.CRITICAL
finally:
logging.basicConfig(format='%(levelname)s : %(filename)s : %(funcName)s : %(lineno)4d : %(message)s', level=logLevel, handlers=[logging.StreamHandler(sys.stdout)])
logging.debug('Example Debug Message')
logging.info('Example Info Message')
logging.warning('Example Warning Message')
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--conffile', type=str, dest='myconffile')
parser.add_argument('-s', '--sharedconf', type=str, dest='sharedconf')
args = parser.parse_args()
conffile = configparser.RawConfigParser()
if args.sharedconf is not None and os.path.exists(args.sharedconf):
conffile.read(args.sharedconf)
if args.myconffile is not None and os.path.exists(args.myconffile):
conffile.read(args.myconffile)
buildconf = {}
buildconf['ammunition name'] = conffile.get('Build', \
'ammunition name', \
fallback='Configuration')
buildconf['range max'] = conffile.getint('Build', 'range max', \
fallback=600)
buildconf['ballistic coefficient'] = conffile.getfloat('Build', \
'ballistic coefficient', \
fallback=0.269)
buildconf['bullet weight'] = conffile.getfloat('Build', \
'bullet weight', \
fallback=40)
buildconf['bullet weight - unit'] = conffile.get('Build', \
'bullet weight - unit', \
fallback='grains')
buildconf['velocity - muzzle'] = conffile.getint('Build', \
'velocity - muzzle', \
fallback=3165)
buildconf['sight height'] = conffile.getfloat('Build', 'sight height', \
fallback=1.5)
buildconf['angle - shooting'] = conffile.getint('Build', 'angle - shooting', \
fallback=0)
try:
buildconf['angle - bore'] = conffile.getfloat('Build', 'angle - bore', \
fallback=None)
except:
buildconf['angle - bore'] = conffile.get('Build', 'angle - bore')
if buildconf['angle - bore'].lower() == 'none':
buildconf['angle - bore'] = None
else:
print("Error in configuration file for 'angle - bore'")
quit()
buildconf['zero - distance'] = conffile.getint('Build', 'zero - distance', \
fallback=50)
buildconf['zero - unit'] = conffile.get('Build', 'zero - unit', \
fallback='y')
buildconf['drag function'] = conffile.get('Build', 'drag function', \
fallback='G1')
buildconf['altitude'] = conffile.getint('Build', 'altitude', \
fallback=0)
buildconf['altitude - unit'] = conffile.get('Build', 'altitude - unit', \
fallback='feet')
buildconf['barometer'] = conffile.getfloat('Build', 'barometer', \
fallback=29.92)
buildconf['temperature'] = conffile.getfloat('Build', 'temperature', \
fallback=59.0)
buildconf['temperature - unit'] = conffile.get('Build', 'temperature - unit', \
fallback='fahrenheit')
buildconf['humidity - relative'] = conffile.getfloat('Build', \
'humidity - relative', \
fallback=0.5)
buildconf['wind - speed'] = conffile.getfloat('Build', 'wind - speed', \
fallback=10)
buildconf['wind - unit'] = conffile.get('Build', 'wind - unit', \
fallback='mph')
buildconf['wind - angle'] = conffile.getint('Build', 'wind - angle', \
fallback=90)
#print (buildconf)
#quit()
#
displayconf = {}
displayconf['rangetype'] = conffile.get('Display', 'rangetype', \
fallback='yards')
displayconf['interval'] = conffile.getint('Display', 'interval', \
fallback=25)
displayconf['Drop - Inches'] = conffile.getboolean('Display','Drop - Inches', \
fallback=True)
displayconf['Drop - Centimeters'] = conffile.getboolean('Display', \
'Drop - Centimeters', \
fallback=False)
displayconf['Drop - MOA'] = conffile.getboolean('Display','Drop - MOA', \
fallback=False)
displayconf['Drop - Mil'] = conffile.getboolean('Display','Drop - Mil', \
fallback=True)
displayconf['Drift - Inches'] = conffile.getboolean('Display', \
'Drift - Inches', \
fallback=True)
displayconf['Drift - Centimeters'] = conffile.getboolean('Display', \
'Drift - Centimeters', \
fallback=False)
displayconf['Drift - MOA'] = conffile.getboolean('Display', 'Drift - MOA', \
fallback=False)
displayconf['Drift - Mil'] = conffile.getboolean('Display', 'Drift - Mil', \
fallback=True)
displayconf['Time'] = conffile.getboolean('Display', 'Time', fallback=True)
displayconf['Velocity - fps'] = conffile.getboolean('Display', \
'Velocity - fps', \
fallback=True)
displayconf['Velocity - mps'] = conffile.getboolean('Display', \
'Velocity - mps', \
fallback=False)
displayconf['Kinetic Energy'] = conffile.getboolean('Display', \
'Kinetic Energy', \
fallback=True)
#configuration, hold_overs = calcBDC()
configuration, hold_overs = calcBDC(buildconf)
console = Console()
console.print()
# Print Configuration Table
if buildconf['ammunition name'] != "Configuration":
conftable = Table(title = buildconf['ammunition name'])
else:
conftable = Table(title = "Configuration")
conftable.add_column("Key", justify="left", no_wrap=True)
conftable.add_column("Value", justify="left", no_wrap=True)
for item in sorted(configuration):
conftable.add_row(item, str(configuration[item]))
console.print(conftable)
console.print()
if displayconf['rangetype'] == 'both':
if buildconf['ammunition name'] != "Configuration":
tablename = buildconf['ammunition name']
else:
tablename = "Both Whole Meters and Yards"
combinedtable = Table(title = tablename)
if displayconf['rangetype'] == 'yards':
if buildconf['ammunition name'] != "Configuration":
tablename = buildconf['ammunition name']
else:
tablename = "Whole Yards Only"
combinedtable = Table(title = tablename)
elif displayconf['rangetype'] == 'meters':
if buildconf['ammunition name'] != "Configuration":
tablename = buildconf['ammunition name']
else:
tablename = "Whole Meters Only"
combinedtable = Table(title = tablename)
if displayconf['rangetype'] in ['both', 'yards']:
combinedtable.add_column("Yards", justify="right", no_wrap=True)
if displayconf['rangetype'] in ['both', 'meters']:
combinedtable.add_column("Meters", justify="right", no_wrap=True)
if displayconf['Drop - Inches']:
combinedtable.add_column("Drop - In.", justify="right", no_wrap=True)
if displayconf['Drop - Centimeters']:
combinedtable.add_column("Drop - Cm.", justify="right", no_wrap=True)
if displayconf['Drop - MOA']:
combinedtable.add_column("Drop - MOA", justify="right", no_wrap=True)
if displayconf['Drop - Mil']:
combinedtable.add_column("Drop - Mil", justify="right", no_wrap=True)
if displayconf['Drift - Inches']:
combinedtable.add_column("Drift - In.", justify="right", no_wrap=True)
if displayconf['Drift - Centimeters']:
combinedtable.add_column("Drift - Cm.", justify="right", no_wrap=True)
if displayconf['Drift - MOA']:
combinedtable.add_column("Drift - MOA", justify="right", no_wrap=True)
if displayconf['Drift - Mil']:
combinedtable.add_column("Drift - Mil", justify="right", no_wrap=True)
if displayconf['Time']:
combinedtable.add_column("Time", justify="right", no_wrap=True)
if displayconf['Velocity - fps']:
combinedtable.add_column("Velocity - fps", justify="right", no_wrap=True)
if displayconf['Velocity - mps']:
combinedtable.add_column("Velocity - mps", justify="right", no_wrap=True)
if displayconf['Kinetic Energy']:
combinedtable.add_column("Kinetic Energy", justify="right", no_wrap=True)
for point in hold_overs.points:
if (displayconf['rangetype'] == 'yards' and float(point.yards).is_integer()) or \
(displayconf['rangetype'] == 'meters' and float(point.meters).is_integer()) or \
(displayconf['rangetype'] == 'both' and (float(point.yards).is_integer() or \
float(point.meters).is_integer())):
if ((float(point.yards) / displayconf['interval']).is_integer() or \
(float(point.meters) / displayconf['interval']).is_integer()):
fieldlist = list()
if displayconf['rangetype'] in ['both', 'yards']:
fieldlist.append(point.yards)
if displayconf['rangetype'] in ['both', 'meters']:
fieldlist.append(point.meters)
# Consider reducing this to two decimal places as there is a minor
# difference exposed when using three decimal places and specifying
# a fixed bore angle for zero
pi = '{:.3f}'.format(round(point.path_inches, 3))
# pi = '{:.2f}'.format(round(point.path_inches, 3))
if displayconf['Drop - Inches']:
fieldlist.append(pi)
pc = '{:.3f}'.format(round(inchToCm(point.path_inches), 3))
if displayconf['Drop - Centimeters']:
fieldlist.append(pc)
moac = '{:.2f}'.format(round(point.moa_correction, 2))
if displayconf['Drop - MOA']:
fieldlist.append(moac)
milc = '{:.2f}'.format(round(point.mil_correction, 2))
if displayconf['Drop - Mil']:
fieldlist.append(milc)
dinch = '{:.3f}'.format(round(point.drift_inches, 3))
if displayconf['Drift - Inches']:
fieldlist.append(dinch)
dcent = '{:.3f}'.format(round(inchToCm(point.drift_inches), 3))
if displayconf['Drift - Centimeters']:
fieldlist.append(dcent)
dmoa = '{:.2f}'.format(round(point.drift_moa, 2))
if displayconf['Drift - MOA']:
fieldlist.append(dmoa)
dmil = '{:.2f}'.format(round(point.drift_mil, 2))
if displayconf['Drift - Mil']:
fieldlist.append(dmil)
stime = '{:.3f}'.format(round(point.seconds, 3))
if displayconf['Time']:
fieldlist.append(stime)
velf = '{:.2f}'.format(round(point.velocity, 2))
if displayconf['Velocity - fps']:
fieldlist.append(velf)
velm = '{:.2f}'.format(round(fps_to_mps(point.velocity), 2))
if displayconf['Velocity - mps']:
fieldlist.append(velm)
ke = '{:.2f}'.format(round(point.kinetic_energy, 2))
if displayconf['Kinetic Energy']:
fieldlist.append(ke)
combinedtable.add_row(*fieldlist)
console.print(combinedtable)
#for point in hold_overs.points:
# if not float(point.yards).is_integer() and \
# not float(point.meters).is_integer():
# print("yards: %s meters: %s" % point.yards, point.meters)
# else:
# print("nope")
#print()
#for point in hold_overs.points:
# exec("print(point.%s)" % (tempdict["rangetype"]))
#print("end")