Update column names in XSY module.

This commit is contained in:
2026-11-05 22:03:40 -06:00
parent af6d214e5a
commit c62bac9d7e
3 changed files with 51 additions and 28 deletions

View File

@@ -1,30 +1,40 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- <!--
Flatten a ControlExpert XSY file so that it can be read by pandas. Flatten a ControlExpert XSY file so that it can be read by pandas.
Copyright 2026 Prime Controls. All rights reserved. Copyright 2026 Prime Controls. All rights reserved.
--> -->
<xsl:output encoding="utf8" method="xml" omit-xml-declaration="no" indent="yes"/> <xsl:output encoding="utf8" method="xml" omit-xml-declaration="no" indent="yes" />
<xsl:template match="/VariablesExchangeFile"> <xsl:template match="/VariablesExchangeFile">
<xsl:copy> <xsl:copy>
<xsl:apply-templates select="dataBlock"/> <xsl:apply-templates select="dataBlock" />
</xsl:copy> </xsl:copy>
</xsl:template> </xsl:template>
<xsl:template match="dataBlock"> <xsl:template match="dataBlock">
<xsl:apply-templates select="variables"/> <xsl:apply-templates select="variables" />
</xsl:template> </xsl:template>
<xsl:template match="variables"> <xsl:template match="variables">
<xsl:copy> <xsl:copy>
<name><xsl:value-of select="@name"/></name> <tagname>
<type><xsl:value-of select="@typeName"/></type> <xsl:value-of select="@name" />
<address><xsl:value-of select="@topologicalAddress"/></address> </tagname>
<comment><xsl:value-of select="comment"/></comment> <type>
<parent/> <xsl:value-of select="@typeName" />
<bitrank/> </type>
<save><xsl:value-of select="attribute/@Save"/></save> <address>
<xsl:value-of select="@topologicalAddress" />
</address>
<comment>
<xsl:value-of select="comment" />
</comment>
<parent />
<bitrank />
<save>
<xsl:value-of select="attribute/@Save" />
</save>
</xsl:copy> </xsl:copy>
</xsl:template> </xsl:template>

View File

@@ -1,5 +1,5 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- <!--
Flatten a ControlExpert XSY file so that it can be read by pandas. Flatten a ControlExpert XSY file so that it can be read by pandas.
Copyright 2026 Prime Controls. All rights reserved. Copyright 2026 Prime Controls. All rights reserved.
@@ -8,41 +8,49 @@
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'" /> <xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" /> <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:output encoding="utf8" method="xml" omit-xml-declaration="no" indent="yes"/> <xsl:output encoding="utf8" method="xml" omit-xml-declaration="no" indent="yes" />
<xsl:template match="/VariablesExchangeFile"> <xsl:template match="/VariablesExchangeFile">
<xsl:copy> <xsl:copy>
<xsl:apply-templates select="DDTSource"/> <xsl:apply-templates select="DDTSource" />
<xsl:apply-templates select="FBSource"/> <xsl:apply-templates select="FBSource" />
</xsl:copy> </xsl:copy>
</xsl:template> </xsl:template>
<xsl:template match="DDTSource"> <xsl:template match="DDTSource">
<xsl:apply-templates select="structure/variables"/> <xsl:apply-templates select="structure/variables" />
</xsl:template> </xsl:template>
<xsl:template match="structure/variables"> <xsl:template match="structure/variables">
<xsl:copy> <xsl:copy>
<name><xsl:value-of select="@name"/></name> <tagname>
<type><xsl:value-of select="translate(@typeName, $lowercase, $uppercase)"/></type> <xsl:value-of select="@name" />
<address/> </tagname>
<comment><xsl:value-of select="../../comment"/>: <xsl:value-of select="comment"/></comment> <type>
<parent><xsl:value-of select="translate(../../@DDTName, $lowercase, $uppercase)"/></parent> <xsl:value-of select="translate(@typeName, $lowercase, $uppercase)" />
</type>
<address />
<comment><xsl:value-of select="../../comment" />: <xsl:value-of select="comment" /></comment>
<parent>
<xsl:value-of select="translate(../../@DDTName, $lowercase, $uppercase)" />
</parent>
<bitrank> <bitrank>
<xsl:for-each select="attribute"> <xsl:for-each select="attribute">
<xsl:if test="@name='ExtractBit'"> <xsl:if test="@name='ExtractBit'">
<xsl:value-of select="@value"/> <xsl:value-of select="@value" />
</xsl:if> </xsl:if>
</xsl:for-each> </xsl:for-each>
</bitrank> </bitrank>
<save/> <save />
</xsl:copy> </xsl:copy>
</xsl:template> </xsl:template>
<xsl:template match="FBSource"> <xsl:template match="FBSource">
<xsl:copy> <xsl:copy>
<name>NULL</name> <name>NULL</name>
<parent><xsl:value-of select="translate(@nameOfFBType, $lowercase, $uppercase)"/></parent> <parent>
<xsl:value-of select="translate(@nameOfFBType, $lowercase, $uppercase)" />
</parent>
<type>DFB</type> <type>DFB</type>
</xsl:copy> </xsl:copy>
</xsl:template> </xsl:template>

View File

@@ -405,15 +405,15 @@ class XSY:
"""Compile a cross-joined and filtered DataBlock by combining the """Compile a cross-joined and filtered DataBlock by combining the
columns from the datablock with the columns from the definitions.""" columns from the datablock with the columns from the definitions."""
datablock_compiled = pd.DataFrame() datablock_compiled = pd.DataFrame()
datablock_compiled["name"] = datablock.apply( datablock_compiled["tagname"] = datablock.apply(
lambda row: f"{row['name']}.{row['name_def']}", axis=1 lambda row: f"{row['tagname']}.{row['tagname_def']}", axis=1
) )
datablock_compiled["parent"] = ""
datablock_compiled["type"] = datablock["type_def"] datablock_compiled["type"] = datablock["type_def"]
datablock_compiled["address"] = datablock.apply( datablock_compiled["address"] = datablock.apply(
lambda row: self._combine_addresses(row), lambda row: self._combine_addresses(row),
axis=1, axis=1,
) )
datablock_compiled["parent"] = ""
datablock_compiled["bitrank"] = datablock["bitrank_def"] datablock_compiled["bitrank"] = datablock["bitrank_def"]
datablock_compiled["save"] = datablock["save"] datablock_compiled["save"] = datablock["save"]
datablock_compiled["comment"] = datablock.apply( datablock_compiled["comment"] = datablock.apply(
@@ -573,7 +573,12 @@ class XSYReader:
self.definitions_ss_path = definitions_ss_path self.definitions_ss_path = definitions_ss_path
self.even_addresses = even_addresses self.even_addresses = even_addresses
def read(self, path: Traversable, expand: bool = True) -> XSYBlock: def read(
self,
path: Traversable,
expand: bool = True,
converters=None,
) -> XSYBlock:
"""Read the dataBlock and definitions of an XSY file into an XSY """Read the dataBlock and definitions of an XSY file into an XSY
object. object.
""" """