JMeter: How to pass random number that contains decimal? - random

We have to pass values random between 8, 8.5, 9, 9.5, 10, 10.5 like wise till 99. How may I achieve this?

I heard Groovy is the new black so you can use __groovy() function for implementing your requirement like:
${__groovy(new java.text.DecimalFormat('0.#').format(Math.ceil(org.apache.commons.lang3.RandomUtils.nextFloat(8.1f\, 99f) * 2) / 2),)}
References:
RandomUtils.nextFloat()
Math.ceil()
Customizing Formats

Related

Sending data whose last character is dynamic in JDBC Request - JMETER

I have a question in Jmeter!
I have a script in a JDBC request (INSERT).
One of the data must be dynamic. Each time I call, the last character of the data must be sequential (1, 2, 3, 4, 5...). Example "XXXHDLALA01", "XXXHDLALA02", "XXXHDLALA03", etc.
The data would be the same every time I insert, but I would only change the last characters, because they are sequential numbers.
The data is as follows:
ACTC104_04358798_20220202_00001
I need to change only the last one (ACTC104_04358798_20220202_00001, ACTC104_04358798_20220202_00002, ACTC104_04358798_20220202_00003, ACTC104_04358798_20220202_00004...)
Can I do this using some kind of regex?
Thanks in advance!
Check out Counter configuration element
If you add Counter and configure it as:
In the JDBC Test Element use ${counter} as the postfix for the dynamic part:
ACTC104_04358798_20220202_${counter}
Demo:
You may also want to use __time() function as well because 20220202 looks like current date to me
ACTC104_04358798_${__time(yyyyMMdd,)}_${counter}
More information: How to Use a Counter in a JMeter Test

AMPL, set 1..T is not working

The 1..T function is not working for me, and I don't know why. My code looks like this:
set TIME;
data;
set TIME = 1..8760 by 3;
display TIME;
Here I want it to display 1, 4, 7, 10, and so on, but it just goes 1..8760 by 3. How can I fix this so that I don't have to write 8,760 different numbers?
Thankful for answers!
I don't find any error in your code. I tried in my AMPL IDE:
AMPL IDE
I suppose that when you write "data" is that your code is in the .dat file and when you write "display" is your .run file
What are you using to write your model?? NEOS SERVER or the IDE??
Regards!
Try deleting the first two lines of your code.
It looks as if the format you're using to specify TIME only works in "model" mode; in "data" mode, the same text is interpreted as declaring a set of literals "3", "by", and "1..8760". (Quick test: if you type display card(TIME); you get a value of 3, telling you that there are exactly 3 members in this set.)
Section 5.2 of the AMPL Book recommends using a "x..y by z" type declaration in the model (with x, y, z as declared params) and then specifying values for x, y, z in the data.
Note that starting at 1 and increasing in steps of 3 won't actually get to 8760 exactly, so you might want to change your start to 0 or 3, or your end to 8761, if you want equal gaps between the numbers.

Iteratively populate dataframes using a for loop in Julia

I am looking to find a way to iteratively populate a dataframe in Julia.
I have a working function that creates multiple points along a line:
#function to draw QMD lines
using DataFrames
function make_lines(qmd)
BA=Float64[]
TPA=Float64[]
QMD=Int[]
for i in stk_percent
tpa= 1*(i*10)/(a[1]+a[2]*(-0.259+0.973*qmd)+a[3]*qmd^2)
ba=pi*(qmd/24)^2*tpa
push!(TPA,tpa)
push!(BA,ba)
push!(QMD,qmd)
end
return DataFrame(TPA=TPA,BA=BA,QMD=QMD)
end
The next step I am trying to accomplish is to run the make_lines function in a loop using a pre-defined set of inputs with all the outputs in one single dataframe but I cannot get it to work.
dia = [7, 8, 10, 12, 14, 16, 18, 20, 22]
# can't get for loop to append all the data frames?
for i in dia
df=DataFrame(TPA=Float64[],BA=Float64[],QMD=Int[])
append!(df,make_lines(i))
return df
end
At first I thought it was how I was using Dataframes, I have never used Push! etc before but I got this code chunk to work
#this works to combine dataframe
test=make_lines(22)
test2=make_lines(8)
test[:]
append!(test,test2)
So why when I run the for loop, do I end up with only the last dataframe it produces?
Am I misinterpreting something? From what I have read Dataframes in Julia work differently than dataframes in R, but I cannot wrap my head around how to get this working.
You are pretty close, but there are a couple of places where you are getting tripped up in your code. You currently have:
dia = [7, 8, 10, 12, 14, 16, 18, 20, 22]
# can't get for loop to append all the data frames?
for i in dia
df=DataFrame(TPA=Float64[],BA=Float64[],QMD=Int[])
append!(df,make_lines(i))
return df
end
This isn't quite what you want for two reasons:
One: This snippet isn't a function. It thus doesn't make sense, and will cause problems, to have return in it.
Two: At each step in your loop, you are re-creating your dataframe df from scratch, erasing everything that you put before it. This is why, as you say, you only end up with the last data frame that it produces. Instead, you would want something like:
dia = [7, 8, 10, 12, 14, 16, 18, 20, 22]
df=DataFrame(TPA=Float64[],BA=Float64[],QMD=Int[])
for i in dia
append!(df,make_lines(i))
end
Note: I couldn't get a completely working version of your code going - the objects stk_percent and a in your main function never get defined, so I didn't really know what to put in for those. But, I believe that if you fix these issues you'll likely be in a better spot (I made up some values for them and it worked fine).
Performance Tip: When you do fix those, my recommendation would be to make them as explicit arguments that you pass to your function. Although it will still work if they are just variables in the global space, this will lead to suboptimal performance of your code, both now and in the future, and potentially worse things, like confusing the scope of variables, having their values change when you don't want, etc. Best to start off from the beginning of your journey with Julia adopting as many best practices in writing your code as is practicable.
I managed to create a blank dataframe by providing the type of variable and the column names
df = DataFrame([DateTime;fill(Float64, 2);String;fill(Float64, 2)],
["Date","A","B","Letter","C","D"])
Then I can append the results to populate the new dataframe by using rename! and then append! functions inside the for loop.
This is very useful for large datasets with numerous columns.

Is there a drawback in using rxjs for readonly collection manipulation

I need to do a Min and Max operation on a array getting from server side.
I am new to rxjs extensions but those library is actually mean to observe changes on a collection, but in my case its just a ONE time calculation on a collection which is no further changed then until I do a server side refresh of the data.
I just want to use the right tool for the right job, thus I ask is it correct to use rxjs here or is that shooting with bombs on flys?
Or should I rather use a library like https://github.com/ENikS/LINQ
to get the Min/Max value of a collection?
There is a LINQ implementation IxJS that is developed and maintained by the same team that is developing RxJS. This might be the right tool for you.
However, you could go with RxJS as well. When using Rx.Observable.from([1, 2, ...]) the execution is synchronous on subscription.
I would use IxJS however:
// An array of values.. (just creating some random ones here)
const values = [2, 4, 23, 1, 0, 34, 56, 2, 3, 45, 98, 6, 3];
// Create an enumerable from the array
const valEnum = Ix.Enumerable.fromArray(values);
const min = valEnum.min();
const max = valEnum.max();
Working example on jsfiddle.
https://github.com/ENikS/LINQ uses all the latest language features and theoretically much faster than IxJS. Last edit on IxJS is 3 years old. (ECMA-262/6.0/) introduced few very important advancements and speed improvements.
It also has better compliance with standard LINQ API and can operate on any collection implementing iterables, including strings, maps, typed arrays, and etc. IxJS can only query array types.

How to specify ranges in YAML?

I can express
3rd page is the title page
in YAML
title: 3
What about the following?
Pages 10 to 15 contains chapter 1
One way is
chapter 1: [10, 11, 12, 13, 14, 15]
I would prefer a range here. Is there anything like that in YAML?
chapter 1: (10..15)
** Update **
The following would be my alternative if there is no such thing as range in YAML
chapter 1:
start page: 10
end page: 15
There is not direct way to specify ranges in YAML, but some YAML can store serialized objects, for example in Ruby:
...
normal range: !ruby/range 10..20
exclusive range: !ruby/range 11...20
negative range: !ruby/range -1..-5
...
Look here
Range is application specific. The following may be meaningful for some applications:
-1 .. Q
a .. Щ
23 .. -23.45
1 .. 12:01:14 (both are integers in YAML !)
But the ruby way is also unclear since it does not say whether the end values are included or not: 10 .. 15
(Are you only talking about ranges of integers ?)
Andrey is right - there is no such thing as a basic range. Ranges can be defined on top of totally ordered data types. YAML does not even know the concept of ordering so it makes no sense to talk about ranges in YAML. YAML only knows the concept of node types, the concept of equality, and some predefined kinds of links between nodes. By the way I don't know any other data serialization lange (JSON, XML, CSV, Hessian, Protocol Buffers...) that natively supports ranges.

Resources