adding old files
commit
91686ed5f7
|
|
@ -0,0 +1,377 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<AlteryxDocument yxmdVer="2021.4">
|
||||||
|
<Nodes>
|
||||||
|
<Node ToolID="1">
|
||||||
|
<GuiSettings Plugin="AlteryxBasePluginsGui.TextInput.TextInput">
|
||||||
|
<Position x="54" y="54" />
|
||||||
|
</GuiSettings>
|
||||||
|
<Properties>
|
||||||
|
<Configuration>
|
||||||
|
<NumRows value="3" />
|
||||||
|
<Fields>
|
||||||
|
<Field name="Column1" />
|
||||||
|
<Field name="Column 2" />
|
||||||
|
</Fields>
|
||||||
|
<Data>
|
||||||
|
<r>
|
||||||
|
<c>1</c>
|
||||||
|
<c>4</c>
|
||||||
|
</r>
|
||||||
|
<r>
|
||||||
|
<c>2</c>
|
||||||
|
<c>5</c>
|
||||||
|
</r>
|
||||||
|
<r>
|
||||||
|
<c>3</c>
|
||||||
|
<c>6</c>
|
||||||
|
</r>
|
||||||
|
</Data>
|
||||||
|
</Configuration>
|
||||||
|
<Annotation DisplayMode="0">
|
||||||
|
<Name />
|
||||||
|
<DefaultAnnotationText />
|
||||||
|
<Left value="False" />
|
||||||
|
</Annotation>
|
||||||
|
</Properties>
|
||||||
|
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxTextInput" />
|
||||||
|
</Node>
|
||||||
|
<Node ToolID="2">
|
||||||
|
<GuiSettings Plugin="AlteryxBasePluginsGui.AlteryxSelect.AlteryxSelect">
|
||||||
|
<Position x="186" y="54" />
|
||||||
|
</GuiSettings>
|
||||||
|
<Properties>
|
||||||
|
<Configuration>
|
||||||
|
<OrderChanged value="False" />
|
||||||
|
<CommaDecimal value="False" />
|
||||||
|
<SelectFields>
|
||||||
|
<SelectField field="Column1" selected="True" type="Int64" size="8" />
|
||||||
|
<SelectField field="Column 2" selected="False" type="WString" size="3" />
|
||||||
|
<SelectField field="*Unknown" selected="False" />
|
||||||
|
</SelectFields>
|
||||||
|
</Configuration>
|
||||||
|
<Annotation DisplayMode="0">
|
||||||
|
<Name />
|
||||||
|
<DefaultAnnotationText />
|
||||||
|
<Left value="False" />
|
||||||
|
</Annotation>
|
||||||
|
</Properties>
|
||||||
|
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxSelect" />
|
||||||
|
</Node>
|
||||||
|
<Node ToolID="3">
|
||||||
|
<GuiSettings Plugin="AlteryxBasePluginsGui.BrowseV2.BrowseV2">
|
||||||
|
<Position x="318" y="54" />
|
||||||
|
</GuiSettings>
|
||||||
|
<Properties>
|
||||||
|
<Configuration>
|
||||||
|
<TempFile>C:\Users\casey.morter\AppData\Local\Temp\Engine_1076_e92ddd5f524045a79cff90fef659b528_\Engine_33528_b9fe906502c14eb3ad38d38f04c81ab2_.yxdb</TempFile>
|
||||||
|
</Configuration>
|
||||||
|
<Annotation DisplayMode="0">
|
||||||
|
<Name />
|
||||||
|
<DefaultAnnotationText />
|
||||||
|
<Left value="False" />
|
||||||
|
</Annotation>
|
||||||
|
</Properties>
|
||||||
|
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxBrowseV2" />
|
||||||
|
</Node>
|
||||||
|
<Node ToolID="4">
|
||||||
|
<GuiSettings Plugin="AlteryxBasePluginsGui.TextInput.TextInput">
|
||||||
|
<Position x="54" y="246" />
|
||||||
|
</GuiSettings>
|
||||||
|
<Properties>
|
||||||
|
<Configuration>
|
||||||
|
<NumRows value="3" />
|
||||||
|
<Fields>
|
||||||
|
<Field name="Column 3" />
|
||||||
|
<Field name="Column 4" />
|
||||||
|
</Fields>
|
||||||
|
<Data>
|
||||||
|
<r>
|
||||||
|
<c>5</c>
|
||||||
|
<c>8</c>
|
||||||
|
</r>
|
||||||
|
<r>
|
||||||
|
<c>6</c>
|
||||||
|
<c>9</c>
|
||||||
|
</r>
|
||||||
|
<r>
|
||||||
|
<c>7</c>
|
||||||
|
<c>10</c>
|
||||||
|
</r>
|
||||||
|
</Data>
|
||||||
|
</Configuration>
|
||||||
|
<Annotation DisplayMode="0">
|
||||||
|
<Name />
|
||||||
|
<DefaultAnnotationText />
|
||||||
|
<Left value="False" />
|
||||||
|
</Annotation>
|
||||||
|
</Properties>
|
||||||
|
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxTextInput" />
|
||||||
|
</Node>
|
||||||
|
<Node ToolID="5">
|
||||||
|
<GuiSettings Plugin="AlteryxBasePluginsGui.AlteryxSelect.AlteryxSelect">
|
||||||
|
<Position x="174" y="246" />
|
||||||
|
</GuiSettings>
|
||||||
|
<Properties>
|
||||||
|
<Configuration>
|
||||||
|
<OrderChanged value="False" />
|
||||||
|
<CommaDecimal value="False" />
|
||||||
|
<SelectFields>
|
||||||
|
<SelectField field="Column 3" selected="True" rename="Col_3_renamed" />
|
||||||
|
<SelectField field="Column 4" selected="False" />
|
||||||
|
<SelectField field="*Unknown" selected="True" />
|
||||||
|
</SelectFields>
|
||||||
|
</Configuration>
|
||||||
|
<Annotation DisplayMode="0">
|
||||||
|
<Name />
|
||||||
|
<DefaultAnnotationText />
|
||||||
|
<Left value="False" />
|
||||||
|
</Annotation>
|
||||||
|
</Properties>
|
||||||
|
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxSelect" />
|
||||||
|
</Node>
|
||||||
|
<Node ToolID="6">
|
||||||
|
<GuiSettings Plugin="AlteryxBasePluginsGui.Formula.Formula">
|
||||||
|
<Position x="174" y="330" />
|
||||||
|
</GuiSettings>
|
||||||
|
<Properties>
|
||||||
|
<Configuration>
|
||||||
|
<FormulaFields>
|
||||||
|
<FormulaField expression="[Column 3] + 10" field="Column 4" size="1" type="Byte" />
|
||||||
|
</FormulaFields>
|
||||||
|
</Configuration>
|
||||||
|
<Annotation DisplayMode="0">
|
||||||
|
<Name />
|
||||||
|
<DefaultAnnotationText><![CDATA[Column 4 = [Column 3] + 10
|
||||||
|
]]></DefaultAnnotationText>
|
||||||
|
<Left value="False" />
|
||||||
|
</Annotation>
|
||||||
|
</Properties>
|
||||||
|
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxFormula" />
|
||||||
|
</Node>
|
||||||
|
<Node ToolID="7">
|
||||||
|
<GuiSettings Plugin="AlteryxBasePluginsGui.Join.Join">
|
||||||
|
<Position x="318" y="258" />
|
||||||
|
</GuiSettings>
|
||||||
|
<Properties>
|
||||||
|
<Configuration joinByRecordPos="False">
|
||||||
|
<JoinInfo connection="Left">
|
||||||
|
<Field field="Col_3_renamed" />
|
||||||
|
</JoinInfo>
|
||||||
|
<JoinInfo connection="Right">
|
||||||
|
<Field field="Column 3" />
|
||||||
|
</JoinInfo>
|
||||||
|
<SelectConfiguration>
|
||||||
|
<Configuration outputConnection="Join">
|
||||||
|
<OrderChanged value="False" />
|
||||||
|
<CommaDecimal value="False" />
|
||||||
|
<SelectFields>
|
||||||
|
<SelectField field="Right_Column 3" selected="True" rename="Right_Column 3" input="Right_" />
|
||||||
|
<SelectField field="Right_Column 4" selected="True" rename="Right_Column 4" input="Right_" />
|
||||||
|
<SelectField field="*Unknown" selected="True" />
|
||||||
|
</SelectFields>
|
||||||
|
</Configuration>
|
||||||
|
</SelectConfiguration>
|
||||||
|
</Configuration>
|
||||||
|
<Annotation DisplayMode="0">
|
||||||
|
<Name />
|
||||||
|
<DefaultAnnotationText />
|
||||||
|
<Left value="False" />
|
||||||
|
</Annotation>
|
||||||
|
</Properties>
|
||||||
|
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxJoin" />
|
||||||
|
</Node>
|
||||||
|
<Node ToolID="10">
|
||||||
|
<GuiSettings Plugin="AlteryxBasePluginsGui.BrowseV2.BrowseV2">
|
||||||
|
<Position x="414" y="342" />
|
||||||
|
</GuiSettings>
|
||||||
|
<Properties>
|
||||||
|
<Configuration>
|
||||||
|
<TempFile>C:\Users\casey.morter\AppData\Local\Temp\Engine_1076_e92ddd5f524045a79cff90fef659b528_\Engine_33528_96b3fed5c185423dafa9c8e54e621b39_.yxdb</TempFile>
|
||||||
|
</Configuration>
|
||||||
|
<Annotation DisplayMode="0">
|
||||||
|
<Name />
|
||||||
|
<DefaultAnnotationText />
|
||||||
|
<Left value="False" />
|
||||||
|
</Annotation>
|
||||||
|
</Properties>
|
||||||
|
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxBrowseV2" />
|
||||||
|
</Node>
|
||||||
|
<Node ToolID="11">
|
||||||
|
<GuiSettings Plugin="AlteryxBasePluginsGui.Formula.Formula">
|
||||||
|
<Position x="270" y="474" />
|
||||||
|
</GuiSettings>
|
||||||
|
<Properties>
|
||||||
|
<Configuration>
|
||||||
|
<FormulaFields>
|
||||||
|
<FormulaField expression="[Engine.TempFilePath]" field="Path" size="1073741823" type="V_WString" />
|
||||||
|
</FormulaFields>
|
||||||
|
</Configuration>
|
||||||
|
<Annotation DisplayMode="0">
|
||||||
|
<Name />
|
||||||
|
<DefaultAnnotationText><![CDATA[Path = [Engine.TempFilePath]
|
||||||
|
]]></DefaultAnnotationText>
|
||||||
|
<Left value="False" />
|
||||||
|
</Annotation>
|
||||||
|
</Properties>
|
||||||
|
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxFormula" />
|
||||||
|
</Node>
|
||||||
|
<Node ToolID="12">
|
||||||
|
<GuiSettings Plugin="AlteryxBasePluginsGui.Sample.Sample">
|
||||||
|
<Position x="150" y="474" />
|
||||||
|
</GuiSettings>
|
||||||
|
<Properties>
|
||||||
|
<Configuration>
|
||||||
|
<Mode>First</Mode>
|
||||||
|
<N>1</N>
|
||||||
|
<GroupFields orderChanged="False" />
|
||||||
|
</Configuration>
|
||||||
|
<Annotation DisplayMode="0">
|
||||||
|
<Name />
|
||||||
|
<DefaultAnnotationText>First 1</DefaultAnnotationText>
|
||||||
|
<Left value="False" />
|
||||||
|
</Annotation>
|
||||||
|
</Properties>
|
||||||
|
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxSample" />
|
||||||
|
</Node>
|
||||||
|
<Node ToolID="13">
|
||||||
|
<GuiSettings Plugin="AlteryxBasePluginsGui.BrowseV2.BrowseV2">
|
||||||
|
<Position x="366" y="474" />
|
||||||
|
</GuiSettings>
|
||||||
|
<Properties>
|
||||||
|
<Configuration>
|
||||||
|
<TempFile>C:\Users\casey.morter\AppData\Local\Temp\Engine_1076_e92ddd5f524045a79cff90fef659b528_\Engine_33528_7a751c4879e24850ab691e9dd40c3227_.yxdb</TempFile>
|
||||||
|
<TempFileDataProfiling />
|
||||||
|
<Layout>
|
||||||
|
<View1>
|
||||||
|
<Hints>
|
||||||
|
<Table />
|
||||||
|
</Hints>
|
||||||
|
</View1>
|
||||||
|
</Layout>
|
||||||
|
</Configuration>
|
||||||
|
<Annotation DisplayMode="0">
|
||||||
|
<Name />
|
||||||
|
<DefaultAnnotationText />
|
||||||
|
<Left value="False" />
|
||||||
|
</Annotation>
|
||||||
|
</Properties>
|
||||||
|
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxBrowseV2" />
|
||||||
|
</Node>
|
||||||
|
<Node ToolID="14">
|
||||||
|
<GuiSettings Plugin="AlteryxBasePluginsGui.DbFileOutput.DbFileOutput">
|
||||||
|
<Position x="522" y="258" />
|
||||||
|
</GuiSettings>
|
||||||
|
<Properties>
|
||||||
|
<Configuration>
|
||||||
|
<File MaxRecords="" FileFormat="0">.\SimpleWorkflowOut.csv</File>
|
||||||
|
<Passwords />
|
||||||
|
<FormatSpecificOptions>
|
||||||
|
<LineEndStyle>CRLF</LineEndStyle>
|
||||||
|
<Delimeter>,</Delimeter>
|
||||||
|
<ForceQuotes>False</ForceQuotes>
|
||||||
|
<HeaderRow>True</HeaderRow>
|
||||||
|
<CodePage>28591</CodePage>
|
||||||
|
<WriteBOM>True</WriteBOM>
|
||||||
|
</FormatSpecificOptions>
|
||||||
|
<MultiFile value="False" />
|
||||||
|
</Configuration>
|
||||||
|
<Annotation DisplayMode="0">
|
||||||
|
<Name />
|
||||||
|
<DefaultAnnotationText>SimpleWorkflowOut.csv</DefaultAnnotationText>
|
||||||
|
<Left value="False" />
|
||||||
|
</Annotation>
|
||||||
|
</Properties>
|
||||||
|
<EngineSettings EngineDll="AlteryxBasePluginsEngine.dll" EngineDllEntryPoint="AlteryxDbFileOutput" />
|
||||||
|
</Node>
|
||||||
|
</Nodes>
|
||||||
|
<Connections>
|
||||||
|
<Connection>
|
||||||
|
<Origin ToolID="1" Connection="Output" />
|
||||||
|
<Destination ToolID="2" Connection="Input" />
|
||||||
|
</Connection>
|
||||||
|
<Connection>
|
||||||
|
<Origin ToolID="2" Connection="Output" />
|
||||||
|
<Destination ToolID="3" Connection="Input" />
|
||||||
|
</Connection>
|
||||||
|
<Connection>
|
||||||
|
<Origin ToolID="4" Connection="Output" />
|
||||||
|
<Destination ToolID="5" Connection="Input" />
|
||||||
|
</Connection>
|
||||||
|
<Connection>
|
||||||
|
<Origin ToolID="4" Connection="Output" />
|
||||||
|
<Destination ToolID="6" Connection="Input" />
|
||||||
|
</Connection>
|
||||||
|
<Connection>
|
||||||
|
<Origin ToolID="4" Connection="Output" />
|
||||||
|
<Destination ToolID="12" Connection="Input" />
|
||||||
|
</Connection>
|
||||||
|
<Connection>
|
||||||
|
<Origin ToolID="5" Connection="Output" />
|
||||||
|
<Destination ToolID="7" Connection="Left" />
|
||||||
|
</Connection>
|
||||||
|
<Connection>
|
||||||
|
<Origin ToolID="6" Connection="Output" />
|
||||||
|
<Destination ToolID="7" Connection="Right" />
|
||||||
|
</Connection>
|
||||||
|
<Connection>
|
||||||
|
<Origin ToolID="7" Connection="Right" />
|
||||||
|
<Destination ToolID="10" Connection="Input" />
|
||||||
|
</Connection>
|
||||||
|
<Connection>
|
||||||
|
<Origin ToolID="7" Connection="Join" />
|
||||||
|
<Destination ToolID="14" Connection="Input" />
|
||||||
|
</Connection>
|
||||||
|
<Connection>
|
||||||
|
<Origin ToolID="11" Connection="Output" />
|
||||||
|
<Destination ToolID="13" Connection="Input" />
|
||||||
|
</Connection>
|
||||||
|
<Connection>
|
||||||
|
<Origin ToolID="12" Connection="Output" />
|
||||||
|
<Destination ToolID="11" Connection="Input" />
|
||||||
|
</Connection>
|
||||||
|
</Connections>
|
||||||
|
<Properties>
|
||||||
|
<Memory default="True" />
|
||||||
|
<GlobalRecordLimit value="0" />
|
||||||
|
<TempFiles default="True" />
|
||||||
|
<Annotation on="True" includeToolName="False" />
|
||||||
|
<ConvErrorLimit value="10" />
|
||||||
|
<ConvErrorLimit_Stop value="False" />
|
||||||
|
<CancelOnError value="False" />
|
||||||
|
<DisableBrowse value="False" />
|
||||||
|
<EnablePerformanceProfiling value="False" />
|
||||||
|
<PredictiveToolsCodePage value="1252" />
|
||||||
|
<DisableAllOutput value="False" />
|
||||||
|
<ShowAllMacroMessages value="False" />
|
||||||
|
<ShowConnectionStatusIsOn value="True" />
|
||||||
|
<ShowConnectionStatusOnlyWhenRunning value="True" />
|
||||||
|
<ZoomLevel value="0" />
|
||||||
|
<LayoutType>Horizontal</LayoutType>
|
||||||
|
<MetaInfo>
|
||||||
|
<NameIsFileName value="True" />
|
||||||
|
<Name>SimpleWorkflow</Name>
|
||||||
|
<Description />
|
||||||
|
<RootToolName />
|
||||||
|
<ToolVersion />
|
||||||
|
<ToolInDb value="False" />
|
||||||
|
<CategoryName />
|
||||||
|
<SearchTags />
|
||||||
|
<Author />
|
||||||
|
<Company />
|
||||||
|
<Copyright />
|
||||||
|
<DescriptionLink actual="" displayed="" />
|
||||||
|
<Example>
|
||||||
|
<Description />
|
||||||
|
<File />
|
||||||
|
</Example>
|
||||||
|
<WorkflowId value="4b1703ae-e2d2-4561-87f2-6dbbf2f085eb" />
|
||||||
|
<Telemetry>
|
||||||
|
<PreviousWorkflowId value="ae55589b-8289-49c6-a07c-a0dc053082f8" />
|
||||||
|
<OriginWorkflowId value="ae55589b-8289-49c6-a07c-a0dc053082f8" />
|
||||||
|
</Telemetry>
|
||||||
|
</MetaInfo>
|
||||||
|
<Events>
|
||||||
|
<Enabled value="True" />
|
||||||
|
</Events>
|
||||||
|
</Properties>
|
||||||
|
</AlteryxDocument>
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
Col_3_renamed,Right_Column 3,Right_Column 4
|
||||||
|
5,5,15
|
||||||
|
6,6,16
|
||||||
|
7,7,17
|
||||||
|
|
|
@ -0,0 +1,350 @@
|
||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Setup"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 23,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Open Alteryx XML into a string \n",
|
||||||
|
"\n",
|
||||||
|
"import polars as pl \n",
|
||||||
|
"import xml.etree.ElementTree as ET\n",
|
||||||
|
"\n",
|
||||||
|
"xml_file_path = \"./SimpleWorkflow/SimpleWorkflow.yxmd\"\n",
|
||||||
|
"tree = ET.parse(xml_file_path)\n",
|
||||||
|
"root = tree.getroot()\n",
|
||||||
|
"\n",
|
||||||
|
"xml_string = ET.tostring(root, encoding='unicode')\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 24,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Parse out nodes (tool data) into a dict\n",
|
||||||
|
"\n",
|
||||||
|
"def extract_tool_id_and_contents(xml_string):\n",
|
||||||
|
" root = ET.fromstring(xml_string)\n",
|
||||||
|
" results = []\n",
|
||||||
|
" for node in root.iter('Node'):\n",
|
||||||
|
" tool_id = node.attrib.get('ToolID')\n",
|
||||||
|
" content = ET.tostring(node, encoding='unicode')\n",
|
||||||
|
" results.append((tool_id, content))\n",
|
||||||
|
" return results\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"results = extract_tool_id_and_contents(xml_string)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Tool Functions"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 25,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def selectTool(df: pl.DataFrame, col_specs: dict):\n",
|
||||||
|
" \"\"\"\n",
|
||||||
|
" Reshape a Polars DataFrame by renaming and retyping columns according to the provided dictionary.\n",
|
||||||
|
"\n",
|
||||||
|
" Args:\n",
|
||||||
|
" df (pl.DataFrame): The input Polars DataFrame.\n",
|
||||||
|
" col_specs (dict): A dictionary where keys are column names in the original DataFrame,\n",
|
||||||
|
" and values are tuples containing the new column name and data type.\n",
|
||||||
|
"\n",
|
||||||
|
" Returns:\n",
|
||||||
|
" pl.DataFrame: The reshaped Polars DataFrame with renamed and retyped columns.\n",
|
||||||
|
" \"\"\"\n",
|
||||||
|
" for old_name, (new_name, dt) in col_specs.items():\n",
|
||||||
|
" df = df.rename({old_name: new_name})\n",
|
||||||
|
" if dt is not None:\n",
|
||||||
|
" df = df.with_column(pl.col(old_name).cast(dt))\n",
|
||||||
|
" return df"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Parsing Tool Config data"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 26,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def TextInputToDf(xml_string):\n",
|
||||||
|
" # Get XML for a Text input tool\n",
|
||||||
|
" root = ET.fromstring(results[3][1])\n",
|
||||||
|
" # Extract the field names\n",
|
||||||
|
" fields = [field.attrib['name'] for field in root.findall(\".//Fields/Field\")]\n",
|
||||||
|
" # Extract the data rows\n",
|
||||||
|
" data_rows = [[int(c.text) for c in row.findall(\"c\")] for row in root.findall(\".//Data/r\")]\n",
|
||||||
|
" # Create the polars dataframe\n",
|
||||||
|
" df = pl.DataFrame(data_rows, fields)\n",
|
||||||
|
" # Display the dataframe\n",
|
||||||
|
" return df"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 22,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"1 TextInput\n",
|
||||||
|
"shape: (3, 2)\n",
|
||||||
|
"┌──────────┬──────────┐\n",
|
||||||
|
"│ Column 3 ┆ Column 4 │\n",
|
||||||
|
"│ --- ┆ --- │\n",
|
||||||
|
"│ i64 ┆ i64 │\n",
|
||||||
|
"╞══════════╪══════════╡\n",
|
||||||
|
"│ 5 ┆ 8 │\n",
|
||||||
|
"│ 6 ┆ 9 │\n",
|
||||||
|
"│ 7 ┆ 10 │\n",
|
||||||
|
"└──────────┴──────────┘\n",
|
||||||
|
"2 AlteryxSelect\n",
|
||||||
|
"3 BrowseV2\n",
|
||||||
|
"4 TextInput\n",
|
||||||
|
"shape: (3, 2)\n",
|
||||||
|
"┌──────────┬──────────┐\n",
|
||||||
|
"│ Column 3 ┆ Column 4 │\n",
|
||||||
|
"│ --- ┆ --- │\n",
|
||||||
|
"│ i64 ┆ i64 │\n",
|
||||||
|
"╞══════════╪══════════╡\n",
|
||||||
|
"│ 5 ┆ 8 │\n",
|
||||||
|
"│ 6 ┆ 9 │\n",
|
||||||
|
"│ 7 ┆ 10 │\n",
|
||||||
|
"└──────────┴──────────┘\n",
|
||||||
|
"5 AlteryxSelect\n",
|
||||||
|
"6 Formula\n",
|
||||||
|
"7 Join\n",
|
||||||
|
"10 BrowseV2\n",
|
||||||
|
"11 Formula\n",
|
||||||
|
"12 Sample\n",
|
||||||
|
"13 BrowseV2\n",
|
||||||
|
"14 DbFileOutput\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"C:\\Users\\casey.morter\\AppData\\Local\\Temp\\ipykernel_4012\\3571569777.py:9: DataOrientationWarning: Row orientation inferred during DataFrame construction. Explicitly specify the orientation by passing `orient=\"row\"` to silence this warning.\n",
|
||||||
|
" df = pl.DataFrame(data_rows, fields)\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"# Parse all tools in tools dict\n",
|
||||||
|
"for tool in results:\n",
|
||||||
|
"\n",
|
||||||
|
" ToolID = tool[0]\n",
|
||||||
|
" ToolXML = tool[1]\n",
|
||||||
|
" ToolType = ET.fromstring(ToolXML).find(\".//GuiSettings\").attrib['Plugin'].split(\".\")[2]\n",
|
||||||
|
"\n",
|
||||||
|
" print(ToolID, ToolType)\n",
|
||||||
|
"\n",
|
||||||
|
" if ToolType == 'TextInput':\n",
|
||||||
|
" print(TextInputToDf(ToolXML))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 29,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Check out a tool\n",
|
||||||
|
"# 0 = TextInput\n",
|
||||||
|
"# 4 = select with rename\n",
|
||||||
|
"tool_xml = results[4][1]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 27,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"'c:\\\\Users\\\\casey.morter\\\\OneDrive - JLL\\\\Documents\\\\01 Workspace\\\\01 Python\\\\Polaryx'"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 27,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"%pwd"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 31,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"ename": "KeyError",
|
||||||
|
"evalue": "'type'",
|
||||||
|
"output_type": "error",
|
||||||
|
"traceback": [
|
||||||
|
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
|
"\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)",
|
||||||
|
"Cell \u001b[1;32mIn[31], line 16\u001b[0m\n\u001b[0;32m 14\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m field \u001b[38;5;129;01min\u001b[39;00m root\u001b[38;5;241m.\u001b[39mfindall(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.//SelectFields/SelectField\u001b[39m\u001b[38;5;124m\"\u001b[39m):\n\u001b[0;32m 15\u001b[0m field_name \u001b[38;5;241m=\u001b[39m field\u001b[38;5;241m.\u001b[39mattrib[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfield\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[1;32m---> 16\u001b[0m field_type \u001b[38;5;241m=\u001b[39m \u001b[43mfield\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mattrib\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mtype\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\n\u001b[0;32m 18\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m 19\u001b[0m field_rename \u001b[38;5;241m=\u001b[39m field\u001b[38;5;241m.\u001b[39mattrib[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mrename\u001b[39m\u001b[38;5;124m'\u001b[39m]\n",
|
||||||
|
"\u001b[1;31mKeyError\u001b[0m: 'type'"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"col_specs = {\n",
|
||||||
|
" \"A\": (\"x\", int, False),\n",
|
||||||
|
" \"B\": (\"y\", str, False),\n",
|
||||||
|
" \"D\": (None, None, True) # drop this column\n",
|
||||||
|
"}\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"# Parse the XML\n",
|
||||||
|
"root = ET.fromstring(tool_xml)\n",
|
||||||
|
"\n",
|
||||||
|
"dict_SelectTool = {}\n",
|
||||||
|
"\n",
|
||||||
|
"for field in root.findall(\".//SelectFields/SelectField\"):\n",
|
||||||
|
" field_name = field.attrib['field']\n",
|
||||||
|
"\n",
|
||||||
|
" try:\n",
|
||||||
|
" field_type = field.attrib['type']\n",
|
||||||
|
" except:\n",
|
||||||
|
" field_type = None\n",
|
||||||
|
" \n",
|
||||||
|
" try:\n",
|
||||||
|
" field_rename = field.attrib['rename']\n",
|
||||||
|
" except:\n",
|
||||||
|
" field_rename = None\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
" dict_SelectTool[field_name] = (None, None, field_rename)\n",
|
||||||
|
" \n",
|
||||||
|
"\n",
|
||||||
|
" # dict_SelectTool['field']\n",
|
||||||
|
"\n",
|
||||||
|
" # if field.attrib['field'] != '*Unknown':\n",
|
||||||
|
" # field.attrib['selected'], \"Type: \", field.attrib['size']\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
" \n",
|
||||||
|
" # print(field.attrib['field'], \"| Selected:\", field.attrib['selected'], \"Type: \", field.attrib['size'])\n",
|
||||||
|
"\n",
|
||||||
|
"dict_SelectTool"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 108,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"gui_settings_text = root.find(\".//GuiSettings\")"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 114,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"'AlteryxBasePluginsGui.TextInput.TextInput'"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 114,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"gui_settings_text.attrib['Plugin']"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import polars as pl\n",
|
||||||
|
"\n",
|
||||||
|
"def reshape_polars_df(df: pl.DataFrame, col_specs: dict):\n",
|
||||||
|
" \"\"\"\n",
|
||||||
|
" Reshape a Polars DataFrame by renaming and retyping columns according to the provided dictionary.\n",
|
||||||
|
"\n",
|
||||||
|
" Args:\n",
|
||||||
|
" df (pl.DataFrame): The input Polars DataFrame.\n",
|
||||||
|
" col_specs (dict): A dictionary where keys are column names in the original DataFrame,\n",
|
||||||
|
" and values are tuples containing the new column name, data type, and a boolean indicating whether\n",
|
||||||
|
" the column should be dropped or not.\n",
|
||||||
|
"\n",
|
||||||
|
" Returns:\n",
|
||||||
|
" pl.DataFrame: The reshaped Polars DataFrame with renamed and retyped columns.\n",
|
||||||
|
" \"\"\"\n",
|
||||||
|
" for old_name, (new_name, dt, drop) in col_specs.items():\n",
|
||||||
|
" if drop:\n",
|
||||||
|
" df = df.drop(old_name)\n",
|
||||||
|
" else:\n",
|
||||||
|
" df = df.rename({old_name: new_name})\n",
|
||||||
|
" if dt is not None:\n",
|
||||||
|
" df = df.with_column(pl.col(old_name).cast(dt))\n",
|
||||||
|
" return df\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "polaryx",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.12.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 2
|
||||||
|
}
|
||||||
Reference in New Issue