summaryrefslogtreecommitdiff
path: root/evaluator/evaluator.py
diff options
context:
space:
mode:
authorblendoit <blendoit@gmail.com>2019-10-21 21:25:52 -0700
committerblendoit <blendoit@gmail.com>2019-10-21 21:25:52 -0700
commit5ab73817371c1b4fedbd98838d3cf28984d73004 (patch)
treedb564394fa4db6db703738c469790d63d09e945b /evaluator/evaluator.py
parent5e82dedea4c56eafc1bba4f3ec8677b15f51c03f (diff)
Correct implem. of evaluator.analyze_all & Evaluator declassification
Diffstat (limited to 'evaluator/evaluator.py')
-rw-r--r--evaluator/evaluator.py71
1 files changed, 30 insertions, 41 deletions
diff --git a/evaluator/evaluator.py b/evaluator/evaluator.py
index b2b6e18..18bb692 100644
--- a/evaluator/evaluator.py
+++ b/evaluator/evaluator.py
@@ -1,48 +1,37 @@
"""
-The evaluator.py module contains a single Evaluator class,
-which knows all the attributes of a specified Aircraft instance,
-and contains functions to analyse the airfoil's geometrical
-& structural properties.
+The evaluator.py module contains functions
+that return calculated data for an aircraft.
+Plotting aircraft components is also possible.
"""
-import sys
import os.path
-import matplotlib.pyplot as plt
import concurrent.futures
-import logging
+import matplotlib.pyplot as plt
from . import drag, inertia, lift, mass
-import generator
-
-logging.basicConfig(filename='log_eval.txt',
- level=logging.DEBUG,
- format='%(asctime)s - %(levelname)s - %(message)s')
-
-
-class Evaluator:
- """Performs structural evaluations on aircrafts.
- Individual aircrafts must claim an Evaluator object as parent."""
- def __init__(self, name):
- self.name = name
- self.aircrafts = []
- self.results = []
- self.I_ = {'x': 0, 'z': 0, 'xz': 0}
- def analyze(self, aircraft):
- """Analyze a single aircraft."""
- aircraft.results.update({'Lift': lift.get_lift_total(aircraft)})
- aircraft.results.update({'Drag': drag.get_drag_total(aircraft)})
- aircraft.results.update({'Mass': mass.get_mass_total(aircraft)})
- aircraft.results.update({'Centroid': inertia.get_centroid(aircraft)})
- return aircraft.results
-
- def analyze_all(self):
- """Perform all analysis calculations on a all aircraft in evaluator."""
- with concurrent.futures.ProcessPoolExecutor() as executor:
- executor.map(self.analyze, self.aircrafts)
-
- return None
+def analyze(aircraft):
+ """Analyze a single aircraft."""
+ results = {
+ 'Lift': lift.get_lift_total(aircraft),
+ 'Drag': drag.get_drag_total(aircraft),
+ 'Mass': mass.get_mass_total(aircraft),
+ 'Centroid': inertia.get_centroid(aircraft)
+ }
+ aircraft.results = results
+ return aircraft.name, results
+
+
+def analyze_all(population):
+ """Analyze all aircraft in a given population."""
+ # for aircraft in population.aircrafts:
+ # print(analyze(aircraft))
+ with concurrent.futures.ProcessPoolExecutor() as executor:
+ results = executor.map(analyze, population.aircrafts)
+ for result in results:
+ print(result)
+ return None
# def analysis(self, V_x, V_z):
# """Perform all analysis calculations and store in class instance."""
@@ -85,13 +74,13 @@ class Evaluator:
# self.spar.cap_area)
# return None
- def tree_print(self, *aircrafts):
+ def tree_print(self, population):
"""Print the list of subcomponents."""
- name = f" TREE FOR {[i.name for i in aircrafts]} IN {self.name} "
+ name = f" TREE FOR {[i.name for i in population.aircraft]} IN {self.name} "
num_of_dashes = len(name)
print(num_of_dashes * '-')
print(name)
- for aircraft in aircrafts:
+ for aircraft in population:
print(".")
print(f"`-- {aircraft}")
print(f" |--{aircraft.wing}")
@@ -105,10 +94,10 @@ class Evaluator:
return None
def tree_save(self,
- *aircrafts,
+ population,
save_path='/home/blendux/Projects/Aircraft_Studio/save'):
"""Save the evaluator's tree to a file."""
- for aircraft in aircrafts:
+ for aircraft in population.aircraft:
file_name = f"{aircraft.name}_tree.txt"
full_path = os.path.join(save_path, file_name)
with open(full_path, 'w') as f:
Copyright 2019--2024 Marius PETER