mehrere oft verwendete Routinen in eigene utils.py eingebaut

This commit is contained in:
2026-01-23 10:23:18 +01:00
parent 37208f61b1
commit 3deebb81f3
9 changed files with 453 additions and 175 deletions
+2 -16
View File
@@ -8,24 +8,10 @@ import os
import configparser
import matplotlib.pyplot as plt
from utils import load_json, to_json, write_results
# Funktionen
def load_json(jsonfilename):
with open(jsonfilename, encoding='utf-8') as fh:
return json.load(fh)
def write_results(jsnResults, outdir, filename):
""" write results to a json file
"""
print("writing results to a json file ...")
outfile = Path(outdir) / filename
with open(outfile, 'w', encoding='utf-8') as fh:
fh.write(jsnResults)
print("done")
def to_json(d, pretty: bool = True) -> str:
return json.dumps(d, indent=2 if pretty else None, ensure_ascii=False, default=str) #ensure_ascii false für darstellung von "ue"
def create_plant(racks:dict, sensors:dict, distributors:dict, mapping:dict, tunnels: dict, tunlength:dict ) -> dict:
# racks = {'Rack_1-0': [Point(0, 0), Point(0, 10)],