Hello! I have tried using the little knowledge I have of KNIME, and I have given up; I have not been able to solve the following problem:
I have a set of fault data in a system. A significant variable is the time between failures. The system inventory is year by year, and I would like to add up the time, taking into account some special conditions:
a. When two whole years (or more years) without failures are completed, I should be able to sum the days of that entire year with those of the previous year without failures.
b. When a failure occurs again, you should be able to reset the time in days.
I attach a screenshot with the column of results that I have achieved with KNIME and the column with the results that I expect to obtain.
Hi
there are 2 ways I can think of.
Either use moving aggregator node (window 2 , type backward and aggregation First) for time between column
This creates a new column where you find the prior row value. Then you can just do check wether both columns (original and new one contain 365) and if so add them together.
Other option use column expressions node directly
You need to enable mutli access in the advanced tab of column expression
Then adjust this formula to your column names
if (column("Year",-1)==365)
{720}
else
{column("Year")}
Brilliant! I discovered (with your help) that the Column Expressions node had this multi-row access option. Thank you very much! Now, I have a strange problem because when I execute this code:
The logic I indicate in the Column Expressions does not execute properly in the last row, in which, as you can see, the value should be 730 + 365 = 1095.
Could you tell me what I am doing wrong? Thank you very much again!
Hi @edwar_forero , although I can’t see your input data, I’m assuming that it is something like:
year
tiempo_entre_avieras
2013
365
2014
365
2015
365
Unfortunately the column expressions node only “remembers” the input values for previous rows within the defined window, but does not remember the output values. Therefore, it will add the 365 in 2015 to the input value of 365 in 2014, rather than the cumulative output value, thereby resulting in 730. I’m not aware of a workaround within the Column expressions nodes, and you would need to do something outside of column expressions including such nodes as Moving Aggregation to perform cumulative operations.
To my mind that all becomes a bit cumbersome, which is why for any such problem I turn to Java Snippets, and is one of the primary reasons I almost never used Column Expressions.
Java snippets are (arguably) marginally more complicated to write than Column Expressions, but the upside is you get proper compilation errors, and faster performance.
For the workflow I’ve attached below, I’ve had to create the data so it is slightly different to your numbers. I don’t know what the basis of your calculations were, and the workflow you uploaded doesn’t contain the base data in a form I could make work.
Anyway, assuming my understanding is correct, I think the following java snippet achieves what you are trying to do:
// Your custom variables:
int cumulTimeBetweenFailures=0; // keeps track of the cumulative time
int lastTimeBetweenFailure = 0; // stores value of failure time from last row
// Enter your code here:
if(lastTimeBetweenFailure >=365 && c_Timebetweenfailures < 365 )
{
cumulTimeBetweenFailures = c_Timebetweenfailures;
}
else if(lastTimeBetweenFailure < 365 && c_Timebetweenfailures >= 365)
{
cumulTimeBetweenFailures = c_Timebetweenfailures;
}
else
{
cumulTimeBetweenFailures += c_Timebetweenfailures;
}
lastTimeBetweenFailure=c_Timebetweenfailures; // store value from current row for checking next time
out_calctimebetweenfailures = cumulTimeBetweenFailures; // cumulative value to be returned for
I just wanted to let you know that I am so thankful to you for saving my life (metaphorically speaking)!
If I have any trouble designing any data process with KNIME nodes, which is rare, I will turn to JavaScript snippets.
Thanks!