Launch.json angepasst, sodass draw cable dxf from easy to new dxf ein neues dxf mit namen easy_cables schriebt. getexdraw.bat angepasst, sodass bei routing ein graph angezeigt wird und gespeichert werden kann (testweise). drawdxf.py angepasst, sodass eine excel ausgabe mit 2 Worksheets geschrieben wird.
This commit is contained in:
+34
-1
@@ -5,7 +5,10 @@ import os.path
|
||||
from dataclasses import dataclass, asdict, fields
|
||||
from dacite import from_dict
|
||||
from typing import List
|
||||
from datetime import datetime
|
||||
from datetime import datetime
|
||||
from openpyxl import Workbook
|
||||
import math
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +22,7 @@ class Point:
|
||||
class Polyline:
|
||||
id: str
|
||||
coords: List[Point]
|
||||
length: float
|
||||
|
||||
def to_tuple(self):
|
||||
ret = list()
|
||||
@@ -70,6 +74,11 @@ def new_dxf(json_file, out_path, dxf_file=False):
|
||||
|
||||
doc.saveas(out_path)
|
||||
|
||||
# Hier für Excel Export
|
||||
excel_path = out_path.replace(".dxf", "_kabellaengen.xlsx")
|
||||
write_excel_from_json(anlage, excel_path)
|
||||
|
||||
|
||||
def check_file_in_work(work_dir, filename):
|
||||
fexists = True
|
||||
if not os.path.exists(filename):
|
||||
@@ -80,6 +89,30 @@ def check_file_in_work(work_dir, filename):
|
||||
mypath = filename
|
||||
return (mypath, fexists)
|
||||
|
||||
def write_excel_from_json(anlage:Polylines, outpath:str):
|
||||
wb = Workbook()
|
||||
length_summary = defaultdict(int)
|
||||
|
||||
#Worksheet 1 - Kabellängen
|
||||
ws1 = wb.active
|
||||
ws1.title = "Kabellängen"
|
||||
ws1.append(["Kabel-ID", "Länge aus Json (m)", "Gerundete Länge (m)"])
|
||||
|
||||
for pl in anlage.kabel:
|
||||
length = pl.length /1000 # Umrechnung von mm in m
|
||||
rounded_len = math.ceil(length/10)*10
|
||||
length_summary[rounded_len] +=1
|
||||
ws1.append([pl.id, length, int(rounded_len)])
|
||||
|
||||
# Worksheet 2 - Zusammengefasste Längen
|
||||
ws2 = wb.create_sheet("Längenübersicht")
|
||||
ws2.append(["Gerundete Länge (m)", "Anzahl Kabel"])
|
||||
|
||||
for rlength in sorted(length_summary):
|
||||
ws2.append([int(rlength), length_summary[rlength]])
|
||||
|
||||
wb.save(outpath)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user