-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBallistics.py
More file actions
95 lines (79 loc) · 3.22 KB
/
Ballistics.py
File metadata and controls
95 lines (79 loc) · 3.22 KB
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
import pandas as pd
from pathlib import Path
import os
from xlrd import open_workbook, XLRDError
class Ballistics:
def __init__(self, csv='./ballistics.csv', min_range=-1, max_range=-1, step=-1, range_col='Range', cols=[]):
csv_file = Path(csv)
if csv_file.is_file():
#print("File Found")
filename = os.path.split(csv)
ext = filename[1].split('.')
ext = ext[len(ext) - 1]
#print(filename[1], ext)
if ext == 'csv':
self.orig_ballistics = self.ballistics = pd.read_csv(csv)
elif ext == 'xls' or ext == 'xlsx':
try:
open_workbook(csv)
except XLRDError:
self.orig_ballistics = self.ballistics = pd.DataFrame()
print("Not A Invalid Excel File!")
else:
self.orig_ballistics = self.ballistics = pd.read_excel(csv)
else:
self.orig_ballistics = self.ballistics = pd.DataFrame()
print("Invalid File: Load CSV or Excel")
else:
self.orig_ballistics = self.ballistics = pd.DataFrame()
self.range_col = range_col
self.setrange(min_range, max_range)
self.selectcolumns(cols)
def setorigballistics(self, b):
self.orig_ballistics = b
def reset(self):
self.ballistics = self.orig_ballistics
def setrange(self, min_range=-1, max_range=-1, step=-1):
min_ranges = pd.DataFrame()
max_ranges = pd.DataFrame()
step_ranges = pd.DataFrame()
if max_range > 0:
max_ranges = self.ballistics[self.range_col] <= max_range
if min_range > 0:
min_ranges = self.ballistics[self.range_col] >= min_range
if step > 0:
step_ranges = self.ballistics[self.range_col] % step == 0
if not min_ranges.empty and not max_ranges.empty:
self.ballistics = self.ballistics[min_ranges & max_ranges]
elif not min_ranges.empty:
self.ballistics = self.ballistics[min_ranges]
elif not max_ranges.empty:
self.ballistics = self.ballistics[max_ranges]
if not step_ranges.empty:
self.ballistics = self.ballistics[step_ranges]
def selectcolumns(self, cols):
if len(cols) > 0:
self.ballistics = self.ballistics.iloc[:, cols]
#print(self.ballistics.iloc[:, cols])
def setrangecol(self, range_col):
if range_col:
self.range_col = range_col
def genballisticscsv(self):
csv_file = Path("./ballistics.csv")
if not csv_file.is_file():
file = open(csv_file, 'w')
file.write('Range,Velocity,Energy,Trajectory,MOA,MILS')
file.close()
else:
print("Ballistics File Exists")
def getballistics(self):
df1 = pd.read_csv('./ballistics.csv')
# df2=df1.set_index("Range")
start_range = 100
end_range = 500
range_col = 'Range'
mm_col = 'Come Up (MILS)'
# for index, row in df1.iterrows():
# if row[range_col] >= start_range and row[range_col] <= end_range:
# print(row[range_col], row[mm_col])
return df1