Files
Rieter-EKalk/lib/calc_site.py
T
2023-06-06 16:35:41 +02:00

159 lines
6.1 KiB
Python

import rieter_ekalk as rek
import pandas as pd
import argparse
import os
import configparser
class cfg():
"""
Liest die config-Datei ein, in der Stückpreise und Zeiteinheiten pro Bauteil wie in der rieter_ekalk Excel-Datei verwendet angegeben sind, und schreibt sie in ein Dictionary.
"""
def __init__(self, path="Sivas_Daten.cfg"):
"""
:param path: Die config-Datei, in der Stückpreise und Zeiteinheiten der jeweiligen Bauteile aufgelistet sind z.B.[HW_Einzelpreise]
# Schaltschrank Einzelpreis
schaltschrankgehaeuse_b1x800_zubehoer = 2000
"""
self._hasConfig = True
if os.path.exists(path):
self._cfg = configparser.ConfigParser(inline_comment_prefixes="#")
self._cfg.optionxform = str
self._cfg.read_file(open(path))
else:
self._hasConfig = False
self._cfg = None
def exists(self):
return self._hasConfig
def isfloat(self, num):
try:
float(num)
return True
except ValueError:
return False
def getTypedDict(self, section:str):
"""
Schreibt die Zuordnungen von Bauteil:Stückpreis/Zeiteinheit (je nach gewählter Überschrift) aus der config-Datei in ein Dictionary.
:param section: Überschrift in der config-Datei z.B. "HW_Einzelpreise"
"""
if section not in self._cfg.sections():
return dict()
res = dict()
for key, val in self._cfg.items(section):
if val.lower() in ['true']:
res[key] =True
elif val.lower() in ['false']:
res[key] =False
elif val.startswith("-"):
res[key] = float(val)
elif self.isfloat(val):
res[key] = float(val)
else:
res[key] = val
return res
def run_calc(infile, outfile, SivasConfig):
infileCfg = cfg(infile)
Anzahl_MG = infileCfg.getTypedDict("allgemein")
rsm_direct_eingabe = infileCfg.getTypedDict("rsm_direct")
rsm_fa_eingabe = infileCfg.getTypedDict("rsm_fa")
flyer_f40_eingabe = infileCfg.getTypedDict("flyer_f40")
neuenhauser_eingabe = infileCfg.getTypedDict("neuenhauser")
flyer_eingabe = infileCfg.getTypedDict("flyer")
verbindungsstrecken_w_eingabe = infileCfg.getTypedDict("verbindungsstrecken_w")
puffer_eingabe = infileCfg.getTypedDict("puffer")
turm_eingabe = infileCfg.getTypedDict("turm")
mg = rek.MG(Anzahl_MG,
rsm_direct=rsm_direct_eingabe,
rsm_fa=rsm_fa_eingabe,
flyer_f40=flyer_f40_eingabe,
neuenhauser=neuenhauser_eingabe,
flyer=flyer_eingabe,
verbindungsstrecken_w=verbindungsstrecken_w_eingabe,
puffer=puffer_eingabe,
turm=turm_eingabe)
anStr = SivasConfig.getTypedDict("Antriebsstrom")
cosPhi = SivasConfig.getTypedDict("cos phi")
al = rek.Anschlussl(anStr, cosPhi)
Anzahl_AL ={}
al.calc(Anzahl_AL, mg)
# self.assertEqual(al._ANZAHL.get("Anzahl_Motor"), 48)
# self.assertAlmostEqual(al._ANZAHL.get("Summe_Strom_Motor"), 26.4)
# self.assertAlmostEqual(al._ANZAHL.get("Summe_Strom_Motor_SPS_Peripherie"), 29.4)
# self.assertAlmostEqual(al._ANZAHL.get("GZF"), 16.2)
# self.assertAlmostEqual(al._ANZAHL.get("Res"), 1.62)
# self.assertAlmostEqual(al._ANZAHL.get("Gesamtstrom"), 17.82)
# self.assertAlmostEqual(al._Anschlussspannung, 400)
# self.assertAlmostEqual(al._ANZAHL.get("Leistung"), 12.345696)
# self.assertAlmostEqual(al._ANZAHL.get("Gesamtanschlussleistung"), 13)
Anzahl_EAS = infileCfg.getTypedDict("EAS")
eas = rek.EA(Anzahl_EAS, mg)
Anzahl_HW = infileCfg.getTypedDict("HW")
hwep = SivasConfig.getTypedDict("HW_Einzelpreise")
hwhp = SivasConfig.getTypedDict("HW_Zeiten Hardwareplanung")
hwzew = SivasConfig.getTypedDict("HW_Zeiten Elektro-Werkstatt")
hw = rek.HW(hwep, hwhp, hwzew)
hw.calc(Anzahl_HW, mg, eas)
emoz = SivasConfig.getTypedDict("Elektro-Montagezeiten")
emo = rek.EMO(emoz)
emo.calc(eas, hw, mg)
Anzahl_DL = infileCfg.getTypedDict("DL")
dl = rek.Dienstleistung(Anzahl_DL, hw)
Anzahl_Ergebnis = infileCfg.getTypedDict("Ergebnis")
kph = SivasConfig.getTypedDict("Kosten pro h")
erg = rek.Ergebnis(kph)
erg.calc(Anzahl_Ergebnis, hw, dl, emo)
summary = erg.summary_costs(hw)
df = pd.DataFrame.from_dict(data=summary, orient='index', columns=['Aufwand'])
df.to_excel(outfile, sheet_name="Kostenaufstellung")
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='calculation of a system according to Bös', prog='ecalc')
parser.add_argument('-i', '--infile', action='store', help='name of the input file', default="jayjay.cfg")
parser.add_argument('-o', '--outfile', action='store', help='name of the output .xlsx file. If none given, name of the input file is used.')
parser.add_argument('-c', '--config', action='store', help='name of the config file inside of cfg folder to use. Default is Sivas_Daten.cfg', default="Sivas_Daten.cfg")
args = parser.parse_args()
sivasCfgFilePath = os.path.join(os.environ.get('ECALC_CFG'), args.config)
RieterConfig = cfg(sivasCfgFilePath)
inFilePath = os.path.join(os.environ.get('ECALC_WORK'), args.infile)
if os.path.isfile(inFilePath):
if args.outfile:
outPath = os.path.join(os.environ.get('ECALC_WORK'), args.outfile)
else:
(fname, ext) = os.path.splitext(args.infile)
outPath = os.path.join(os.environ.get('ECALC_WORK'), fname + '.xlsx')
run_calc(inFilePath, outPath, RieterConfig)
else:
print("no such file in ECALC_WORK")
# os.environ.get('ECALC_BIN')
# os.environ.get('ECALC_WORK')
# os.environ.get('ECALC_CFG')
# os.environ.get('ECALC_LIB')