Getting the right calc for multiple if statement in tableau - tableau-api

I’m trying to write a if then statement on tableau but I might be missing something it’s a multiple comparison
What I have now
If {Receive campus match } = false then ‘0’
Else
If { matches lag} = true then true else false
Else
If { days difference between goods planned vs shipped} < = 0
Then { fixed .......} there’s an LOD
ELSE ‘0’
End
End
End
But it not correct ! Help will be needed

Since you have not uploaded any data/screenshot, it is very difficult to understand your problem, yet I can see a few errors in your proposed calculation.
Your proposed calculation, if broken into phrases becomes like this-
line-1 If {Receive campus match } = false
line-2 then ‘0’
line-3 Else If { matches lag} = true
line-4 then true
line-5 else false
line-6 Else If { days difference between goods planned vs shipped} < = 0
line-7 Then { fixed .......} there’s an LOD
line-8 ELSE ‘0’
line-9 End End End
Problem-1: In tableau there is ELSEIF and not ELSE IF
Problem-2: You cannot start a new else if (sic!) (line-6) once an else (line-5) has been provided
Problem-3: Why three END in line-9?
Basically the syntax of IF THEN ELSE IF ELSE END goes like this...
IF <Condition>
Then <Result 1>
ELSEIF <condition 2>
then <Result>
... Repeat ELSEIF and THEN here, if you have several conditions
ELSE <last result corresponding to last false condition>
END

Related

check if key variable is equal to button

i wanna click a random button 50 times from a list unless it is 1 only click it once, its always going to the else even if key is 1
!F2::
breakvar = 1
return
!F1::
loop
{
Random, var, 1,7
keyList = {1},{2},{3},{w},{a},{s},{d}
StringSplit, KeyAry, KeyList, `,,%A_Space%
key := KeyAry%var%
loop 50
{
; i've tryied:
;(%key% = "1")
;(key = 1)
;(key = {1})
; but with out success
if (key = "1")
{
Send, %key%
break
}
else
{
Send, %key%
Sleep, 100
}
}
if breakvar = 1
break
}
breakvar = 0
return
also is there a better way to achieve what i am trying to do?
thx
Your main mistake was that you indeed didn't manage to get the if statement corrent. The right one would've been if (key = "{1}").
But really, I don't know why you even had the { }, it's a common mistake I see from nearly every beginner, I wonder where it comes from.
You're only supposed to use { } for escaping or if the special notation is needed for something such as {space}. Read more from the documentation.
Here's a cleaned up script with all other weirdness removed as well:
KeyList := StrSplit("1,2,3,{space},+1,w,🐈", ",") ; +1 is shift + 1 (whatever key that will produce in your keyboard layout)
!F2::BreakVar := true
!F1::
loop
{
Random, index, 1, 7
key := KeyList[index]
loop 2
{
SendInput, % key
if (key = "1")
break
Sleep, 100
}
if (BreakVar)
break
}
BreakVar := false
return
To be totally correct, I should say that you shouldn't loop under hotkeys and should use a timer instead, but I wont add that in to confuse you. This should be fine as well, if you have problems with hotkeys after this, you can look into a timer approach yourself or ask help here.

Keep longest strings while removing those partially matched with them

I have a set of data like this:
I love
Hong Kong
I love Hong Kong and Japan.
and Japan.
test.
just a
This is just a test.
I would like to keep the longest ones while removing those partially matched with them. the desired result:
I love Hong Kong and Japan.
This is just a test.
but the actual result is
I love
I love Hong Kong and Japan.
This is just a test.
Here are my code in AHK:
FileEncoding, UTF-8
FileSelectFile, FileName
FileRead, Var, %FileName%
lines_master := StrSplit(Var, "`r`n")
l :=lines_master.MaxIndex()
lines_temp :=[]
Remaining_List =
count_match = 0
While l > 1
{
for i, element in lines_master
{
if (i == 1)
{
master :=element
}
Else
{
if !InStr(master, element)
{
lines_temp.Insert(element)
count_match := count_match + 1
}
}
}
x := l - 1
if (count_match == x)
{
lines_temp.Insert(master)
}
else
{
Remaining_List .=master . "`r`n"
}
count_match = 0
lines_master :=lines_temp
lines_temp :=[]
l :=lines_master.MaxIndex()
}
FileAppend, %Remaining_List%, F:\result.txt, UTF-8
Exit
if I sort the list by length in words, it works. However, I would like to know how to refine the code and make it work no matter what order the list of strings is in.
thank you.

Prime Numbers Swift 3

After hours of Googling, I'm still at a standstill. I would appreciate if someone would point out the error in my formula or coding choice. Please keep in mind I'm new to Swift. I'm not used to non C-style for loops.
if textField.text != "" {
input = Double(textField.text!)! // parse input
// return if number less than 2 entered
if input < 2 {
resultLabel.text = "Enter a number greater than or equal to 2."
return;
}
// get square root of input and parse to int
inputSquared = Int(sqrt(input));
// loop from 2 to input iterating by 1
for i in stride(from: 2, through: input, by: 1) {
if inputSquared % Int(i) == 0 {
resultLabel.text = "\(Int(input)) is not a prime number."
}
else {
resultLabel.text = "\(Int(input)) is a prime number!"
}
}
}
I didn't know the formula on how to find a prime number. After looking up multiple formulas I have sorta settled on this one. Every result is a prime number, however. So my if condition is wrong. I just don't know how to fix it.
Check my algorithm.It works.But I'm not sure this is an effective algorithm for prime number
var input:Int = 30
var isPrime:Bool = true
if(input == 2){
print("Input value 2 is prim number")
}
else if(input < 2){
print("Input value must greater than 2")
}
else{
for i in 2...input-1{
if((input%i) == 0){
isPrime = false
break;
}
}
if(isPrime){
print("Your Input Value \(input) is Prime!")
}
}
A couple of solutions that work have been posted, but none of them explain why yours doesn't. Some of the comments get close, however.
Your basic problem is that you take the square root of input, then iterate from 2 to the input checking if the integer part of the square root is divisible by i. You got that the wrong way round. You need to iterate from 2 to the square root and check that the input is divisible by i. If it is, you stop because input is not prime. If you get to the end without finding a divisor, you have a prime.
try this code in playground you will get this better idea and try to use playground when you try the swift as you are not familiar with swift playground is best.
let input = 13 // add your code that take value from textfield
var prime = 1
// throw error less than 2 entered
if input < 2 {
assertionFailure("number should be 2 or greater")
}
// loop from 2 to input iterating by 1
for i in stride(from: 2, to: input, by: 1) {
if input % i == 0{
prime = 0
}
}
if prime == 1 {
print("\(input) number is prime")
} else {
print("\(input) number is not prime")
}

swift: Using or in a loop condition statement

sorry for asking a simple question, but unfortunately after an hour debugging I am a bit lost. I want to use "or" in the condition of a repeat while loop. Unfortunately the code just leave the loop when the first condition is true, the second seams to be never checked.
Here is my code:
j=1
repeat {
if (Int(scores[1][j]) != 0) {
if (nrOfMoves < Int(scores[1][j])) {
positionToStore = j
positionFound = true
}
} else {
positionToStore = j
positionFound = true
}
j++
} while(positionFound == false || j > 5)
while is just leaving when positionFound is true when j reaches 6 it just repeats or bette terminates by an exception
From documentation:
Repeat-While
The other variation of the while loop, known as the repeat-while loop,
performs a single pass through the loop block first, before
considering the loop’s condition. It then continues to repeat the loop
until the condition is false.
It meens that your loop works only when condition positionFound == false || j > 5 is false. When positionFound set to true, condition becomes true and you leave the loop.
In your situation you need to use while loop
From documentation:
While
A while loop starts by evaluating a single condition. If the condition
is true, a set of statements is repeated until the condition becomes
false.
Here’s the general form of a while loop:
while positionFound == false || j > 5 {
if (Int(scores[1][j]) != 0) {
if (nrOfMoves < Int(scores[1][j])) {
positionToStore = j
positionFound = true
}
} else {
positionToStore = j
positionFound = true
}
j++
}
The condition in a repeat-while loop tells what needs to happen for the loop to continue. You want to loop while j <= 5 so that it drops out of that loop when j reaches 6. Also, you need to continue when both conditions hold, so in this case you should use && instead of ||. With this change, the code then reads "continue looping as long as I haven't found what I'm looking for AND my index is still good":
j=1
repeat {
if (Int(scores[1][j]) != 0) {
if (nrOfMoves < Int(scores[1][j])) {
positionToStore = j
positionFound = true
}
} else {
positionToStore = j
positionFound = true
}
j++
} while(positionFound == false && j <= 5)
A common shorthand way of writing positionFound == false is !positionFound and is pronounced "not positionFound".

I got error message about simulink "Output argument is not assigned on some execution paths"

In simulink, I made some model using "MATLAB function"block
but I met error message here.
here is code and error message.
function [VTAS,postVTAS]=fcn(mode,initialVTAS,a,t,preVTAS)
if mode == 1
VTAS = initialVTAS + (a * t) ;
postVTAS = VTAS;
elseif mode == 2
datasize = length(preVTAS);
lastvalue = preVTAS(datasize);
VTAS = lastvalue + 0;
postVTAS = VTAS;
end
end
Output argument 'VTAS' is not assigned on some execution paths.
Function 'MATLAB Function' (#36.25.28), line 1, column 26:
"fcn"
Launch diagnostic report.
I think there is no problem about output "VTAS"
please teach me what is a problems.
As the compiler tells you, under some circumstances there is no output value assigned to VTAS. The reason is that you only assign values to that output if mode is 1 or 2. The compiler doesn't know what values are feasible for mode. To remedy this, you need to make sure that VTAS is assigned under any and all circumstances.
This could be accomplished by, e.g. adding an else construct, like so:
function [VTAS,postVTAS]=fcn(mode,initialVTAS,a,t,preVTAS)
if mode == 1
VTAS = initialVTAS + (a * t) ;
postVTAS = VTAS;
elseif mode == 2
datasize = length(preVTAS);
lastvalue = preVTAS(datasize);
VTAS = lastvalue + 0;
postVTAS = VTAS;
else
VTAS = NaN;
postVTAS = NaN;
end
end
Edit:
Additionally, it would be good practice for the else case to throw an error. This would be helpful for debugging.
As a minor note, for every case, postVTAS is equal to VTAS, so essentially it is superfluous to return both from the function.