empiricaly / empirica

Open source project to tackle the problem of long development cycles required to produce software to conduct multi-participant and real-time human experiments online.
https://empirica.ly/
Apache License 2.0
44 stars 8 forks source link

Empirica.onRoundEnded cuts off the round so early that messes with data recording #575

Open HuangHam opened 1 month ago

HuangHam commented 1 month ago

Is there an existing issue for this?

What happened?

This is my stages for a round: round.addStage({name: "fixation", duration:1}); round.addStage({name: "maintenance", duration:10}); round.addStage({name: "retention", duration:1}); round.addStage({name: "recall", duration:10000}); //limit of few hours to respond (basically unlimited time) round.addStage({name: "feedback", duration:1});

and I want to manually record the duration of each stage using these lines of code in each stage file:
 function recordData(){
    const endTime = new Date();
    if (is_practice) {
      player.set(`startTimeFeedbackPractice_${currentRound}`, startTime);
      player.set(`endTimeFeedbackPractice_${currentRound}`, endTime);
    } else {
      player.set(`startTimeFeedback`, startTime);
      player.set(`endTimeFeedback`, endTime);
    }
    console.log(startTime, endTime)
    console.log(player.get(`startTimeFeedback`), player.get(`endTimeFeedback`))
  };

  useEffect(() => {
    return () => {
      recordData();
    };
  }, []); 

So here I console.log the start and end time of the feedback stage (which is the last stage in the round) and they all look normal: the end time is roughly 1 second later than the start time as specified in my callback.js file. However, if I want to log the same quantity in the callback.js file at the end of the round:

Empirica.onRoundEnded(({ round }) => {
  const players = round.currentGame.players;
  for (const player of players) {

    console.log(
     player.get("startTimeFeedback"), player.get("endTimeFeedback"));
  }
});

endTimeFeedback now becomes equal to startTimeFeedback even though they are supposed to be 1 second apart. This bug occurs because Feedback is the last stage in the round. If I manually add another stage after it the bug goes away.

Steps To Reproduce

Just try to record the start time and end time of a stage and log it in the endround function in the callback.js file.

Empirica Version

v 1.11.4

What OS are you seeing the problem on?

macOS

What browser are you seeing the problem on?

Chrome

Relevant log output

No response

Anything else?

No response

Code of Conduct