Solutions to "Just KNIME It!" Challenge 4

hi KNIMErs, here we go…

br tommy

KnimeIT_4.knwf (11.0 KB)

1 Like

Here is my solution:
Capture
It can be found at:
https://hub.knime.com/frankcolumbo/spaces/Public/latest/challenge%2020220216

Frank

1 Like

Another approach, using the loop :

Hi KNIMERS!

Here my solution:

Have a nice day!

My solution for Challenge 4 …

Similar to most others… I do like @Thyme 's one node solution.

tC/.

2 Likes

here is my one-node solution, based on Python KNIME_challenge_4b – KNIME Hub

1 Like

Hello dear KNIMErs,

Here is my solution, perhaps not very original or “fancy”, but let’s go : KNIME_Challenge-4 – KNIME Hub

hello
my solution for the Just Knime It! Challenge 4

1 Like

Here’s my solution! #justknimeit-4

Challenge-04.knwf (12.0 KB)

2 Likes

Just adding a few comments after looking at a few solutions. This is not to say that I am necessarily right in my comments, but rather I want put out what I think so that someone can correct me if I am wrong (that’s how we know when we are wrong and learn to correct it :slight_smile:). It’s also part of knowledge sharing:

I see a few people doing the Line Plot. Though it is mentioned in the challenge, in my opinion, it is more of the background story than the request. The request is about adding a new column “Change” whose values are determined by the rules in the request. But no harm in doing the plots of course :wink:

I see also a few of you using the String to Date&Time after reading the data, probably to convert the Date column into date type. You can configure the CSV Reader to read the Date column as date in the Transformation tab:

That way, you don’t have use the String to Date&Time

Correct. However, how can you tell if the data comes sorted? The effort of adding a Sorter, that makes sure the data is properly sorted, is much less than checking if the data is already sorted (you would have to sort and compare, meaning you would have to sort anyways).

@msworn , nice one with the Math Formula, although that would not work for the first row as the lagged value would be missing, so your Math Formula would return nothing (neither 0 nor 1) for that row :slight_smile:

@Thyme nice one with the Java snippet. Indeed great use of the “global variable”.

@lucian.cristian an interesting different approach. But this approach relies on the assumption that there is data for every date (and may be it is safe make this assumption in this case :))

@MoLa_Data , the Column Resorter node sorts the order of the columns. It’s the Sorter node what you are looking for if you want to sort the dates as your description suggest.

Note: I had to globalize some cases in the first 2 comments as the forum does not allow me to mention more than 5 users in a post.

4 Likes

Hi all,

This is my solution of this challenge :slight_smile:

1 Like

I didn’t know about the lag column node. That’s going to be such a time saver in so many use cases. The comment about possible missing dates it’s very valid.

2 Likes

Yes, the Lag Column node is quite useful in this kind of operation, but you present a quite interesting alternative, though I would rely more on some row position (after sorting) than date just in case not all dates are present in the data :slight_smile:

1 Like

@bruno29a the point is correct, I use the transformation for reading de CSV, and I used the Sorter only like a validating way to take all DAYS in order because nothing said the data coming on ORDER BY DATE

2 Likes

Here’s my solution. Not as elegant as some, but works.

REF Daily Prices.knwf (50.0 KB)

1 Like

Here’s my solution!

1 Like

You can configure the lag node to ignore NULL values - as shown in the screenshot :+1:
Coalesces to the same value as the reference column.
Definitely take your point about sorting the dates though - almost zero effort for the peace of mind!

2 Likes

Hi @msworn , by ignoring the NULL values, you are actually removing these rows, in this case the first row, which is the row with date 2015-01-01. As per the request’s description, the first row should stay, and even with a Change value of 1.

If I were to take a guess, your result most probably starts with the 2nd row, Date 2015-01-02, with a Change value of 0.

Thanks for the information! I have updated my submission with Sort and Missing values - I would have updated it in the math formula, but it has no function for handling missing values (not treated as NaN unfortunately)