Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring up to latest empirica #266

Closed
4 of 5 tasks
JamesPHoughton opened this issue Aug 5, 2022 · 2 comments
Closed
4 of 5 tasks

Bring up to latest empirica #266

JamesPHoughton opened this issue Aug 5, 2022 · 2 comments
Assignees

Comments

@JamesPHoughton
Copy link
Collaborator

JamesPHoughton commented Aug 5, 2022

Things that are currently broken but we expect the latest empirica to fix

it('from intro steps', () => {
const playerKey = `test_${Math.floor(Math.random() * 1e13)}`;
const playerKeys = [playerKey];
// Consent and Login
cy.empiricaLoginPlayers({ playerKeys });
cy.wait(1000);
// Cancel Batch
cy.empiricaClearBatches();
cy.wait(1000);
// Check that player canceled
cy.visit(`/?playerKey=${playerKey}`);
cy.contains('About this study').should('not.exist');
cy.contains('No experiments available');
});

it('has no games available', () => {
const playerKey = `test_${Math.floor(Math.random() * 1e13)}`;
cy.visit(`http://localhost:3000/?playerKey=${playerKey}`);
cy.contains('No experiments available');
cy.wait(10000);
cy.contains('consent').should('not.exist');
cy.contains('I AGREE').should('not.exist');
});

Places where upgrading empirica will require some changes in our code

useEffect(() => {
// the following code works around https://github.com/empiricaly/empirica/issues/132
// TODO: remove when empirica is updated @npaton
if (!accessKey && (!isDevelopment || videoCallEnabledInDev)) {
const timer = setTimeout(() => {
console.log('Refreshing to load video');
window.location.reload();
}, 2000);
return () => clearTimeout(timer);
}
});

useEffect(() => {
// the following code works around https://github.com/empiricaly/empirica/issues/132
// TODO: remove when empirica is updated
// CC: @npaton
if (!accessKey && (!isDevelopment || videoCallEnabledInDev)) {
const timer = setTimeout(() => {
console.log('Refreshing to load video');
window.location.reload();
}, 3000);
return () => clearTimeout(timer);
}
});

const currentPlayers = players.length;

  • Routing around no-games
    Currently the no-games page gets displayed on every render, which leads to some unexpected side-effects as we want to stop the player's payment counter when they hit this screen. Currently this is worked around with a delay in the default useEffect(..., []). Documented in noGames is rendered even when games are available empiricaly/empirica#134

// TODO: shouldn't need this timeout in new version
// @npaton
const timer = setTimeout(() => {
console.log('Experiment stoppped in intro screens, stopping payment counter');
player.set('playerComplete', true);
}, 500);
return () => clearTimeout(timer);
}, []);

  • Player client-side adjustment of timer rendering
    We have a stage which plays a video, and when the video ends, it submits the stage. We want the stage timer to reflect the time remaining in the video. We expect the following code to break in the updated empirica:
    // TODO: shouldn't need this timeout in new version
    // @npaton
    const timer = setTimeout(() => {
    console.log('Experiment stoppped in intro screens, stopping payment counter');
    player.set('playerComplete', true);
    }, 500);
    return () => clearTimeout(timer);
    }, []);

Open questions:

We want to call a JS function stored in another repo (ie, https://github.com/Watts-Lab/surveys/blob/main/src/surveys/team_viability/teamViability.score.js) so that we can have surveys that can be shared between projects, documented here: Issue #215

Is this a reasonable pattern:

  1. Get the score function as a string in onNewBatch, save it to batch and then copy it to game object:

    const scoreFuncURL = url.replace('json', 'score.js');
    try {
    const response = await axios.get(scoreFuncURL);
    const scoreFuncString = response.data;
    const scoreFunc = scoreFuncString.slice(scoreFuncString.indexOf('{') + 1, scoreFuncString.lastIndexOf('}'));
    console.log(`Fetched score function from: ${scoreFuncURL}`);
    ExitScores[surveyFile] = scoreFunc;

  2. Then use Function to make it execute:

    const sf = scoreFunc ? new Function('responses', scoreFunc) : null;

@JamesPHoughton
Copy link
Collaborator Author

JamesPHoughton commented Sep 12, 2022

Updates in: #269

Currently outstanding:

@JamesPHoughton JamesPHoughton self-assigned this Sep 12, 2022
@JamesPHoughton
Copy link
Collaborator Author

Closed by #269
Dropping the lobby counter for now, as it will change once we have dynamic allocation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants