File size: 1,469 Bytes
507714c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # SPDX-License-Identifier: MIT - Copyright (c) 2026 Novaeon
"""Streaming-Konvertierung BPIC 2019 XES -> Parquet (stdlib iterparse, wenig RAM)."""
import sys, xml.etree.ElementTree as ET, pandas as pd
src, dst = sys.argv[1], sys.argv[2]
NS = "{http://www.xes-standard.org/}"
rows, trace_attrs, in_trace = [], {}, False
def attrs(el):
return {c.get("key"): c.get("value") for c in el if c.tag.split("}")[-1] in ("string", "date", "float", "int", "boolean")}
for ev, el in ET.iterparse(src, events=("start", "end")):
tag = el.tag.split("}")[-1]
if ev == "start" and tag == "trace": in_trace, trace_attrs = True, None
elif ev == "end" and tag == "event" and in_trace:
a = attrs(el); a["_event"] = True; rows.append(a); el.clear()
elif ev == "end" and tag == "trace":
t = attrs(el)
# Trace-Attribute nachtragen (Events dieser Trace sind die letzten ohne 'case:concept:name')
i = len(rows) - 1
while i >= 0 and "case:concept:name" not in rows[i]:
for k, v in t.items(): rows[i]["case:" + k] = v
i -= 1
el.clear(); in_trace = False
df = pd.DataFrame(rows).drop(columns=["_event"])
df["time:timestamp"] = pd.to_datetime(df["time:timestamp"], utc=True, format="ISO8601")
if "Cumulative net worth (EUR)" in df: df["Cumulative net worth (EUR)"] = pd.to_numeric(df["Cumulative net worth (EUR)"], errors="coerce")
df.to_parquet(dst, index=False)
print(df.shape); print(df.columns.tolist())
|