Compare time in Dialogflow CX conditional response - dialogflow-cx

I try to compare time in conditional response:
if $sys.func.IDENTITY($sys.func.FORMAT_DATE($sys.func.NOW(), "H")) < 8 OR $sys.func.IDENTITY($sys.func.FORMAT_DATE($sys.func.NOW(), "H")) > 20
We are closed now
else
We are open
endif
Time is 18:20, and I added $sys.func.IDENTITY($sys.func.FORMAT_DATE($sys.func.NOW(), "H")) to the text output and made sure it says "18", but it keeps saying "We are closed now".
I see that "18" is of string type. I might need to convert the value to integer, but how?
Working hours are between 8am-9pm
How to properly compare?

The right hand side is type casted to the same type as the left hand side before comparing.
Said this, I think that you can use “HH” to make sure you have a leading zero, since there could be a non-numeric “:mm” minute part.
You can use the following code:
if $sys.func.FORMAT_DATE($sys.func.NOW(), "HH") < “08” OR $sys.func.FORMAT_DATE($sys.func.NOW(), "HH") > “20”
We are closed now
else
We are open
endif

Related

How to use formula CASE WHEN on Netsuite Oracle?

Hi Can someone help me with the Saved Search: So I’m trying to create a formula(numeric) that would say:
CASE WHEN {internalid} = ‘32319’ THEN 1 ELSE 0 END
— didn’t work it didn’t even show on the description
I also tried:
CASE {internalid} WHEN 32319 THEN 1 ELSE 0 END — also didn’t work and didn’t show on the description.
Not sure if perhaps using formula on my saved search is disabled on my end if so how can I know or check? Or maybe I did not use to correct syntax for the CASE WHEN? The formula is also grayed out(highlighted).
I managed to find a solution. As it turns out I just needed to put a value of 1 on the textbox for Value to validate the CASE WHEN Statement. Also whether there's a single quote for the numbers or in this case without a single quote, it still worked.
Either of those forms should work but your screen shots show a Formula(Text) rather than Formula(Numeric)

Is there something I'm doing wrong to pick up this error?

I am new to Ti-basic, and I am trying to code it. I'm trying to make this 'special type of input' program. It is kind of like input, but it will show the word as it is being pressed (and there is no need to put in alpha)
Here is the code so far that I believe is pertaining to the error
:{41,42,43,51,52,53,54,55,61,62,63,64,65,71,72,73,74,75,81,82,83,84,85,91,92,93,94,102,103,103}→∟KEYS
:"ABCDEFGHIJKLMNOPQRSTUVWXYZθ :?"→Str7
:0→K
:""→Str1
:
:Repeat K=105
:getKey→K
:If max(∟KEYS-K)
:prgmFINDIND
:.........
:End
Inside prgmFINDIND, This is the code
:1+sum(not(cumSum(∟KEYS=K)))→I
://I is used later on in the code. It isn't pertaining to the problem.
I have done some testing with pause on this already, and I found the problem was in the if statement. It returns an 'INVALID DIM' error.
Anybody know what's wrong?
In this part (edited a bit)
Repeat K=105
getKey->K
If max(|LKEYS=K
prgmFINDIND
Str1+sub(Str7,I,1->Str1
End
prgmFINDIND is only called if the key that was pressed is in the list, otherwise the index I is not changed (and possibly implicitly zero, or whatever other value that was left there).
Pressing GOTO on the INVALID DIM actually goes to Str1+sub(Str7,I,1->Str1, indicating that a bad index was used to index into Str7.
It could be fixed by using an If/Then block, which can cover more than one statement:
Repeat K=105
getKey->K
If max(|LKEYS=K
Then
prgmFINDIND
Str1+sub(Str7,I,1)->Str1
End
End

Jmeter - While Controller with Counter Config Element

I have a while controller that waits for a certain regular expression to appear in the response before logging the user out. However, due to timeouts with the previous request this will occasionally enter into an infinite loop, skewing the data. I'm looking to set this request so that it only sends 5 times before exiting the loop and logging the user out.
After searching for an answer it seems that either the ${__counter()} variable or Counter Config Element are the solution, but neither seem to be working as I would expect.
Here is what I've got so far:
While Controller (${__javaScript( "${DONE_A}" != "Thank you for your order" || ${counter} < 5;)}
Counter (set to 5, increment 1)
Constant Timer (2000 ms)
GET /checkout/confirmation
^RegExp Extractor (DONE)
Logout
I can see a couple of problems with your script:
During 1st iteration counter value is NaN, you need to either declare it via i.e. User Defined Variables or to add check for "Not a Number" into your condition
You cannot refer variables as ${counter} in __JavaScript function. If you need to address it, you need to surround the variable with quotation marks (like you do for your DONE_A variable. If you need to treat the variable like a numeric one - use i.e. parseInt() function
Given point 2, my expectation is what your While controller clause simply does not work, that's why you're getting an endless loop.
This one should be good for your scenario:
${__javaScript(isNaN(parseInt("${counter}")) || parseInt("${counter}") < 5 && "${DONE_A}" != "Thank you for your order",)}

Fortran77 User Input Validation

I need the user to enter only real numbers when prompted. An error message should be displayed and program should stop in case the user enters a character or any other symbol. How can i do this in fortran 77.
I assumed, you probably want to have more tries, because what you have in your question does the compiler does automatically.
You can use the IOSTAT= or ERR= specifiers.
INTEGER IE
DO I = 1, MAX
READ(*,*,IOSTAT=IE) X
IF (IE.eq.0) GOTO 10
PRINT *,"Wrong input, try again."
END DO
10 CONTINUE
or
GOTO 10
20 PRINT *,"Wrong input, try again."
10 READ(*,*,ERR=20) X
improving the user interface a little, i like to read a string, then do the error check on an internal read:
character insting*80
ie=1
do while(ie.ne.0)
read(*,'(a)')instring
if(instring(1:1).eq.'q')stop
read(instring,*,iostat=ie)x
if(ie.ne.0)then
write(*,*)'invalid input ',trim(instring),' is not a real number'
endif
enddo
(note trim is not f77 btw, but its easy enough to replicate if needed)
Note, with some effort you can handle the pathalogic cases. A leading '/' or ',' throws no error but leaves the value of x unchanged (likely system/compiler dependent however!), so you can do something like this:
x=-999999.
read(instring,*,iostat=ie)x
if(ie.eq.0.and.x.eq.-999999.)then
.. code to handle error..
endif
You could alternately use index to look for the bad characters. On my system a decimal . by itself is taken as zero. That gets a bit cumbersome to handle, but it can be done by parsing instring

confirm conditional statement applies to >0 observations in Stata

This is something that has puzzled me for some time and I have yet to find an answer.
I am in a situation where I am applying a standardized data cleaning process to (supposedly) similarly structured files, one file for each year. I have a statement such as the following:
replace field="Plant" if field=="Plant & Machinery"
Which was a result of the original code-writing based on the data file for year 1. Then I generalize the code to loop through the years of data. The problem becomes if in year 3, the analogous value in that variable was coded as "Plant and MachInery ", such that the code line above would not make the intended change due to the difference in the text string, but not result in an error alerting the change was not made.
What I am after is some sort of confirmation that >0 observations actually satisfied the condition each instance the code is executed in the loop, otherwise return an error. Any combination of trimming, removing spaces, and standardizing the text case are not workaround options. At the same time, I don't want to add a count if and then assert statement before every conditional replace as that becomes quite bulky.
Aside from going to the raw files to ensure the variable values are standardized, is there any way to do this validation "on the fly" as I have tried to describe? Maybe just write a custom program that combines a count if, assert and replace?
The idea has surfaced occasionally that replace should return the number of observations changed, but there are good reasons why not, notably that it is not a r-class or e-class command any way and it's quite important not to change the way it works because that could break innumerable programs and do-files.
So, I think the essence of any answer is that you have to set up your own monitoring process counting how many values have (or would be) changed.
One pattern is -- when working on a current variable:
gen was = .
foreach ... {
...
replace was = current
replace current = ...
qui count if was != current
<use the result>
}

Resources