Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

how to access datamatrix using javascript?

Hi,

I want to copy the data in one datamatrix to another datamatrix in the same experiment.

I use python inline script and it works well:

items['new_loop_1'].dm.ID[0] = items['new_loop'].dm.ID[5]

items['new_loop_1'].dm.conditions[0] = items['new_loop'].dm.conditions[5]

Because I am going to run this experiment in OSWEB, so I need to change it to javascript.

I will be appreciated if you could help me with how I can achieve the same function using javascript.

Thank you!

Jing

Comments

  • edited May 11

    Hi @jing ,

    In OSWeb, the loop items do not use a DataMatrix, but a custom JavaScript object. In principle, you can access this also programmatically. Say that you want to print out the 'matrix' for an item called block_loop:

    console.log(this.experiment.items._items["block_loop"].matrix)
    

    But it's not really intended to be used that way, and so it's probably best to think of a different solution.

    What exactly do you want to do?

    — Sebastiaan

    Buy Me A Coffee

  • Hi @sebastiaan,

    thank you very much for your reply!

    In my experiment there are two loops (matrixes), the "new_loop" is filled with data and has many columns and rows, one of the column is "ID". The "new_loop_1" is a "empty" matrix, it only has the same column names as the new loop, but it is not filled with actual data.

    I want to copy special rows according to specific order from the new_loop to the new_loop_1, for example,

    the row with ID = 5 from the "new loop" will be copied to the "new_loop_1" and serves as row 0.

    the row with ID = 33 from the "new loop" will be copied to the "new_loop_1" and serves as row 1.

    the row with ID = 60 from the "new loop" will be copied to the "new_loop_1" and serves as row 2.

    Through this way, the new_loop_1will have the order and specfic data I want. When I run this experiment, the originally empty new_loop_1 will be filled with some specfic data from new loop.

    I do not need to print the matrix in the console, I want the data in one "matrix" be copied in another matrix according to the order I specified. I hope that I have made it clear.

    Thank you again for your help!!

    Best wishes,

    Jing

  • Hello @sebastiaan,

    I have solved the problem of copying special rows from one matrix to another matrix through

    this.experiment.items._items["new_loop_1"].matrix[0] =this.experiment.items._items["new_loop"].matrix[5]

    this.experiment.items._items["new_loop_1"].matrix[1] =this.experiment.items._items["new_loop"].matrix[33]

    this.experiment.items._items["new_loop_1"].matrix[2] =this.experiment.items._items["new_loop"].matrix[60]

    Everything worked well, but there is still one problem that I was not able to solve.

    That is, after copying the matrix, the row 0 in the new_loop_1 can not be presented in the sketchpad. The row 1 and row 2 worked well.

    I have checked the console and found that:

    in the first trial, this.experiment.items._items["new_loop_1"].matrix[0].Phrase1 was filled with data from this.experiment.items._items["new_loop"].matrix[5].Phrase1, such as "abc", but vars.Phrase1 of new _loop_1 was empty.

    In the second and third trial, this.experiment.items._items["new_loop_1"].matrix[0].Phrase1 was filled with data, such as "bcd", and vars.Phrase1 was filled with the same data.

    This is the problem why the first trial can not be presented in the sketchpad. But I was not sure, why in the first trial the value of this.experiment.items._items["new_loop_1"].matrix[0].Phrase1 can not be automatically given to the variable vars.Phrase1, but in the following trials it worked.


    Could you please help me with this question?

    Thank you very much!

    Best wishes!

    Jing

  • Hi Jing,

    Does it work for the last trial? I don't know how the matrix object is represented internally, but it could be a problem that the first line is interpreted as header and not as content, so that it is skipped. Further alternatives could be trying to copying the information line by line.

    You could also share your experiment here. Unfortunately though, without an api, I won't be able to help you much. At least, I don't know what kind of objects this matrix is and what operations are defined on it.

    Hope this helps,

    Eduard

    Buy Me A Coffee

  • Hi, @eduard,

    thank you very much for your reply. Yes, it worked for the last trial, as you said, maybe the first line is interpreted as header.

    I solved the problem by copying the trial to the second, third, fourth... lines, the first line is empty and unused.

    this.experiment.items._items["new_loop_1"].matrix[1] =this.experiment.items._items["new_loop"].matrix[5]

    this.experiment.items._items["new_loop_1"].matrix[2] =this.experiment.items._items["new_loop"].matrix[33]

    this.experiment.items._items["new_loop_1"].matrix[3] =this.experiment.items._items["new_loop"].matrix[60]

    The new_loop_1 begins from line1. I leave this.experiment.items._items["new_loop_1"].matrix[0] empty. This time it works perfect.

    Thank you!

    Best wishes

    Jing

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games