Results Filtering#
![]() |
In this example we will demonstrate how to:
|
from dlubal.api import rfem
import pandas, os
with rfem.Application() as rfem_app:
# --- Pre-processing results by Filters ---
# Add optional filters to limit the amount of data retrieved from the database.
# Currently, filters can only be applied to 'object_no' and/or 'loading'!
filters=[
rfem.results.ResultsFilter(column_id='member_no', filter_expression='1,3,6'),
rfem.results.ResultsFilter(column_id='loading', filter_expression='LC1, CO1'),
]
# Retrieve filtered results as a Pandas DataFrame (.data)
results: pandas.DataFrame = rfem_app.get_results(
results_type=rfem.results.ResultsType.STATIC_ANALYSIS_MEMBERS_INTERNAL_FORCES,
filters=filters
).data
print(f"\nResults Pre-processed (Filters):\n{results}")
# --- Post-processing results by Pandas DataFrame ---
# Once the relevant data has been filtered, we can further process and analyze it using the Pandas DataFrame.
# Pandas provides powerful tools to manipulate and analyze data in an efficient and flexible manner.
# Retrieve the entire row that corresponds to this minimum 'n' value
row_n_min = results.loc[results['n'].idxmin()]
print(f"\nResults Post-processed (Pandas):\n{row_n_min}")
# Find the minimum value of the 'n' column
n_min = results['n'].min()
print("n_min:", n_min)
# # --- Export the results to a CSV file ---
# Save the Pandas dataframe to a CSV file in the current working directory.
file_path = os.path.abspath('./results.csv')
results.to_csv(path_or_buf=file_path)
print(f"\nResults Exported:\n{file_path}")
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using Microsoft.Data.Analysis;
using Rfem = Dlubal.Api.Rfem;
using Common = Dlubal.Api.Common;
ApplicationRfem? RfemApp = null;
try
{
RfemApp = new ApplicationRfem();
// --- Pre-processing results by Filters ---
// Add optional filters to limit the amount of data retrieved from the database.
// Currently, filters can only be applied to 'object_no' and/or 'loading'!
var filters = new List<Rfem.Results.ResultsFilter>
{
// Replace ColumnId and FilterExpression with values supported by your server
new Rfem.Results.ResultsFilter { ColumnId = "member_no", FilterExpression = "1,3,6" },
new Rfem.Results.ResultsFilter { ColumnId = "loading", FilterExpression = "LC1, CO1" }
};
// Retrieve filtered results as a Microsoft.Data.Analysis.DataFrame (.Data)
Common.Table results = await RfemApp.get_results(
resultsType: Rfem.Results.ResultsType.StaticAnalysisMembersInternalForces,
filters: filters
);
Console.WriteLine($"\nResults Pre-processed (Filters):\n{results.Data}");
// --- Post-processing results by Microsoft DataFrame ---
// Once the relevant data has been filtered, we can further process and analyze it using the Microsoft DataFrame.
// Retrieve the entire row that corresponds to this minimum 'n' value.
var nCol = results.Data.Columns["n"];
if (nCol != null)
{
double minVal = double.PositiveInfinity;
long minIdx = -1;
for (long i = 0; i < nCol.Length; i++)
{
var cell = nCol[i];
if (cell == null) continue;
if (double.TryParse(cell.ToString(), out double v))
{
if (v < minVal)
{
minVal = v;
minIdx = i;
}
}
}
if (minIdx >= 0)
{
// DataFrameRow -> use results.Row(index)
var rowNMin = results.Row((int)minIdx);
// Print the whole row (join columns with a separator)
var rowValues = new List<string>();
for (int c = 0; c < results.Data.Columns.Count; c++)
{
rowValues.Add(rowNMin[c]?.ToString() ?? string.Empty);
}
var columnHeader = results.Data.Columns.Select(c => c.Name);
Console.WriteLine($"\nResults Post-processed (DataFrame):");
Console.WriteLine(string.Join("\t", columnHeader));
Console.WriteLine(string.Join("\t", rowValues));
}
}
// --- Export the results to a CSV file ---
// Save the Microsoft DataFrame to a CSV file in the current working directory.
var filePath = Path.GetFullPath("./results.csv");
using (var writer = new StreamWriter(filePath))
{
// Write the header (column names)
var columnNames = results.Data.Columns.Select(c => c.Name);
writer.WriteLine(string.Join(",", columnNames));
// Write the rows
for (int i = 0; i < results.Data.Rows.Count; i++)
{
var rowValues = results.Data.Rows[i].Select(cell => cell?.ToString() ?? string.Empty);
writer.WriteLine(string.Join(",", rowValues));
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
finally
{
if (RfemApp != null) await RfemApp.close_connection();
}