Watts-Lab / surveys

Library of surveys for deliberation experiments
MIT License
3 stars 4 forks source link

Update or remove surveyWrapper #38

Closed JamesPHoughton closed 1 year ago

JamesPHoughton commented 2 years ago

Currently we have a code snippet for wrapping surveyjs surveys for empirica. However, we don't have the usePlayer hook, and so writing a callback to save the data doesn't work. For example, in our empirica experiment, we have:

export default function SurveyWrapper({ surveyJson, scoreFunc, next }) {
    const game = useGame()
    const player = usePlayer();
    const surveyModel = new Model(surveyJson);

    const saveResults = useCallback( sender => {
        const { data } = sender;
        const responses = data;  // is there a better way to do this?
        let result = scoreFunc ? scoreFunc(responses) : {}  // if no scoreFunc defined, default to empty dict
        const record = {
            responses: data, 
            result: result
        };
        player.set('Surveys', record);

        next();
    });

    surveyModel.onComplete.add(saveResults);

    return(
        <Survey style={surveyStyle} model={surveyModel} />
    )
}

What we really need is for whoever is using these surveys to have a reproducible way of using them. Maybe we don't need to include the actual surveyWrapper component here?