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

NF: Adding field seperator selection in output #566

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
15 changes: 13 additions & 2 deletions src/data/ExperimentHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ export class ExperimentHandler extends PsychObject
* @param {module:core.PsychoJS} options.psychoJS - the PsychoJS instance
* @param {string} options.name - name of the experiment
* @param {Object} options.extraInfo - additional information, such as session name, participant name, etc.
* @param {string} field_separator - Delimiter character specification
*/
constructor({
psychoJS,
name,
extraInfo,
dataFileName
dataFileName,
field_separator
} = {})
{
super(psychoJS, name);
Expand All @@ -88,6 +90,13 @@ export class ExperimentHandler extends PsychObject
`${this._participant}_${this._experimentName}_${this._datetime}`
);

this._addAttribute("field_separator",
(typeof field_separator === "string" || field_separator.length === 1 || field_separator !== '\n')
? field_separator
: ',',
','
);

// loop handlers:
this._loops = [];
this._unfinishedLoops = [];
Expand All @@ -98,6 +107,8 @@ export class ExperimentHandler extends PsychObject
this._currentTrialData = {};

this._experimentEnded = false;


}

/**
Expand Down Expand Up @@ -291,7 +302,7 @@ export class ExperimentHandler extends PsychObject
// TODO only save the given attributes
const worksheet = XLSX.utils.json_to_sheet(data);
// prepend BOM
const csv = "\ufeff" + XLSX.utils.sheet_to_csv(worksheet);
const csv = "\ufeff" + XLSX.utils.sheet_to_csv(worksheet, {FS: this.field_separator});

// upload data to the pavlovia server or offer them for download:
const filenameWithoutPath = this._dataFileName.split(/[\\/]/).pop();
Expand Down