Erste Version

This commit is contained in:
2025-06-02 18:23:17 +02:00
commit 4eb648d712
8 changed files with 376 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
import csv
import os.path
# noinspection SpellCheckingInspection
class CsvDialect (csv.Dialect):
lineterminator='\r\n'
delimiter = ','
quotechar = '"'
quoting=csv.QUOTE_NONNUMERIC
class ComponentReader:
def __init__(self):
self._inner_structure_data = {}
self._reactor_data = {}
self._weapon_data = {}
with open(os.path.join(os.path.dirname(__file__), 'tabellen', 'bauteile.csv')) as csvfile:
component_reader = csv.DictReader(csvfile, dialect=CsvDialect)
for row in component_reader:
self._inner_structure_data[float(row['GTonnage'])] = row
with open(os.path.join(os.path.dirname(__file__), 'tabellen', 'reaktoren.csv')) as csvfile:
component_reader = csv.DictReader(csvfile, dialect=CsvDialect)
for row in component_reader:
self._reactor_data[float(row['RW'])] = row
with open(os.path.join(os.path.dirname(__file__), 'tabellen', 'waffen.csv')) as csvfile:
component_reader = csv.DictReader(csvfile, dialect=CsvDialect)
for row in component_reader:
self._weapon_data[row['Waffentyp']] = row
def inner_structure_from(self, tonnage: float) -> float:
return float(self._inner_structure_data.get(tonnage, {}).get('Tonnage IS', 0.0))
def reactor_tonnage_from(self, reactor_value: int) -> float:
return float(self._reactor_data.get(reactor_value, {}).get('Tonnage', 0.0))