Start writing expand_datablock method.
This commit is contained in:
@@ -8,7 +8,7 @@ import pandas as pd
|
|||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
|
|
||||||
import AuDaGe
|
import AuDaGe
|
||||||
from AuDaGe.iec import datatypes, ElementaryVariable, UDT
|
from AuDaGe.iec import DataTypes, ElementaryVariable, UDT
|
||||||
|
|
||||||
class XSY():
|
class XSY():
|
||||||
"""Schneider Electric EcoStruxure Control Expert variable exchange file
|
"""Schneider Electric EcoStruxure Control Expert variable exchange file
|
||||||
@@ -53,26 +53,26 @@ class XSY():
|
|||||||
]
|
]
|
||||||
self.datablock = self._read_datablock()
|
self.datablock = self._read_datablock()
|
||||||
self.defs: DataFrame = self._read_defs()
|
self.defs: DataFrame = self._read_defs()
|
||||||
|
self.datablock_expanded = self._expand_datablock()
|
||||||
|
|
||||||
def __fspath__(self) -> os.path:
|
def __fspath__(self) -> os.path:
|
||||||
return self.xsy_path
|
return self.xsy_path
|
||||||
|
|
||||||
def _expand_datablock(self) -> DataFrame:
|
def _expand_datablock(self) -> DataFrame:
|
||||||
# Consider df.explode here.
|
# Consider df.explode here.
|
||||||
self.datablock = self.datablock.set_index('type').join(
|
self.datablock.set_index("type")
|
||||||
self.defs.set_index('parent'),
|
datablock = (
|
||||||
# how = 'cross',
|
self.datablock
|
||||||
lsuffix = 'db',
|
.join(
|
||||||
rsuffix = 'ddt',
|
self.defs,
|
||||||
|
how="cross",
|
||||||
|
rsuffix="_def"
|
||||||
|
)
|
||||||
|
.query(
|
||||||
|
"type==parent_def"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
return self.datablock
|
return datablock
|
||||||
|
|
||||||
# def _read(self) -> DataFrame:
|
|
||||||
# """Read *and* expand the dataBlock using the definitions within the XSY
|
|
||||||
# file and from the external definition files, if provided.
|
|
||||||
# """
|
|
||||||
# pass
|
|
||||||
|
|
||||||
def _read_datablock(self) -> DataFrame:
|
def _read_datablock(self) -> DataFrame:
|
||||||
"""Read the dataBlock of an XSY file into a dataframe."""
|
"""Read the dataBlock of an XSY file into a dataframe."""
|
||||||
@@ -80,19 +80,19 @@ class XSY():
|
|||||||
open(self.xsy_path) as xsy_file,
|
open(self.xsy_path) as xsy_file,
|
||||||
open(self.db_ss_path) as ss_file
|
open(self.db_ss_path) as ss_file
|
||||||
):
|
):
|
||||||
self.datablock = pd.read_xml(xsy_file, stylesheet=ss_file)
|
datablock = pd.read_xml(xsy_file, stylesheet=ss_file)
|
||||||
return self.datablock
|
return datablock
|
||||||
|
|
||||||
def _read_defs(self) -> DataFrame:
|
def _read_defs(self) -> DataFrame:
|
||||||
"""Read the DDTSource nodes of an XSY file into a dataframe."""
|
"""Read the DDTSource nodes of an XSY file into a dataframe."""
|
||||||
self.def_paths.append(self.xsy_path)
|
self.def_paths.append(self.xsy_path)
|
||||||
defs = DataFrame()
|
defs: list[DataFrame] = []
|
||||||
with open(self.ddt_ss_path) as ss_file:
|
with open(self.ddt_ss_path) as ss_file:
|
||||||
for def_path in self.def_paths:
|
for def_path in self.def_paths:
|
||||||
with open(def_path) as def_file:
|
with open(def_path) as def_file:
|
||||||
def_df = pd.read_xml(def_file, stylesheet = ss_file)
|
def_df = pd.read_xml(def_file, stylesheet = ss_file)
|
||||||
defs = pd.concat([defs, def_df])
|
defs.append(def_df)
|
||||||
return defs
|
return pd.concat(defs)
|
||||||
|
|
||||||
def write(self, ):
|
def write(self, ):
|
||||||
"""Write dataframe to XSY file."""
|
"""Write dataframe to XSY file."""
|
||||||
|
|||||||
@@ -10,5 +10,15 @@ def test_init():
|
|||||||
def test_export():
|
def test_export():
|
||||||
xsy = XSY("tests/data/hsps.xsy")
|
xsy = XSY("tests/data/hsps.xsy")
|
||||||
out_path = "tests/output"
|
out_path = "tests/output"
|
||||||
xsy.datablock.to_csv(os.path.join(out_path, 'test_db.csv'), index=False)
|
xsy.datablock.to_csv(
|
||||||
xsy.defs.to_csv(os.path.join(out_path, 'test_ddt.csv'), index=False)
|
os.path.join(out_path, 'datablock.csv'),
|
||||||
|
index=False
|
||||||
|
)
|
||||||
|
xsy.defs.to_csv(
|
||||||
|
os.path.join(out_path, 'defs.csv'),
|
||||||
|
index=False
|
||||||
|
)
|
||||||
|
xsy.datablock_expanded.to_csv(
|
||||||
|
os.path.join(out_path, 'expanded.csv'),
|
||||||
|
index=False
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user