summaryrefslogtreecommitdiff
path: root/creator/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'creator/base.py')
-rw-r--r--creator/base.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/creator/base.py b/creator/base.py
new file mode 100644
index 0000000..91d4c70
--- /dev/null
+++ b/creator/base.py
@@ -0,0 +1,59 @@
+"""The base.py module contains parent classes for components."""
+import numpy as np
+import sys
+import os.path
+import logging
+
+logging.basicConfig(filename='log.txt',
+ level=logging.DEBUG,
+ format='%(asctime)s - %(levelname)s - %(message)s')
+
+
+class Component:
+ """Basic component providing coordinates and tools."""
+
+ # TODO: define defaults in separate module
+ def __init__(self):
+ self.x = np.array([])
+ self.z = np.array([])
+ self.material = str()
+ self.mass = float()
+
+ def set_material(self, material):
+ """Set the component bulk material."""
+ self.material = material
+
+ def info_print(self, round):
+ """Print all the component's coordinates to the terminal."""
+ name = f' CREATOR DATA FOR {str(self).upper()} '
+ num_of_dashes = len(name)
+ print(num_of_dashes * '-')
+ print(name)
+ for k, v in self.__dict__.items():
+ if type(v) != list:
+ print('{}:\n'.format(k), v)
+ print(num_of_dashes * '-')
+ for k, v in self.__dict__.items():
+ if type(v) == list:
+ print('{}:\n'.format(k), np.around(v, round))
+ return None
+
+ def info_save(self, save_path, number):
+ """Save all the object's coordinates (must be full path)."""
+ file_name = f'{str(self).lower()}_{number}.txt'
+ full_path = os.path.join(save_path, file_name)
+ try:
+ with open(full_path, 'w') as sys.stdout:
+ self.info_print(6)
+ # This line required to reset behavior of sys.stdout
+ sys.stdout = sys.__stdout__
+ logging.debug(f'Successfully wrote to file {full_path}')
+ except IOError:
+ print(f'Unable to write {file_name} to specified directory.\n',
+ 'Was the full path passed to the function?')
+ return None
+
+
+class Aircraft:
+ """This class tracks all sub-components and is fed to the evaluator."""
+ pass
Copyright 2019--2024 Marius PETER