Hi All
In the GQI, I have a table with different alarms, now I need to export from this table the count for each type of severity present in the table.
What I need at the end is table where is present a row for each kind of severity with the count of occurencys, so in this way I can populate in the right way a widget on the LCA.
I tried to build a solution for this with the plain GQI, but it require to create a GQI for each alarm severity type, and also will require to join all the GQI at the end that not work properly on the widget to show the count of the alarms.
I'm tring with the Custom Operator, I'm able to keep track of the occurency for each severity type, but I'm not able to print out the count with the name of the severity as row to any table, how I should achive it?
[GQIMetaData(Name = "DataOperator1")] public sealed class DataOperator1 : IGQIColumnOperator, IGQIRowOperator, IGQIInputArguments
{
private GQIColumnDropdownArgument _severityColumnArg = new GQIColumnDropdownArgument("Severity") { IsRequired = true, Types = new GQIColumnType[] { GQIColumnType.String } };private GQIColumn _severityColumn;
private GQIStringColumn _severityNameColumnResult = new GQIStringColumn("SeverityType");
private GQIIntColumn _severityCountColumnResult = new GQIIntColumn("Count");public List<Tuple<string, int>> Counters = new List<Tuple<string, int>>();
public GQIArgument[] GetInputArguments()
{
return new GQIArgument[] { _severityColumnArg };
}public OnArgumentsProcessedOutputArgs OnArgumentsProcessed(OnArgumentsProcessedInputArgs args)
{
_severityColumn = args.GetArgumentValue(_severityColumnArg);return new OnArgumentsProcessedOutputArgs();
}public void HandleColumns(GQIEditableHeader header)
{
header.AddColumns(_severityNameColumnResult);
header.AddColumns(_severityCountColumnResult);
}public void HandleRow(GQIEditableRow row)
{
var severityValue = row.GetValue<string>(_severityColumn).ToLower();row.SetValue(_severityNameColumnResult, severityValue, $"{severityValue}");
var index = Counters.FindIndex(t => t.Item1 == severityValue);if (index != -1)
{
int count = Counters[index].Item2 + 1;
Counters[index] = Tuple.Create(severityValue, count);
row.SetValue(_severityCountColumnResult, count, $"{count}");
}
else
{
Counters.Add(new Tuple<string, int>(severityValue, 1));
row.SetValue(_severityCountColumnResult, 1, $"{1}");
}
}
}
Here the code I used for the custom operator
You should be able to do this without the need for a custom operator. You can aggregate (distinct count) the alarm ID. This will give you the total amount of alarms, so not exactly what you want. But here comes the interesting part: an aggregation can optionally be followed by one or more group by operators, so aggregate (id) + group by (severity) will give you the total amount of alarms for each severity.
I’m glad it worked out! Just to clarify, a custom operator isn’t the best fit for this use case. Custom operators are typically used to transform one row into another, rather than to produce aggregated results. If the built-in aggregate or group operators weren’t available, you might handle this with an ad-hoc data source, where you have full control over the data and the final output. However, using the built-in operators is faster and generally the preferred approach to achieve the same result.
Hi Gilles, thanks for your answer, it works like a charms, thanks a lot!