LoadRunner Correlation 'Ord' random issue - performance-testing

I am able to capture the response using ord=All in web_reg_save_param.
case 1,
Input:12345
Response:["18/3/2017","20/2/2017","20/2/2016"].
case 2,
Input:98451
Response:["12/1/2017","01/1/2016"]
web_reg_save_param("date","LB=\"","RB=\"","ORD=ALL","LAST);
`
Captured Values are:
date_1:18/3/2017
date_2:,
date_3:20/2/2017
date_4:,
date_5:20/2/2016
Here is the task:
1) I need to fetch random date each time.
2) Date may vary depending upon the input(In case 1, 3 dates and case 2, 2 dates).
I have tried:
1) Correlating and using lr_paramarr_random() function- failed, it will fetch ',' at some point.
2) using for loop and if statement to find out odd/even position.

Using web_reg_save_param() function like you did will, of course, fetch a comma(',') since it is situated between two quote symbols(' " ').
You can use web_reg_save_param_regexp() function with the following regular expression:
"(\d{2}\/\d\/\d{4})"
Set the parameters: "Ordinal=All", "Group=1".
This function will extract the dates and store them into an array.
This time lr_paramarr_random() should return correct results because now your array contains nothing but dates.

Related

Python Warning Panda Dataframe "Simple Issue!" - "A value is trying to be set on a copy of a slice from a DataFrame"

first post / total Python novice so be patient with my slow understanding!
I have a dataframe containing a list of transactions by order of transaction date.
I've appended an additional new field/column called ["DB/CR"], that dependant on the presence of "-" in the ["Amount"] field populates 'Debit', else 'Credit' in the absence of "-".
Noting the transactions are in date order, I've included another new field/column called [Top x]. The output of which is I want to populate and incremental independent number (starting at 1) for both debits and credits on a segregated basis.
As such, I have created a simple loop with a associated 'if' / 'elif' (prob could use else as it's binary) statement that loops through the data sent row 0 to the last row in the df and using an if statement 1) "Debit" or 2) "Credit" increments the number for each independently by "Debit" 'i' integer, and "Credit" 'ii' integer.
The code works as expected in terms of output of the 'Top x'; however, I always receive a warning "A value is trying to be set on a copy of a slice from a DataFrame".
Trying to perfect my script, without any warnings I've been trying to understand what I'm doing incorrect but not getting it in terms of my use case scenario.
Appreciate if someone can kindly shed light on / propose how the code needs to be refactored to avoid receiving this error.
Code (the df source data is an imported csv):
#top x debits/credits
i = 0
ii = 0
for ind in df.index:
if df["DB/CR"][ind] == "Debit":
i = i+1
df["Top x"][ind] = i
elif df["DB/CR"][ind] == "Credit":
ii = ii+1
df["Top x"][ind] = ii
Interpreter
df["Top x"][ind] = i
G:\Finances Backup\venv\Statementsv.03.py:173: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
df["Top x"][ind] = ii
Many thanks :)
You should use df.loc["DB/CR", ind] = "Debit"
Use iterrows() to iterate over the DF. However, updating DF while iterating is not preferable
see documentation here
Refer to the documentation here Iterrows()
You should never modify something you are iterating over. This is not
guaranteed to work in all cases. Depending on the data types, the
iterator returns a copy and not a view, and writing to it will have no
effect.

split String Variable in few numeric Variables in SPSS

I have a string variable with comma separated numbers that I want to split into four numeric variables.
makeArr
var1a
var1b
var1c
var1d
6,8,13,10
6
8
13
10
10,11,2
10
11
2
7,1,14,3
7
1
14
3
With:
IF (CHAR.INDEX(makeArr,',') >= 1)
f12a=CHAR.SUBSTR(makeArr,1,CHAR.INDEX(makeArr,',')-1).
EXECUTE.
IF (CHAR.INDEX(makeArr,',') >= 1)
f12b=CHAR.SUBSTR(makeArr,CHAR.INDEX(makeArr,',')+1,CHAR.INDEX(makeArr,',')-1).
EXECUTE.
I always get the first variable written without any problems.
This no longer works with the second variable because it has a different length and the comma is also written here.
So I would need a split at the comma and the division of the numbers over the comma.
Since char.substr will only tell you about the location of the first occurence of the search string, you need to start the second search from a new location - AFTER the first occurence, and this gets more and more complicated as you continue. My suggestion is create a copy of your array variable, which you will cut pieces off as you proceed - so that you are only searching for the first occurence of "," every time.
First I recreate your example data to demonstrate on.
data list free/makeArr (a20).
begin data
"6,8,13,10" "10,11,2" "7,1,14,3"
end data.
Now I copy your array into a new variable #tmp. Note that I add a "," at the end so the syntax stays the same for all parts of the array. I add the "#" at the beginning of the name to make it invisible, you can remove it if you want.
It is possible to do the following calculation in steps as you started to do, but nicer to loop throug the steps (especially if this is an example for a longer array).
string f12a f12b f12c f12d #tmp (a20).
compute #tmp=concat(rtrim(makeArr),",").
do repeat nwvr=f12a f12b f12c f12d.
do IF #tmp<>"".
compute nwvr=CHAR.SUBSTR(#tmp,1,CHAR.INDEX(#tmp,',')-1).
compute #tmp=CHAR.SUBSTR(#tmp,CHAR.INDEX(#tmp,',')+1).
end if.
end repeat.
EXECUTE.
Here I found a different solution for what I think is the same problem:
https://www.ibm.com/mysupport/s/question/0D50z00006PsP3tCAF/splitting-a-string-variable-divided-by-commas-into-new-single-variables?language=es
One line of code makes the work:
spssinc trans result=var_1 to var_4 type=20/formula 're.split(", *", makeArr)'.

kdb: How to double-loop over a text file and extract the values, per line, per key?

I am working on question 4 of adventofcode. I have a list of strings called "q4" where there are 3 lines (just simple data for now) and each line has keys & values, such as: passport ID being 662406624, or birth year being 1947, etc.
show q4
"eyr:2024 pid:662406624 hcl:#cfa07d byr:1947 iyr:2015 ecl:amb hgt:150cm"
"iyr:2013 byr:1997 hgt:182cm hcl:#ceb3a1 eyr:2027 ecl:gry cid:102 pid:018128"
"hgt:61in iyr:2014 pid:916315544 hcl:#733820 ecl:oth"
I created a function to grab the value for a given key
get_field_value: {[field; pp_str] pp_fields: " " vs pp_str; pid_field: pp_fields[where like[pp_fields; field,":*"]]; start_i: (pid_field[0] ss ":")[0] + 1; end_i: count pid_field[0]; indices: start_i + til (end_i - start_i); pid_field[0][indices]}
fields: ("eyr"; "pid"; "hcl"; "byr"; "iyr"; "ecl"; "hgt")
With the help from this other thread, I could get the values for a given list of keys: kdb/q: How to apply a string manipulation function to a vector of strings to output a vector of strings?
get_field_value[; q4[0]] each fields / Iterates through each field
"2024"
"662406624"
"#cfa07d"
"1947"
"2015"
"amb"
"150cm"
But now how do I do this for each line in my text file (each of the 3 strings in "q4")? In Python or C++ logic, basically I want to do a nested for-loop, the outer loop to iterate through each of the strings, and then within that, for each string, the inner loop grabs the value for each of the keys (fields):
/ Attempt 1 - Fail
get_field_value[each fields ; each q4]
/ Attempt 2 - Fail
each[get_field_value[; each q4]] fields
/ Attempt 3 - Fail
get_field_value[; each q4] each fields
How do I do this? Thanks!

Ruby Selenium send_keys_characters not sending the strings I want

xlsx = Roo::Excelx.new($docs_dir + '/mytestsheet.xlsx')
xlsx.each_row_streaming do |row|
send_keys_characters(row)
step %[I wait for 2 sec]
end
end
I've been struggling with pulling the values from an xlsx file and sending each cell with send_keys_characters into a manual input field on my website; I have 2 issues here and I can't seem to figure out the solutions:
it does not pull ONLY the value of the cell I want e.g "test1", "test2", instead it writes one after the other excel feature:
[#<Roo::Excelx::Cell::String:0x0000000008076b30 #cell_value="test1", #style=0, #coordinate=[1, 1], #value="test1">]
[#<Roo::Excelx::Cell::String:0x0000000006399800 #cell_value="test2", #style=0, #coordinate=[2, 1], #value="test2">]
How can I pull only the value of the cell and mention it on my input field and then Submit?
It needs to pick up the first value and then Submit and continue the scenario and then to return and pick the second value and third and so forth... How can I pick one value at a time and then go to the next step?
This is a ruby / selenium question.
So in essence your problem is looking for the code to enumerate over your objects and send the values you want.
I'm not familiar with Roo, but if they use standard readers then you can just do
array.each do |excel_string|
input_field.send_keys(excel_string)
end
This will concatenate all of the values, so your input field will say test1test2 e.t.c.
If you need to type these in across a set of fields i.e. input_field 1/2/3 I would use #zip to create a 2d-array pair
text_values = array.map(&:value)
zipped_array = input_fields.zip(text_values)
zipped_array.each do |input_field, value|
input_field.send_keys(value)
end

Cognos query calculation - how to obtain a null/blank value?

I have a query calculation that should throw me either a value (if conditions are met) or a blank/null value.
The code is in the following form:
if([attribute] > 3)
then ('value')
else ('')
At the moment the only way I could find to obtain the result is the use of '' (i.e. an empty character string), but this a value as well, so when I subsequently count the number of distinct values in another query I struggle to get the correct number (the empty string should be removed from the count, if found).
I can get the result with the following code:
if (attribute='') in ([first_query].[attribute]))
then (count(distinct(attribute)-1)
else (count(distinct(attribute))
How to avoid the double calculation in all later queries involving the count of attribute?
I use this Cognos function:
nullif(1, 1)
I found out that this can be managed using the case when function:
case
when ([attribute] > 3)
then ('value')
end
The difference is that case when doesn't need to have all the possible options for Handling data, and if it founds a case that is not in the list it just returns a blank cell.
Perfect for what I needed (and not as well documented on the web as the opposite case, i.e. dealing with null cases that should be zero).

Resources