How to use loop statements and condition statements in TOSCA? - tosca

I am new to TOSCA, kindly guide me How to use loop statements and condition statements in TOSCA...
Thanks in advance.
Sreeni

The best way to find help on this is to refer Tosca documentation.
Please check this : https://support.tricentis.com/community/manuals_detail.do?lang=en&version=10.0.0&url=tchb/conditional_statements.htm
The above link refers to the manual for Tosca 10.0

You can use IF statement for condition, in which you can compare values within tbox set buffer and choose the direction with Then or Else statement.
For looping there are two options While and Do-While loops. Syntax remains same like other programming languages, only thing need to take care is that you need to mention repetition count for looping. By default repetition count for loop is 30, which can be changed to any count you want, just it gives false error when the count has reached to maximum if the loop doesn't end at 'n-1' count.
To avoid this false error you can first take count of elements on which actually you want to apply the loop and then set that value to repetition count by passing a buffer value.

Related

Dictionary key-values not updating after for-loop in R

sample codeI am writing a for-loop in R to iterate through each row of my data-frame, and have created dictionary 'key-value' variables in a hash constructor. My code is intended to identify the presence of various strings (i.e. grepl("pattern", data)) in each row, and add one to the key-value count if grepl() returns TRUE. After iterating through the for-loop though, my dictionary values still return zero, despite the absence of errors from my script. Since the final value for H11 should have been 5, not zero, I would appreciate any feedback on the attached snapshots that may be causing this.
Thank you everyone for the feedback. I figured out the issue, as it was a simple reassignment step that I excluded.

How to use vectorization with if conditional logic

Question
I am new to programming and am experiencing an issue with conditional logic. In my function the condition has length > 1 and thus only the first case of it being true will populate. How would I go about implementing the correct functionality?
Output
I get incorrect information for the BaseQoQ and StressQoQ calculations for all regions with counter = 1. How would I modify my code so the correct information populates for a conditional with length > 1? I am new to R so any insight is much appreciated.
The vectorised form of ifcondition in R is ifelse, whose definition can be found here. In your example one can have
with(HPF,
ifelse(index != 0,
case1,
case2)
)
notice that you may want to wrap case1 (respectively case2) assignments into independent functions, to avoid confusions with the ifelse commas themselves.

Finding 'first occurrence' using Match Function in R

I am new to 'R' and 'Stackoverflow' so forgive me for the incredibly basic question. I'm trying to find the 'index' of the first female in my dataset.
Code Snapshot
My overall dataset is called 'bike', so first I thought it would be a good idea to assign a new vector of just the genders...
bike$genders
Then I tried using the function:
match(1, genders)
match(F, genders)
Neither of which worked! I know this is and should be relatively simple but I'm just starting out so I really appreciate your help.
Probably the most direct method would be to use
match("F", bike[,"genders"] which will return the index of the first match.
If you want to know the rows#, this should give you the rows, with their numbers printed to the screen, and you will see the index for rows with it.
bike[bike$gender=="F",]
and if you only want the row numbers to set to a vector
rnam<-row.names(bike[bike$gender=="F",])

MS Access- Calculated Column for Distinct Count in Table Rather than a Query

I'd like to have a Calculated Column in a table that counts the instances of a concatenation.
I get the following error when inputting Abs(Count([concat])) as the column formula for the calculation: The expression Abs(Count([concat])) cannot be used in a calculated column.
Is there any other way to do it without doing a query? I'm pretty sure it can't be done but I figured I'd ask anyways since I didn't see any other posts about it.
No, and even if there was, you should create and use a query for this.
Besides, applying Abs on a count doesn't make much sense, as the count cannot be negative.

expand.grid - try to solve "cannot allocate vector of size" issue

I need to create huge data.frame of combinations, but I don't need them all. But as I saw here, expand.grid function is not able to add specific condition which combination throw out.
So I decided to go step by step. For example I have
variants<-9 # number of possible variants
aa<-c(0:variants) # vector of possible variants
ab<-c(0:variants)
ac<-c(0:variants)
ad<-c(0:variants)
ae<-c(0:variants)
af<-c(0:variants)
ag<-c(0:variants)
ah<-c(0:variants)
ai<-c(0:variants)
aj<-c(0:variants)
If I try to
expand.grid(aa,ab,ac,ad,ae,af,ag,ah,ai,aj)
the "cannot allocate vector of size" issue comes ..
So I tried to go step by step like
step<-2 # it is a condition for subsetting the grid
grid_2<-expand.grid(aa,ab)
sub_grid_2<-grid_2[abs(grid_2[,1]-grid_2[,2])<=step,]
which gives me combinations I need. To save memory I add then another column like
fun_grid_list_3<-function(x){
a<-sub_grid_2[x,1]
b<-sub_grid_2[x,2]
d<-rep(c(1:variants))
c<-data.frame(Var1=rep(a,variants),Var2=rep(b,variants),Var3=d)
return(c)
}
sublist_grid_3<-mclapply(c(1:nrow(sub_grid_2)),fun_grid_list_3,mc.cores=detectCores(),mc.preschedule=FALSE)
sub_grid_3=ldply(sublist_grid_3)
But the problem comes when I come to grid of 8 and more variables. It takes so much time, but it should be just adding a number into another frame. Maybe I am wrong and it trully need that time but I hope there is a more efficient way how to do this.
All I need is to create expand.grid of 2 variables, then add condition to subset it. Then add another column which respects the subsetted grid (add c(0:variants) to every row, it means create more rows of course ... and then subset it by condition and so ....
Can anybody help to make it faster? I hoped that use mclapply trought function should be the fastest, but maybe not ..
Thanks to anyone ...

Resources