Jest - How to run .each in parallel - jestjs

I'm currently using test.each, anyway to run them in parallel instead of synchronously?
test.each`
searchEngine | keyword | urlToVisit
${'https://google.com/?num=100'} | ${'aol'} | ${'a[href="https://www.aol.com/"]'}
${'https://google.com/?num=100'} | ${'aol'} | ${'a[href="https://www.aol.com/"]'}
`('should search on google and navigate to domain', async ({

It has been available since Jest 26.3 (via https://github.com/facebook/jest/pull/9326).
test.concurrent.each([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3],
])('.add(%i, %i)', async (a, b, expected) => {
expect(a + b).toBe(expected);
});
https://jestjs.io/docs/api#testconcurrenteachtablename-fn-timeout

Related

How to read predict() result in Tensorflowjs using a SavedModel

Code using tfjs-node:
const model = await tf.node.loadSavedModel(modelPath);
const data = fs.readFileSync(imgPath);
const tfimage = tf.node.decodeImage(data, 3);
const expanded = tfimage.expandDims(0);
const result = model.predict(expanded);
console.log(result);
for (r of result) {
console.log(r.dataSync());
}
Output:
(8) [Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor]
Float32Array(100) [48700, 48563, 48779, 48779, 49041, 48779, ...]
Float32Array(400) [0.10901492834091187, 0.18931034207344055, 0.9181075692176819, 0.8344497084617615, ...]
Float32Array(100) [61, 88, 65, 84, 67, 51, 62, 20, 59, 9, 18, ...]
Float32Array(9000) [0.009332209825515747, 0.003941178321838379, 0.0005068182945251465, 0.001926332712173462, 0.0020033419132232666, 0.000742495059967041, 0.022082984447479248, 0.0032682716846466064, 0.05071520805358887, 0.000018596649169921875, ...]
Float32Array(100) [0.6730095148086548, 0.1356855034828186, 0.12674063444137573, 0.12360832095146179, 0.10837388038635254, 0.10075071454048157, ...]
Float32Array(1) [100]
Float32Array(196416) [0.738592267036438, 0.4373246729373932, 0.738592267036438, 0.546840488910675, -0.010780575685203075, 0.00041256844997406006, 0.03478313609957695, 0.11279871314764023, -0.0504981130361557, -0.11237315833568573, 0.02907072752714157, 0.06638012826442719, 0.001794634386897087, 0.0009463857859373093, ...]
Float32Array(4419360) [0.0564018189907074, 0.016801774501800537, 0.025803595781326294, 0.011671125888824463, 0.014013528823852539, 0.008442580699920654, ...]
How do I read the predict() response for object detection? I was expecting a dictionary with num_detections, detection_boxes, detection_classes, etc. as described here.
I also tried using tf.execute(), but it throws me the following error: UnhandledPromiseRejectionWarning: Error: execute() of TFSavedModel is not supported yet.
I'm using efficientdet/d0 downloaded from here.
When you download the tensor using dataSync() it just keeps the value. If you wanted the object with a description of each of the results without the tensors you would just have to console.log(result). Then you expand the result from your log in the browsers console it should return something like this:
Tensor {
"dataId": Object {},
"dtype": "float32",
"id": 160213,
"isDisposedInternal": false,
"kept": false,
"rankType": "2",
"scopeId": 365032,
"shape": Array [
1,
3,
],
"size": 3,
"strides": Array [
3,
],
}
The output of your console.log(result) contains 8 tensors within it which shows that it is correct. You are looping over each of the results and each of the outputs should follow this format :
['num_detections', 'detection_boxes', 'detection_classes', 'detection_scores', 'raw_detection_boxes', 'raw_detection_scores, 'detection_anchor_indices', 'detection_multiclass_scores']

Neither 'day_of_week' nor 'which_occurrence' can be specified when creating a monthly date-based trigger

When trying to switch a schedule trigger from a monthly by-weekday schedule to a by-date schedule, I get an error saying 'day_of_week' nor 'which_occurrence' can be specified when creating a monthly date-based trigger.
However, I am not using either of these properties in the new configuration.
Error: Neither 'day_of_week' nor 'which_occurrence' can be specified when creating a monthly date-based trigger
Error: /Stage[main]/Windowsupdate::Config/Scheduled_task[Run Windows Update]/trigger: change from [
{
'schedule' => 'monthly',
'months' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
'which_occurrence' => 'second',
'day_of_week' => ['saturday'],
'start_date' => '2018-8-7',
'start_time' => '13:15',
'enabled' => true,
'minutes_interval' => 80,
'minutes_duration' => 560,
'index' => 0
}] to [
{
'schedule' => 'monthly',
'start_time' => '13:15',
'months' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
'on' => 15,
'minutes_interval' => '80',
'minutes_duration' => '560'
}] failed: Neither 'day_of_week' nor 'which_occurrence' can be specified when creating a monthly date-based trigger
This appears to be a bug in the scheduled_task module. When I remove the existing task and run the code again, it applies without issue.

Type error in Nodejs and Postgres

I'm generating a dynamic update query based on a list of provided objects for postgres. This is what my query looks like:
update loan_item_assignment as t set id = c.id, dateselectionid = c.dateselectionid, loanitemid = c.loanitemid, active = c.active, type = c.type from (values ( $1, $2, $3, $4, $5 ), ( $6, $7, $8, $9, $10 ), ( $11, $12, $13, $14, $15 ), ( $16, $17, $18, $19, $20 ), ( $21, $22, $23, $24, $25 ), ( $26, $27, $28, $29, $30 ), ( $31, $32, $33, $34, $35 ), ( $36, $37, $38, $39, $40 ) ) as c( id, dateselectionid, loanitemid, active, type ) where c.id = t.id returning *
And here's the values list I'm giving it:
[ 7,
35,
3,
true,
'normal',
8,
35,
4,
true,
'normal',
1,
35,
6,
true,
'normal',
2,
35,
7,
true,
'normal',
3,
35,
8,
true,
'normal',
5,
35,
10,
true,
'normal',
4,
35,
11,
true,
'normal',
6,
35,
12,
true,
'normal' ]
As far as I can tell, the values match up correctly. This is the error I'm seeing:
{ [error: operator does not exist: text = integer]
name: 'error',
length: 195,
severity: 'ERROR',
code: '42883',
detail: undefined,
hint: 'No operator matches the given name and argument type(s). You might need to add explicit type casts.',
position: '448',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_oper.c',
line: '726',
routine: 'op_error' }
And this is the code that's ultimately running the query:
var performQuery = function(text, values, cb) {
pg.connect(connectionString, function(err, client, done) {
client.query(text, values, function(err, result) {
done();
if (!result) {
console.log(err);
cb([], err);
} else {
cb(result.rows, err);
}
})
});
}
And here is the table definition:
Table "public.loan_item_assignment"
Column | Type | Modifiers | Storage | Stats target | Description
-----------------+---------+-------------------------------------------------------------------+----------+--------------+-------------
id | integer | not null default nextval('loan_item_assignment_id_seq'::regclass) | plain | |
dateselectionid | integer | | plain | |
loanitemid | integer | | plain | |
active | boolean | | plain | |
type | text | | extended | |
Indexes:
"loan_item_assignment_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
"loan_item_assignment_dateselectionid_fkey" FOREIGN KEY (dateselectionid) REFERENCES date_selection(id)
"loan_item_assignment_loanitemid_fkey" FOREIGN KEY (loanitemid) REFERENCES loan_item(id)
Vitaly-t's comment on my answer is the solution - to use the pg-promise library to generate the query, and specifically method helpers.update for generating multi-row update queries, as shown in PostgreSQL multi-row updates in Node.js.

pass array of arrays from routes to view node.js

I am trying to pass an array of arrays from routes to view page. My data that I am trying to pass is :
[
[10, 10],
[20, 50],
[30, 120],
[40, 80],
[50, 90],
[60, 50],
[70, 70],
[80, 90],
[90, 150],
[100, 50],
[110, 40],
[120, 70],
[130, 20],
[140, 40],
[200, 30]
]
I am getting it in below format:
["10,10,20,50,30,120,40,80,50,90,60,50,70,70,80,90,90,150,100,50,110,40,120,70,130,20,140,40,200,30"]
but I need it in the same format I am sending.
My index.js(routes file) is:
router.get('/', function(req, res, next) {
var dataset = [
[10, 10],
[20, 50],
[30, 120],
[40, 80],
[50, 90],
[60, 50],
[70, 70],
[80, 90],
[90, 150],
[100, 50],
[110, 40],
[120, 70],
[130, 20],
[140, 40],
[200, 30]
];
console.log(dataset);
res.render('index',{"data" : [dataset]});
});
module.exports = router;
and in my view file, I am trying to get it like:
<div class="hold_data" data-info={{data}}></div>
Please suggest if anyone knows how this can be achieved. Thanks in advance :)
Try JSON.stringify as below -
res.render('index',{"data" : JSON.stringify(dataset)});
Hope this helps.

Google Line charts Customizing vAxes with string and define position

I try to implement a Line Chart with string on xAxie and vAxie.
For vAxie I want to start to 10eme and finish with 1er value. Is it possible to switch these values?
Today :
10eme
9eme
8eme
7eme
6eme
4eme
3eme
2eme
1er
1 journee / 2 journee / 3 journee / ...
Target :
1er
2eme
3eme
4eme
5eme
6eme
7eme
8eme
9eme
10eme
1 journee / 2 journee / 3 journee / ...
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Journee', 'Position'],
['1 Journee', 10],
['2 Journee', 7],
['3 Journee', 7],
['4 Journee', 6],
['5 Journee', 8],
['6 Journee', 9],
['7 Journee', 10]
]);
var options = {
title: 'Evolution au classement',
hAxis: {title: 'Journee', titleTextStyle: {color: '#333'}},
vAxis: {title: 'Classement'},
vAxis: {minValue: 1},
vAxis: {maxValue: 10},
viewWindowMode:'explicit',
vAxis: {title: 'Classement', ticks: [{v:1, f:"1er"},{v:9, f:"9eme"},{v:8, f:"8eme"},{v:7, f:"7eme"},{v:6, f:"6eme"},{v:5, f:"5eme"},{v:4, f:"4eme"},{v:3, f:"3eme"},{v:2, f:"2eme"},{v:10, f:"10eme"}]},
pointSize: 5,
};
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
it is ok I found a way to do it with direction: -1 in vaxis option.
here the result.
Thank you
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Journee', 'EQUIPE 1', 'EQUIPE 2'],
['1 Journee', 1, 3],
['2 Journee', 2, 5],
['3 Journee', 5, 4],
['4 Journee', 5, 3],
['5 Journee', 6, 5],
['6 Journee', 4, 6],
['7 Journee', 2, 7]
]);
var options = {
title: 'Evolution au classement',
curveType: 'function',
hAxis: {title: 'Journee', titleTextStyle: {color: '#333'}},
vAxis:
{title: 'Classement', minValue: 0, maxValue: 11, direction: -1, ticks: [{v:0, f:""},{v:1, f:"1er"},{v:9, f:"9eme"},{v:8, f:"8eme"},{v:7, f:"7eme"},{v:6, f:"6eme"},{v:5, f:"5eme"},{v:4, f:"4eme"},{v:3, f:"3eme"},{v:2, f:"2eme"},{v:10, f:"10eme"},{v:11, f:""}]},
pointSize: 5,
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>

Resources