mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00
Pushed inital version of documentation for metadata
This commit is contained in:
commit
d55674f70d
@ -1,5 +1,7 @@
|
||||
export interface JsPsychExtensionInfo {
|
||||
name: string;
|
||||
version: string;
|
||||
data: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface JsPsychExtension {
|
||||
|
@ -38,6 +38,11 @@ export class VariablesMap {
|
||||
*/
|
||||
private variables: { [key: string]: VariableFields };
|
||||
|
||||
/**
|
||||
* Flag that determines if the extension variables' default descriptions have been generated in the metadata.
|
||||
**/
|
||||
extensionDefaultFlag: boolean = false;
|
||||
|
||||
/**
|
||||
* Creates the VariablesMap bycalling generateDefaultVariables() method to
|
||||
* generate the basic metadata common to every dataset_description.json file.
|
||||
@ -48,6 +53,37 @@ export class VariablesMap {
|
||||
this.generateDefaultVariables();
|
||||
}
|
||||
|
||||
generateDefaultExtensionVariables(): void {
|
||||
if (this.extensionDefaultFlag) {
|
||||
return;
|
||||
}
|
||||
|
||||
const extension_type_var: VariableFields = {
|
||||
"@type": "PropertyValue",
|
||||
name: "extension_type",
|
||||
description: {
|
||||
default: "unknown",
|
||||
jsPsych: "The name(s) of the extension(s) used in the trial.",
|
||||
},
|
||||
value: "string",
|
||||
};
|
||||
this.setVariable(extension_type_var);
|
||||
|
||||
const extension_version_var: VariableFields = {
|
||||
"@type": "PropertyValue",
|
||||
name: "extension_version",
|
||||
description: {
|
||||
default: "unknown",
|
||||
jsPsych: "The version(s) of the extension(s) used in the trial.",
|
||||
},
|
||||
value: "numeric",
|
||||
};
|
||||
|
||||
this.setVariable(extension_version_var);
|
||||
|
||||
this.extensionDefaultFlag = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the default variables shared between every JsPsych experiment and fills in
|
||||
* with default descriptions according to JsPsych documentation.
|
||||
@ -111,7 +147,12 @@ export class VariablesMap {
|
||||
variable["description"] = description[key];
|
||||
} else if (numKeys == 2) {
|
||||
delete description["default"]; // deletes default
|
||||
|
||||
// Delete the property if its value is "unknown"
|
||||
for (const descKey in description as object) {
|
||||
if (description[descKey] === "unknown") {
|
||||
delete description[descKey];
|
||||
}
|
||||
}
|
||||
if (Object.keys(description).length == 1) {
|
||||
// error checking that it reduced to one key
|
||||
const key = Object.keys(description)[0];
|
||||
@ -120,6 +161,12 @@ export class VariablesMap {
|
||||
} else if (numKeys > 2) {
|
||||
// deletes default
|
||||
delete description["default"];
|
||||
// Delete the property if its value is "unknown"
|
||||
for (const descKey in description as object) {
|
||||
if (description[descKey] === "unknown") {
|
||||
delete description[descKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var_list.push(variable);
|
||||
|
@ -89,6 +89,14 @@ export default class JsPsychMetadata {
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the default descriptions for extension_type and extension_version in metadata. Should be called after
|
||||
* default metadata is generated, and only should be called once.
|
||||
**/
|
||||
generateDefaultExtensionVariables(): void {
|
||||
this.variables.generateDefaultExtensionVariables();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that creates an author. This method can also be used to overwrite existing authors
|
||||
* with the same name in order to update fields.
|
||||
@ -294,7 +302,15 @@ export default class JsPsychMetadata {
|
||||
const extensionType = observation["extension_type"]; // fix for non-list (single item extension)
|
||||
const extensionVersion = observation["extension_version"];
|
||||
|
||||
const ignored_fields = new Set(["trial_type", "trial_index", "time_elapsed"]);
|
||||
if (extensionType) this.generateDefaultExtensionVariables(); // After first call, generation is stopped.
|
||||
|
||||
const ignored_fields = new Set([
|
||||
"trial_type",
|
||||
"trial_index",
|
||||
"time_elapsed",
|
||||
"extenstion_type",
|
||||
"extension_version",
|
||||
]);
|
||||
|
||||
for (const variable in observation) {
|
||||
const value = observation[variable];
|
||||
@ -304,11 +320,13 @@ export default class JsPsychMetadata {
|
||||
if (ignored_fields.has(variable)) this.updateFields(variable, value, typeof value);
|
||||
else {
|
||||
await this.generateMetadata(variable, value, pluginType, version);
|
||||
extensionType
|
||||
? extensionType.forEach((ext, index) =>
|
||||
this.generateMetadata(variable, value, ext, extensionVersion[index], true)
|
||||
) // verify
|
||||
: console.log("No extensionType");
|
||||
if (extensionType) {
|
||||
await Promise.all(
|
||||
extensionType.map((ext, index) =>
|
||||
this.generateMetadata(variable, value, ext, extensionVersion[index])
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user