how to select the value alone but not the header - javascript

Then('It also should contain {int} of {word} {word}s',
(
count: number,
side: "SKIP" | "ANY" | "any",
pointType: FusionPointType
) => {
return fusionPointTotal.verifyTotalCount(pointType, side.toUpperCase(), count);
});
this is my code in .ts file
my gherkin code is
And It also should contain 0 of any proteins
header on UI is : X' status
value : - (which is empty)
expected to count 0 values
Error:
invoke.find(div.gene-info-row h5:contains("X' Status")) 289 assert
expected <h5> to have a length of 0 but got 1
error states that It is considering the value of X' Status which is empty (-) as a value
I need a code in such a way that if the value is x,y,z then count, other than these values count should be 0
example:
Header: X' status
Value : x1
count: 1
Header: X' status
Value : -
Count: 0

Related

Extract string after another string in a complicated string

I have this string -
ContactTrigger: execution of AfterInsert
caused by: System.DmlException: Update failed. First exception on row 0 with id 0032200000AYK5AAAX; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Spouse Cannot be more than 1: []
Class.ContactTriggerHelper.updateDependentData: line 309, column 1
Trigger.ContactTrigger: line 26, column 1
I need to identify if this string contains FIELD_CUSTOM_VALIDATION_EXCEPTION and I need to extract this part of the message 'Spouse Cannot be more than 1'
Which I am not able to
I tried this --
var pageErrors = saveResult.error[0].pageErrors[0].message;
console.log('pageErrors--->'+pageErrors);
var errMessage;
if(pageErrors.includes('FIELD_CUSTOM_VALIDATION_EXCEPTION')){
console.log('Inside includes');
console.log('pageErrors.indexOf("FIELD_CUSTOM_VALIDATION_EXCEPTION")-->'+pageErrors.indexOf('FIELD_CUSTOM_VALIDATION_EXCEPTION'));
console.log('pageErrors.lastIndexOf("FIELD_CUSTOM_VALIDATION_EXCEPTION")-->'+pageErrors.lastIndexOf('FIELD_CUSTOM_VALIDATION_EXCEPTION,'));
errMessage = pageErrors.substring(pageErrors.indexOf('FIELD_CUSTOM_VALIDATION_EXCEPTION'),pageErrors.lastIndexOf('FIELD_CUSTOM_VALIDATION_EXCEPTION,'));
}
You can try this
FIELD_CUSTOM_VALIDATION_EXCEPTION,\s*([^:]+)
let findValue = (str) => {
return str.match(/FIELD_CUSTOM_VALIDATION_EXCEPTION,\s*([^:]+)/i)
}
let str = `ContactTrigger: execution of AfterInsert
caused by: System.DmlException: Update failed. First exception on row 0 with id 0032200000AYK5AAAX; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Spouse Cannot be more than 1: []
Class.ContactTriggerHelper.updateDependentData: line 309, column 1 Trigger.ContactTrigger: line 26, column 1`
console.log(findValue(str))
console.log(findValue(str)[1])
let str2 = `ContactTrigger: execution of AfterInsert
caused by: System.DmlException: Update failed. First exception on row 0 with id 0032200000AYK5AAAX;
Class.ContactTriggerHelper.updateDependentData: line 309, column 1 Trigger.ContactTrigger: line 26, column 1`
console.log(findValue(str2))
You can even do something simpler and faster than regular expressions. Since you know the exact error message you need to track, you can split the error string from end of the error massage up to end of line or up to ":" character (you can also optionally trim it if you need to remove any surrounding spaces).
So:
const str = `ContactTrigger: execution of AfterInsert
caused by: System.DmlException: Update failed. First exception on row 0 with id 0032200000AYK5AAAX; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Spouse Cannot be more than 1: []
Class.ContactTriggerHelper.updateDependentData: line 309, column 1 Trigger.ContactTrigger: line 26, column 1`;
const ERR = 'FIELD_CUSTOM_VALIDATION_EXCEPTION,';
const ind = str.indexOf(ERR);
let msg = -1 < ind ? str.slice(ind+ERR.length, str.indexOf("\n",ind+ERR.length)) : null;
msg = msg ? msg.trim() : null; // optionally trim it as well
console.log(str);
console.log(msg);

Unexpected true value returned from function comparing getComputedStyle().width values

I have the following function
const wider_than = (el1, el2) => getComputedStyle(el1).width > getComputedStyle(el2).width;
I am using it to control the innerhtml value of a nested div. If the inner div is wider than the outter div i want the inner div to set its text to "error". Else I want to set it to a user defined value.
But the function is returning true at unexpected times. Using the following logs
console.log(getComputedStyle(display_text).width);
console.log(getComputedStyle(display).width);
console.log(wider_than(display_text, display));
console.log(getComputedStyle(display_text).width > getComputedStyle(display).width);
and updating the value of the display_text innerHTML character by character, it runs normally for the first character but then breaks for the second character. Here is the outputs from the logs
53.3958px
639px
false
false
80.0625px
639px
true
true
Can anyone explain why this might be happening?
console.log('"b" > "a" :', "b" > "a");//"b" comes after "a"
console.log('"bun" > "abbot" :', "bun" > "abbot");//"b" comes after "a" regardless of word length
console.log('"2" > "1" :', "2" > "1");
console.log('"2" > "100" :', "2" > "100");
There is a good reason for strings to not be sorted like numbers - imagine you have a playlist and are trying to sort song titles, "7" by Arctic Monkeys should come after "19th Nervous Breakdown" by the Rolling Stones.
The parseFloat global function is tailored to extracting numbers from strings that start with them. So it's ideal for size values like "53.3958px"
const size1 = "53.3958px";
const size2 = "639px";
const size3 = "80.0625px";
console.log(`${size1} > ${size2} compared as strings:`, size1 > size2);
console.log(`${size1} > ${size2} compared as numbers:`, parseFloat(size1) > parseFloat(size2));
console.log(`${size3} > ${size2} compared as strings:`, size3 > size2);
console.log(`${size3} > ${size2} compared as numbers:`, parseFloat(size3) > parseFloat(size2));

Displaying a currency from a number

How can I change a number ( integer ) into a currency format while live input/typing?
ex :
45678 => 456.78
or
234567 => 2345.67 or 2,345.67 or 2 345.67
( depending on the mask format used )
Before people start tagging this question as an existing one, I have already seen the existing codes that format numbers, but those examples do not handle the last two numbers as decimals. Instead those format the string 45678 into 45 678.00 or 45,678.00 instead of 456.78.
Something like convert:
######## into ### ###.##
You could iterate the mask and reassemble the result string.
It creates from both values two arrays (with spread syntax ...) for a single number or mask character in an array.
Then it iterates the mask characters from the right side and
(m === '#' ? v.pop() || '' : v.length ? m : '') + s
builds a new string with either a numerical value, if # is found
m === '#' ? v.pop() || ''
or takes the value of the mask by checking the length of the values
v.length ? m : ''
to prevent adding spaces or unwanted characters.
function convert(i, mask) {
var v = [...i.toString()];
return [...mask].reduceRight((s, m) => (m === '#' ? v.pop() || '' : v.length ? m : '') + s, '');
}
console.log(convert(45678, '### ###.##')); // 456.78
console.log(convert(234567, '### ###.##')); // 2345.67
console.log(convert(234567, '###,###.##')); // 2,345.67
console.log(convert(234567, '### ###.##')); // 2 345.67
Add an event handler for when you type into the input to format the value for that input.
$('#myTextbox').keyup(function(){
$(this).val(($(this).val() /100).toFixed(2);
});
(number).toFixed() function converts a number to string. To avoid this try:
var x4 = 999546765687;
x4 = x4/100;
x4.toFixed(2);
Number(x4)
The toLocaleString() method returns a string with a language sensitive representation of this number.
var currency = 234567/100;
var currencyString = currency.toLocaleString('en-US')
console.log(currencyString);
For angular
https://angular.io/api/common/CurrencyPipe
Try using
#Component({
selector: 'currency-pipe',
template: `
A: {{a | currency}}
<!--output 'CA$0.26'-->
<p>A: {{a | currency:'CAD'}}</p>
<!--output 'CAD0.26'-->
<p>A: {{a | currency:'CAD':'code'}}</p>
<!--output 'CA$0,001.35'-->
<p>B: {{b | currency:'CAD':'symbol':'4.2-2'}}</p>
<!--output '$0,001.35'-->
<p>B: {{b | currency:'CAD':'symbol-narrow':'4.2-2'}}</p>
<!--output '0 001,35 CA$'-->
<p>B: {{b | currency:'CAD':'symbol':'4.2-2':'fr'}}</p>
</div>`
})
export class CurrencyPipeComponent {
a: number = 0.259;
b: number = 1.3495;
}

Check that a mathematical operation (adding, multiplying) can be done successfully in javascript?

Given a specific group of "Strings" that represent integers in an addition operation, how is it possible to know if the calculation is possible in javascript? for instance.
2 + 2 (definetly possible)
20000000000000000 - 1 (not possible)
2e50 + 2e60 (not possible)
200000 + 5 + 40 + 300 + 2000 + 10000 (possible)
The same applies to multiplication, several integers, duable or not?
2*2 (possible)
3*2e200 (possible)
4*-3e700 (not possible)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
Open your browsers error console and view what this does.
"use strict";
var i,
numbers=[
2+2,
20000000000000000 - 1,
2e50 + 2e60,
200000 + 5 + 40 + 300 + 2000 + 10000,
2*2,
3*2e200,
4*-3e700
],
s=numbers.length;
for(i=0;i<s;i++){
console.log(
'The value of array index '+i+' is'+
((Number.isSafeInteger((numbers[i])))?'':' NOT')+
' Safe'
);
}
Output from console:
The value of array index 0 is Safe
The value of array index 1 is NOT Safe
The value of array index 2 is NOT Safe
The value of array index 3 is Safe
The value of array index 4 is Safe
The value of array index 5 is NOT Safe
The value of array index 6 is NOT Safe
Some of these number may be accurate, but can not be compared to determine which is greater

Postgresql9.3 query optimization

I am using postgresql 9.3 in my node.js application. In my database i have some 7lakhs records now. Also in my database i have json datatype column.
My query is as following:
EXPLAIN ANALYSE select id_0, name_0, id_1, name_1, id_2, name_2, id_3, name_3, id_4, name_4, latitude, longitude, to_char(collecteddate, 'dd/mm/yyyy') as collecteddate, key, value->>'xxxxx' as value from table where
CAST(value->'xxxxx'->> 'aaaaa' as INTEGER)BETWEEN 1 and 43722 and value->'PCA_2011'->> 'aaaaa' NOT LIKE ' ' and
CAST(value->'xxxxx'->> 'bbbbb' as INTEGER)BETWEEN 1 and 100 and value->'xxxx'->> 'bbbbb' NOT LIKE ' '
and leveltype = 'nnnn' and id_1= 'ww' and id_0 = 'uuu' and collecteddate = '2011-03-31';
This query will retrieve almost 1lakh records and takes 3 secs to be executed. I have created index for the json column and also the columns in where conditions. But i think its very long time to execute. Is there any way to reduce the execution time. I am new to this database optimization concepts, is there any optimization techniques to reduce my execution time to some milli seconds. Thanks in advance..
EDIT:
My index definition:
CREATE INDEX index_pop on table (id_0, id_1, collecteddate, leveltype, key, (value->'xxxxx'->>'aaaa'));
My Explain analyses result:
"Bitmap Heap Scan on table (cost=1708.27..59956.46 rows=1 width=132) (actual time=880.576..5137.266 rows=93615 loops=1)"
" Recheck Cond: (((id_0)::text = '356'::text) AND ((id_1)::text = '9'::text) AND (collecteddate = '2011-03-31'::date) AND ((leveltype)::text = 'pppp'::text))"
" Filter: ((((value -> 'xxxx'::text) ->> 'aaaa'::text) !~~ ' '::text) AND (((value -> 'xxxxx'::text) ->> 'bbbb'::text) !~~ ' '::text) AND ((((value -> 'xxxxx'::text) ->> 'aaaaa'::text))::integer >= 1) AND ((((value -> 'PCA (...)"
" Rows Removed by Filter: 4199"
" -> Bitmap Index Scan on index_name (cost=0.00..1708.27 rows=37856 width=0) (actual time=828.856..828.856 rows=97814 loops=1)"
" Index Cond: (((id_0)::text = '356'::text) AND ((id_1)::text = '9'::text) AND (collecteddate = '2011-03-31'::date) AND ((leveltype)::text = 'ppppp'::text))"
"Total runtime: 5211.271 ms"
ALso 1 more thing: Bitmap Index Scan on index_name is different index other than in my where condition index, also y only 1 index is earched??

Categories

Resources