Leeps-Lab / random_number_game

MIT License
0 stars 1 forks source link

Number displayed as image is from previous round #14

Open mgutierrezc opened 3 years ago

mgutierrezc commented 3 years ago

Hi @alkngo,

I've managed to create an optimized version of the code using JS, but there is a problem I would like your help with.

In each stage, the code is displaying the task numbers as images starting from the third round. However, when an image is displayed, it is the one from the previous round.

The code for displaying the images is the following:

https://github.com/Leeps-Lab/random_number_game/blob/79f09e192a5b6a7f31b829c044e2bbcbb1208417/templates/random_number_game/Decision.html#L15

In {% block scripts %}: https://github.com/Leeps-Lab/random_number_game/blob/79f09e192a5b6a7f31b829c044e2bbcbb1208417/templates/random_number_game/Decision.html#L33-L45

https://github.com/Leeps-Lab/random_number_game/blob/79f09e192a5b6a7f31b829c044e2bbcbb1208417/templates/random_number_game/Decision.html#L58

https://github.com/Leeps-Lab/random_number_game/blob/79f09e192a5b6a7f31b829c044e2bbcbb1208417/templates/random_number_game/Decision.html#L73

Converting the number to image https://github.com/Leeps-Lab/random_number_game/blob/79f09e192a5b6a7f31b829c044e2bbcbb1208417/models.py#L318-L335

alkngo commented 3 years ago

Okay, I'll take a look at this.

mgutierrezc commented 3 years ago

Cool, thanks! Just to avoid conflicts, could you work in a branch different than the JavaScript one?

alkngo commented 3 years ago

Yes I can.

mgutierrezc commented 3 years ago

Hi @alkngo, would you tell me your progress on this issue?

Thanks

alkngo commented 3 years ago

Hello, I've been busy the past few days, but I have been looking at the code, and I can't find the source of the issue yet. To tell you the truth, I'm not too familiar with the image-writing mechanism yet. If the bug in this takes too much time to find, could I suggest an alternative to the image-writing? I see you have now incorporated oTree live pages which is a more canon version of otree-redwood. In the original otree-redwood game I made, instead of writing to an image file, I was just storing a string of the number and sending that back and forth between client and server: (related code below)

Receiving and Sending on the Frontend: https://github.com/Leeps-Lab/random_number_game/blob/25af0af3f90d93533c66fd381412e8e3d3c8291c/static/random_number_game/random-number/random-number.js#L97-L127

Stylizing the number text like this would effectively turn the text to an image: https://github.com/Leeps-Lab/random_number_game/blob/25af0af3f90d93533c66fd381412e8e3d3c8291c/static/random_number_game/random-number/random-number.js#L44-L49

Receiving and Sending on the Backend: https://github.com/Leeps-Lab/random_number_game/blob/25af0af3f90d93533c66fd381412e8e3d3c8291c/models.py#L166-L185

I think we could simply translate this otree-redwood code to otree live pages code (unless the bug in your current code can be found). Thoughts?

mgutierrezc commented 3 years ago

No worries. If you feel you can implement your suggestion, feel free to do so. It looks like a good alternative to the current image-writing mechanism

On Tue, Mar 16, 2021 at 12:27 AM alkngo @.***> wrote:

Hello, I've been busy the past few days, but I have been looking at the code, and I can't find the source of the issue yet. To tell you the truth, I'm not too familiar with the image-writing mechanism yet. If the bug in this takes too much time to find, could I suggest an alternative to the image-writing? I see you have now incorporated oTree live pages which is a more canon version of otree-redwood. In the original otree-redwood game I made, instead of writing to an image file, I was just storing a string of the number and sending that back and forth between client and server: (related code below)

Receiving and Sending on the Frontend:

https://github.com/Leeps-Lab/random_number_game/blob/25af0af3f90d93533c66fd381412e8e3d3c8291c/static/random_number_game/random-number/random-number.js#L97-L127

Stylizing the number text like this would effectively turn the text to an image:

https://github.com/Leeps-Lab/random_number_game/blob/25af0af3f90d93533c66fd381412e8e3d3c8291c/static/random_number_game/random-number/random-number.js#L44-L49

Receiving and Sending on the Backend:

https://github.com/Leeps-Lab/random_number_game/blob/25af0af3f90d93533c66fd381412e8e3d3c8291c/models.py#L166-L185

I think we could simply translate this otree-redwood code to otree live pages code (unless the bug in your current code can be found). Thoughts?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Leeps-Lab/random_number_game/issues/14#issuecomment-799961592, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKM2IYOL7H2GPP7Y6N3DKRLTD3T55ANCNFSM4YQLL7VA .

-- Marco Gutierrez Jefe de Práctica - Pontificia Universidad Católica del Perú

alkngo commented 3 years ago

Ok, i will work on that then.

alkngo commented 3 years ago

Actually, I think I might've found the error. Is it possible that in the frontend,

displayBase64Image(imagePlaceholder, base64Image);

Should be in liveRecv() instead of submit_transcription() ?

alkngo commented 3 years ago

15

mgutierrezc commented 3 years ago

I haven't thought of that. Have you tested that this change works?

On Tue, Mar 16, 2021 at 7:45 PM alkngo @.***> wrote:

15 https://github.com/Leeps-Lab/random_number_game/pull/15

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Leeps-Lab/random_number_game/issues/14#issuecomment-800709526, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKM2IYNEWUZRXRTERQWTXBLTD73RZANCNFSM4YQLL7VA .

-- Marco Gutierrez Jefe de Práctica - Pontificia Universidad Católica del Perú

alkngo commented 3 years ago

I've tested it, and the game still works. I think it does show the number from the right stage number now. Although, the first round still shows no number, which is by design right?

mgutierrezc commented 3 years ago

Cool. It should display the number on the first round though. Any ideas about that?

El El mar, mar. 16, 2021 a las 8:02 p. m., alkngo @.***> escribió:

I've tested it, and the game still works. I think it does show the number from the right stage number now. Although, the first round still shows no number, which is by design right?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Leeps-Lab/random_number_game/issues/14#issuecomment-800715615, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKM2IYKWYJKHBEFWZHZ3LYLTD75UDANCNFSM4YQLL7VA .

-- Marco Gutierrez Jefe de Práctica - Pontificia Universidad Católica del Perú

alkngo commented 3 years ago

I'll look into it some more.

alkngo commented 3 years ago

16

It looks like the step of loading the first image had to be done separately from the rest. I finished that, and I think everything should be good now.

mgutierrezc commented 3 years ago

16

It looks like the step of loading the first image had to be done separately from the rest. I finished that, and I think everything should be good now.

You are right. The images are being displayed correctly now. Thanks for your help!

alkngo commented 3 years ago

No problem, apologies for the long delay!

mgutierrezc commented 3 years ago

Hi @alkngo,

While debugging the code, I noticed that the issue is still there. The images are displayed correctly, but the numbers they present are from a previous round. image

For example, lets consider the following numbers for rounds 1-3 provided by the previous image:

round 1: 679341528 round 2: 612897354 round 3: 481925367

When the player is in round 2, the image is displaying the number 679341528 (from round 1) When the player is in round 3, the image is displaying the number 612897354 (from round 1)

This also happens with round 1, but the number displayed appears from nowhere (I guess this has to do with the order in which the js and python code for the task is executed)

Would you check what is causing this weird issue?

alkngo commented 3 years ago

17 I think this should fix it. I just reordered some stuff around.

mgutierrezc commented 3 years ago

17 I think this should fix it. I just reordered some stuff around.

It works! Thanks!

mgutierrezc commented 3 years ago

Hi @alkngo, looks like this still has some issues. When starting the first round, there are times in which the image displayed is not the image registered by the backend. For example, this happened in the stage 2 of a demo session :

DEBUG: task_number = 451693827                                                                                          
DEBUG: transcription = 136984527 

Would you give a look at it please?

mgutierrezc commented 3 years ago

Hi @alkngo, looks like this still has some issues. When starting the first round, there are times in which the image displayed is not the image registered by the backend. For example, this happened in the stage 2 of a demo session :

DEBUG: task_number = 451693827                                                                                          
DEBUG: transcription = 136984527 

Would you give a look at it please?

I've noticed this happens when there is a timeout on the previous stage

alkngo commented 3 years ago

Hey, sorry for the delay. I think #18 may fix it. I had misinterpreted when before_next_page() would be called, but I think moving the contents of that function to the creating_vars() function will make the first number assignment accurate.