-
Notifications
You must be signed in to change notification settings - Fork 0
/
func_calc_fuel_burn.py
79 lines (62 loc) · 1.79 KB
/
func_calc_fuel_burn.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
#!/usr/bin/env python
__version__ = "20210129"
__author__ = "Decaff_42"
__copyright__ = "2021 by Decaff_42"
__license__ = """Only non-commercial use with attribution is allowed without
prior written permission from Decaff_42."""
"""
VERSION HISTORY:
20190114 - Original Release
20210129 - Re-formatting IAW PEPs. Breaks interactions with legacy code.
"""
import re
def get_fuel_burn_total(dat, avg_fuel):
"""
Estimate the fuel burned by the aircraft.
"""
# Get dat file values for burn rates.
fuel_mil = ""
fuel_afterburner = ""
for line in dat:
if line.startswith("FUELMILI"):
fuel_mil = determine_fuel_rate(line)
elif line.startswith("FUELABRN"):
fab = determine_fuel_rate(line)
if fuel_mil != "" and fuel_afterburner != "":
break
if fuel_mil == "":
fuel_mil = 0
if fuel_afterburner == "":
fuel_afterburner = 0
avg_thr = avg_fuel[0]/99
mil_time = avg_fuel[1]
ab_time = avg_fuel[2]
# Calculate total fuel burn.
fuel = 0
fuel += float(fuel_mil) * float(avg_thr) * float(mil_time)
fuel += float(fuel_afterburner) * float(ab_time)
fuel = int(fuel)
return fuel
def determine_fuel_rate(line):
"""find what units are in the burn rate strings."""
units = ["t", "lb", "kg"]
line = line.split()
unit = ""
chars = "abcdefghijklmnopqrstuvwxyz"
# Get units.
for i in units:
if i in line[1]:
unit = i
break
# Get burn rate as float
rate = line[1]
rate = re.sub('[^.0-9]', '', rate)
rate = float(rate)
# Convert burn rate to kg.
if unit == "t":
rate = rate * 2000
elif unit == "lb":
rate = rate * 0.453592
else:
rate = rate
return rate