Jmeter - How to compare two numbers using threshold - jmeter

For the purpose of my testing i need to compare two numbers, which are real numbers.
a) 0.070103 vs. b) 0.0701029999999999986
What is the best way to archive that, if possible with threshold included?

How about rounding them?
Something like:
import java.math.MathContext
def a = 0.070103
def b = 0.0701029999999999986
def roundedA = a.round(new MathContext(5))
def roundedB = b.round(new MathContext(5))
log.info('Rounded a: ' + roundedA)
log.info('Rounded b: ' + roundedB)
log.info('Numbers are equal: ' + roundedA.equals(roundedB))
More information:
BigDecimal.round()
MathContext
Scripting JMeter Assertions in Groovy - A Tutorial

Related

How do I repeat the number in the command code?

I'm a newbie of programming, and i have a basic question.
The bottom is the code I made to extract Excel data.
import os
path = "./data"
file_list = os.listdir(path)
from openpyxl import load_workbook
results = []
for file_name_raw in file_list:
file_name = "./data/"+file_name_raw
wb = load_workbook(filename=file_name, data_only=True)
Ad = wb.get_sheet_by_name('Advanced')
result = []
**result.append(Ad['C1'].value)
result.append(Ad['C2'].value)
result.append(Ad['C3'].value)
result.append(Ad['C4'].value)
result.append(Ad['C5'].value)
...
result.append(Ad['C100'].value)**
results.append(result)
print(results)
If i want to repeat the number in the result.append(Ad['C number ].value)
how can i make a code? Is there a way to use for loop?
You can write this in a for loop.
Define a range for your repetitions, let's say you want to do result.append(...) for 100 times, then:
Assuming you are using python
for i in range(1, 100):
result.append(Ad['C' + str(i) ].value)
OR
By specifying a limit:
n = 100
for i in range(1, n):
result.append(Ad['C' + str(i) ].value)

Lua Random number generator always produces the same number

I have looked up several tutorials on how to generate random numbers with lua, each said to use math.random(), so I did. however, every time I use it I get the same number every time, I have tried rewriting the code, and I always get the lowest possible number. I even included a random seed based on the OS time. code below.
require "math"
math.randomseed(os.time())
num = math.random(0,10)
print(num)
I'm using the random function like this:
math.randomseed(os.time())
num = math.random() and math.random() and math.random() and math.random(0, 10)
This is working fine. An other option would be to improve the built-in random function, described here.
This might help! I had to use these functions to write a class that generates Nano IDs. I basically used the milliseconds from the os.clock() function and used that for math.randomseed().
NanoId = {
validCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",
generate = function (size, validChars)
local response = ""
local ms = string.match(tostring(os.clock()), "%d%.(%d+)")
local temp = math.randomseed(ms)
if (size > 0 and string.len(validChars) > 0) then
for i = 1, size do
local num = math.random(string.len(validChars))
response = response..string.sub(validChars, num, num)
end
end
return response
end
}
function NanoId:Generate()
return self.generate(21, self.validCharacters)
end
-- Runtime Testing
for i = 1, 10 do
print(NanoId:Generate())
end
--[[
Output:
>>> p2r2-WqwvzvoIljKa6qDH
>>> pMoxTET2BrIjYUVXNMDNH
>>> w-nN7J0RVDdN6-R9iv4i-
>>> cfRMzXB4jZmc3quWEkAxj
>>> aFeYCA2kgOx-s4UN02s0s
>>> xegA--_EjEmcDk3Q1zh7K
>>> 6dkVRaNpW4cMwzCPDL3zt
>>> R2Fct5Up5OwnHeExDnqZI
>>> JwnlLZcp8kml-MHUEFAgm
>>> xPr5dULuv48UMaSTzdW5J
]]

Extract multiple protein sequences from a Protein Data Bank along with Secondary Structure

I want to extract protein sequences and their corresponding secondary structure from any Protein Data bank, say RCSB. I just need short sequences and their secondary structure. Something like,
ATRWGUVT Helix
It is fine even if the sequences are long, but I want a tag at the end that denotes its secondary structure. Is there any programming tool or anything available for this.
As I've shown above I want only this much minimal information. How can I achieve this?
from Bio.PDB import *
from distutils import spawn
Extract sequence:
def get_seq(pdbfile):
p = PDBParser(PERMISSIVE=0)
structure = p.get_structure('test', pdbfile)
ppb = PPBuilder()
seq = ''
for pp in ppb.build_peptides(structure):
seq += pp.get_sequence()
return seq
Extract secondary structure with DSSP as explained earlier:
def get_secondary_struc(pdbfile):
# get secondary structure info for whole pdb.
if not spawn.find_executable("dssp"):
sys.stderr.write('dssp executable needs to be in folder')
sys.exit(1)
p = PDBParser(PERMISSIVE=0)
ppb = PPBuilder()
structure = p.get_structure('test', pdbfile)
model = structure[0]
dssp = DSSP(model, pdbfile)
count = 0
sec = ''
for residue in model.get_residues():
count = count + 1
# print residue,count
a_key = list(dssp.keys())[count - 1]
sec += dssp[a_key][2]
print sec
return sec
This should print both sequence and secondary structure.
You can use DSSP.
The output of DSSP is explained extensively under 'explanation'. The very short summary of the output is:
H = α-helix
B = residue in isolated β-bridge
E = extended strand, participates in β ladder
G = 3-helix (310 helix)
I = 5 helix (π-helix)
T = hydrogen bonded turn
S = bend

What is the difference between gensim LabeledSentence and TaggedDocument

Please help me in understanding the difference between how TaggedDocument and LabeledSentence of gensim works. My ultimate goal is Text Classification using Doc2Vec model and any classifier. I am following this blog!
class MyLabeledSentences(object):
def __init__(self, dirname, dataDct={}, sentList=[]):
self.dirname = dirname
self.dataDct = {}
self.sentList = []
def ToArray(self):
for fname in os.listdir(self.dirname):
with open(os.path.join(self.dirname, fname)) as fin:
for item_no, sentence in enumerate(fin):
self.sentList.append(LabeledSentence([w for w in sentence.lower().split() if w in stopwords.words('english')], [fname.split('.')[0].strip() + '_%s' % item_no]))
return sentList
class MyTaggedDocument(object):
def __init__(self, dirname, dataDct={}, sentList=[]):
self.dirname = dirname
self.dataDct = {}
self.sentList = []
def ToArray(self):
for fname in os.listdir(self.dirname):
with open(os.path.join(self.dirname, fname)) as fin:
for item_no, sentence in enumerate(fin):
self.sentList.append(TaggedDocument([w for w in sentence.lower().split() if w in stopwords.words('english')], [fname.split('.')[0].strip() + '_%s' % item_no]))
return sentList
sentences = MyLabeledSentences(some_dir_name)
model_l = Doc2Vec(min_count=1, window=10, size=300, sample=1e-4, negative=5, workers=7)
sentences_l = sentences.ToArray()
model_l.build_vocab(sentences_l )
for epoch in range(15): #
random.shuffle(sentences_l )
model.train(sentences_l )
model.alpha -= 0.002 # decrease the learning rate
model.min_alpha = model_l.alpha
sentences = MyTaggedDocument(some_dir_name)
model_t = Doc2Vec(min_count=1, window=10, size=300, sample=1e-4, negative=5, workers=7)
sentences_t = sentences.ToArray()
model_l.build_vocab(sentences_t)
for epoch in range(15): #
random.shuffle(sentences_t)
model.train(sentences_t)
model.alpha -= 0.002 # decrease the learning rate
model.min_alpha = model_l.alpha
My question is model_l.docvecs['some_word'] is same as model_t.docvecs['some_word']?
Can you provide me weblink of good sources to get a grasp on how TaggedDocument or LabeledSentence works.
LabeledSentence is an older, deprecated name for the same simple object-type to encapsulate a text-example that is now called TaggedDocument. Any objects that have words and tags properties, each a list, will do. (words is always a list of strings; tags can be a mix of integers and strings, but in the common and most-efficient case, is just a list with a single id integer, starting at 0.)
model_l and model_t will serve the same purposes, having trained on the same data with the same parameters, using just different names for the objects. But the vectors they'll return for individual word-tokens (model['some_word']) or document-tags (model.docvecs['somefilename_NN']) will likely be different – there's randomness in Word2Vec/Doc2Vec initialization and training-sampling, and introduced by ordering-jitter from multithreaded training.

sorting a nested list by both members of an element

I have a nested list in which I want to sort by the inner and outer elements. I have looked at other solutions on stackoverflow and tried several but none of them work the way I want them to. Below, I've presented four attempts that don't work. The comments for each block of code speak for themselves as to what I'm doing and what I want to accomplish.
from operator import itemgetter
# a representation of my real data to be sorted
list_1 = [['key_e', ['v4eee', 'v1eee', 'v3eee', 'v2eee']], ['key_d', ['v4ddd', 'v1ddd', 'v3ddd', 'v2ddd']], ['key_a', ['v4aaa', 'v1aaa', 'v3aaa', 'v2aaa']], ['key_c', ['v4ccc', 'v1ccc', 'v3ccc', 'v2ccc']], ['key_b', ['v4bbb', 'v1bbb', 'v3bbb', 'v2bbb']]]
"""
# same data as above but formatted for readability
list_1 =
[
['key_e', ['v4eee', 'v1eee', 'v3eee', 'v2eee']],
['key_d', ['v4ddd', 'v1ddd', 'v3ddd', 'v2ddd']],
['key_a', ['v4aaa', 'v1aaa', 'v3aaa', 'v2aaa']],
['key_c', ['v4ccc', 'v1ccc', 'v3ccc', 'v2ccc']],
['key_b', ['v4bbb', 'v1bbb', 'v3bbb', 'v2bbb']]
]
"""
# when running the code, pick 1 of the 4 below sort methods and comment out the other 3
# sort method #1 that doesn't work the way I want it to
list_1.sort(key = lambda x: x[1])
list_1.sort(key = itemgetter(0))
"""
# sort method #2 that doesn't work the way I want it to
list_1 = sorted(list_1, key = lambda x: (x[0], x[1]))
"""
"""
# sort method #3 that doesn't work the way I want it to
list_1.sort(key = itemgetter(1))
list_1.sort(key = itemgetter(0))
"""
"""
# sort method #4 that doesn't work the way I want it to
list_1.sort(key = itemgetter(0, 1))
"""
# print the sorted data
for d in list_1:
print d[0] + ',' + d[1][0] + ',' + d[1][1] + ',' + d[1][2] + ',' + d[1][3] + '\r\n'
"""
# what I get using any of the sort methods
key_a,v4aaa,v1aaa,v3aaa,v2aaa
key_b,v4bbb,v1bbb,v3bbb,v2bbb
key_c,v4ccc,v1ccc,v3ccc,v2ccc
key_d,v4ddd,v1ddd,v3ddd,v2ddd
key_e,v4eee,v1eee,v3eee,v2eee
# what I want
key_a,v1aaa,v2aaa,v3aaa,v4aaa
key_b,v1bbb,v2bbb,v3bbb,v4bbb
key_c,v1ccc,v2ccc,v3ccc,v4ccc
key_d,v1ddd,v2ddd,v3ddd,v4ddd
key_e,v1eee,v2eee,v3eee,v4eee
"""
I think you want the sub-lists to be sorted, and the outer list to be sorted. In which case, do it in two steps:
sorted_inner = [[k, sorted(l)] for k, l in list_1]
sorted_outer = sorted(sorted_inner)
This gives me:
sorted_outer == [['key_a', ['v1aaa', 'v2aaa', 'v3aaa', 'v4aaa']],
['key_b', ['v1bbb', 'v2bbb', 'v3bbb', 'v4bbb']],
['key_c', ['v1ccc', 'v2ccc', 'v3ccc', 'v4ccc']],
['key_d', ['v1ddd', 'v2ddd', 'v3ddd', 'v4ddd']],
['key_e', ['v1eee', 'v2eee', 'v3eee', 'v4eee']]]

Resources