mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-10 18:50:54 +00:00
added user-specified filenames, opening and closing of sessions uses gitlab Id in order to benefit from the speed-up provided by the database indexes
This commit is contained in:
parent
aeca039240
commit
16f84872c6
@ -312,7 +312,7 @@ export class PsychoJS
|
|||||||
* @async
|
* @async
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
async start({ configURL = "config.json", expName = "UNKNOWN", expInfo = {}, resources = [] } = {})
|
async start({ configURL = "config.json", expName = "UNKNOWN", expInfo = {}, resources = [], dataFileName } = {})
|
||||||
{
|
{
|
||||||
this.logger.debug();
|
this.logger.debug();
|
||||||
|
|
||||||
@ -344,6 +344,7 @@ export class PsychoJS
|
|||||||
this._experiment = new ExperimentHandler({
|
this._experiment = new ExperimentHandler({
|
||||||
psychoJS: this,
|
psychoJS: this,
|
||||||
extraInfo: expInfo,
|
extraInfo: expInfo,
|
||||||
|
dataFileName
|
||||||
});
|
});
|
||||||
|
|
||||||
// setup the logger:
|
// setup the logger:
|
||||||
|
@ -138,7 +138,9 @@ export class ServerManager extends PsychObject
|
|||||||
const self = this;
|
const self = this;
|
||||||
return new Promise((resolve, reject) =>
|
return new Promise((resolve, reject) =>
|
||||||
{
|
{
|
||||||
const url = this._psychoJS.config.pavlovia.URL + "/api/v2/experiments/" + encodeURIComponent(self._psychoJS.config.experiment.fullpath) + "/sessions";
|
const url = this._psychoJS.config.pavlovia.URL
|
||||||
|
+ "/api/v2/experiments/" + this._psychoJS.config.gitlab.projectId
|
||||||
|
+ "/sessions/";
|
||||||
jQuery.post(url, data, null, "json")
|
jQuery.post(url, data, null, "json")
|
||||||
.done((data, textStatus) =>
|
.done((data, textStatus) =>
|
||||||
{
|
{
|
||||||
@ -219,8 +221,9 @@ export class ServerManager extends PsychObject
|
|||||||
this.setStatus(ServerManager.Status.BUSY);
|
this.setStatus(ServerManager.Status.BUSY);
|
||||||
|
|
||||||
// prepare DELETE query:
|
// prepare DELETE query:
|
||||||
const url = this._psychoJS.config.pavlovia.URL + "/api/v2/experiments/" + encodeURIComponent(this._psychoJS.config.experiment.fullpath) + "/sessions/"
|
const url = this._psychoJS.config.pavlovia.URL
|
||||||
+ this._psychoJS.config.session.token;
|
+ "/api/v2/experiments/" + this._psychoJS.config.gitlab.projectId
|
||||||
|
+ "/sessions/" + this._psychoJS.config.session.token;
|
||||||
|
|
||||||
// synchronous query the pavlovia server:
|
// synchronous query the pavlovia server:
|
||||||
if (sync)
|
if (sync)
|
||||||
@ -231,7 +234,7 @@ export class ServerManager extends PsychObject
|
|||||||
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||||
request.send(JSON.stringify(data));
|
request.send(JSON.stringify(data));
|
||||||
*/
|
*/
|
||||||
/* This does not work in Chrome before of a CORS bug
|
/* This does not work in Chrome because of a CORS bug
|
||||||
await fetch(url, {
|
await fetch(url, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: { 'Content-Type': 'application/json;charset=UTF-8' },
|
headers: { 'Content-Type': 'application/json;charset=UTF-8' },
|
||||||
|
@ -68,12 +68,33 @@ export class ExperimentHandler extends PsychObject
|
|||||||
psychoJS,
|
psychoJS,
|
||||||
name,
|
name,
|
||||||
extraInfo,
|
extraInfo,
|
||||||
|
dataFileName
|
||||||
} = {})
|
} = {})
|
||||||
{
|
{
|
||||||
super(psychoJS, name);
|
super(psychoJS, name);
|
||||||
|
|
||||||
this._addAttribute("extraInfo", extraInfo);
|
this._addAttribute("extraInfo", extraInfo);
|
||||||
|
|
||||||
|
// process the extra info:
|
||||||
|
this._experimentName = (typeof extraInfo.expName === "string" && extraInfo.expName.length > 0)
|
||||||
|
? extraInfo.expName
|
||||||
|
: this.psychoJS.config.experiment.name;
|
||||||
|
this._participant = (typeof extraInfo.participant === "string" && extraInfo.participant.length > 0)
|
||||||
|
? extraInfo.participant
|
||||||
|
: "PARTICIPANT";
|
||||||
|
this._session = (typeof extraInfo.session === "string" && extraInfo.session.length > 0)
|
||||||
|
? extraInfo.session
|
||||||
|
: "SESSION";
|
||||||
|
this._datetime = (typeof extraInfo.date !== "undefined")
|
||||||
|
? extraInfo.date
|
||||||
|
: MonotonicClock.getDateStr();
|
||||||
|
|
||||||
|
this._addAttribute(
|
||||||
|
"dataFileName",
|
||||||
|
dataFileName,
|
||||||
|
`${this._participant}_${this._experimentName}_${this._datetime}`
|
||||||
|
);
|
||||||
|
|
||||||
// loop handlers:
|
// loop handlers:
|
||||||
this._loops = [];
|
this._loops = [];
|
||||||
this._unfinishedLoops = [];
|
this._unfinishedLoops = [];
|
||||||
@ -278,15 +299,6 @@ export class ExperimentHandler extends PsychObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get various experiment info:
|
|
||||||
const info = this.extraInfo;
|
|
||||||
const __experimentName = (typeof info.expName !== "undefined") ? info.expName : this.psychoJS.config.experiment.name;
|
|
||||||
const __participant = ((typeof info.participant === "string" && info.participant.length > 0) ? info.participant : "PARTICIPANT");
|
|
||||||
const __session = ((typeof info.session === "string" && info.session.length > 0) ? info.session : "SESSION");
|
|
||||||
const __datetime = ((typeof info.date !== "undefined") ? info.date : MonotonicClock.getDateStr());
|
|
||||||
const gitlabConfig = this._psychoJS.config.gitlab;
|
|
||||||
const __projectId = (typeof gitlabConfig !== "undefined" && typeof gitlabConfig.projectId !== "undefined") ? gitlabConfig.projectId : undefined;
|
|
||||||
|
|
||||||
let data = this._trialsData;
|
let data = this._trialsData;
|
||||||
// if the experiment data have to be cleared, we first make a copy of them:
|
// if the experiment data have to be cleared, we first make a copy of them:
|
||||||
if (clear)
|
if (clear)
|
||||||
@ -306,7 +318,8 @@ export class ExperimentHandler extends PsychObject
|
|||||||
const csv = "\ufeff" + XLSX.utils.sheet_to_csv(worksheet);
|
const csv = "\ufeff" + XLSX.utils.sheet_to_csv(worksheet);
|
||||||
|
|
||||||
// upload data to the pavlovia server or offer them for download:
|
// upload data to the pavlovia server or offer them for download:
|
||||||
const key = `${__participant}_${__experimentName}_${__datetime}${tag}.csv`;
|
const filenameWithoutPath = this._dataFileName.split(/[\\/]/).pop();
|
||||||
|
const key = `${filenameWithoutPath}${tag}.csv`;
|
||||||
if (
|
if (
|
||||||
this._psychoJS.getEnvironment() === ExperimentHandler.Environment.SERVER
|
this._psychoJS.getEnvironment() === ExperimentHandler.Environment.SERVER
|
||||||
&& this._psychoJS.config.experiment.status === "RUNNING"
|
&& this._psychoJS.config.experiment.status === "RUNNING"
|
||||||
@ -323,11 +336,20 @@ export class ExperimentHandler extends PsychObject
|
|||||||
// save to the database on the pavlovia server:
|
// save to the database on the pavlovia server:
|
||||||
else if (this._psychoJS.config.experiment.saveFormat === ExperimentHandler.SaveFormat.DATABASE)
|
else if (this._psychoJS.config.experiment.saveFormat === ExperimentHandler.SaveFormat.DATABASE)
|
||||||
{
|
{
|
||||||
|
const gitlabConfig = this._psychoJS.config.gitlab;
|
||||||
|
const projectId = (typeof gitlabConfig !== "undefined" && typeof gitlabConfig.projectId !== "undefined") ? gitlabConfig.projectId : undefined;
|
||||||
|
|
||||||
let documents = [];
|
let documents = [];
|
||||||
|
|
||||||
for (let r = 0; r < data.length; r++)
|
for (let r = 0; r < data.length; r++)
|
||||||
{
|
{
|
||||||
let doc = { __projectId, __experimentName, __participant, __session, __datetime };
|
let doc = {
|
||||||
|
projectId,
|
||||||
|
__experimentName: this._experimentName,
|
||||||
|
__participant: this._participant,
|
||||||
|
__session: this._session,
|
||||||
|
__datetime: this._datetime
|
||||||
|
};
|
||||||
for (let h = 0; h < attributes.length; h++)
|
for (let h = 0; h < attributes.length; h++)
|
||||||
{
|
{
|
||||||
doc[attributes[h]] = data[r][attributes[h]];
|
doc[attributes[h]] = data[r][attributes[h]];
|
||||||
|
Loading…
Reference in New Issue
Block a user