# Detecting flip flop changes

6 posts / 0 new
myrahz
Offline
Joined: 06/06/2017 - 10:54
Detecting flip flop changes

Hello there, recently one of the analysis I'm doing is searching for flip-flop changes on logs.
For instance detecting these type of changes:
https://imgur.com/a/tHoCa0v
Detecting flip flop changes on numeric numbers is easy. I usually create a field that appends both numbers as a string and constantly follow the logic of writing the small one first and then the larger one. This will create the same string wether the change is 100 to 1000 or 1000 to 100 and they are easily detected by searching for duplicates no that newly created field.
https://imgur.com/a/P5VGIBa
However I can't apply the same logic to character fields. Is there any criteria that I can use in order to achieve something like this that works no matter how the strings are written or their size?

https://imgur.com/a/wJW5jab

Brian Element
Offline
Joined: 07/11/2012 - 19:57

This was an interesting question and here is what I came up with.  I could not figure out a way to do it directly through the equation editor but IDEA allows you to create custom functions that you can use in the equation editor and I came up with a custom function that changes the text into a value by adding the ASCII codes for each character together along with adding the character position, I did this because if I didn't ABCD would give the same value as DCBA.

The custom function is called #CharToNum and it takes a character field and returns a numberic field.  This is an example of the equation:

The results using your example is the following:

Which I think is what you are looking for.

Files:
myrahz
Offline
Joined: 06/06/2017 - 10:54

Thanks Brian, you always like challenges!
Initially I thought about converting each character to ASCII but I thought there could be an easier solution.
I also thought of indexing every string, like recno per string, create a master table that would have a recno for each string and then apply the numerical logic to the index instead of the word itself.
I have to start using custom scripting often as there are simple programming solutions for these types of problems. Once again thank you!

Brian Element
Offline
Joined: 07/11/2012 - 19:57

No problem, that was a good example of using a Custom Function.  Generally if my equations start to look too complex I switch over and do a Custom Function to create them.  It is handy to know.

DanHoep
Offline
Joined: 09/13/2018 - 05:37

Hi there,
I think the same result can be reached by simply comparing both strings:
`@if(BEFORE<AFTER;BEFORE+AFTER;AFTER+BEFORE)`
Or am I missing something?

Images:
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Yes that would work but it was more fun doing the custom function :-)