mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
Begining docs and marking updates for metadata fetching
This commit is contained in:
parent
631150e8fe
commit
8e9835f285
@ -0,0 +1,53 @@
|
||||
# Metadata Module
|
||||
|
||||
The metadata module contains functions for interacting metadata according to [Psych-DS standards](https://psych-ds.github.io/). To interact with the metadata, we strongly recommend you call the generate method on the experiment data then adjust fields accordingly. The generate method uses documentation for plugins and extensions created in the main JsPsych repo to create default descriptions. This works best for experiments run in v8+, but will also work for old experimental data.
|
||||
|
||||
---
|
||||
|
||||
## metadata.generate
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
### Examples
|
||||
|
||||
|
||||
|
||||
#### Calling metadata after running an experiment
|
||||
|
||||
```javascript
|
||||
var metadata = new jsPsychMetadata();
|
||||
|
||||
const metadata_options = {
|
||||
randomField: "this is a field",
|
||||
author: {
|
||||
"John": {
|
||||
name: "John",
|
||||
givenName: "Johnathan",
|
||||
},
|
||||
},
|
||||
variables: {
|
||||
"trial_type" : {
|
||||
description: {
|
||||
"chat-plugin": "this chat plugin allows you to talk to gpt!",
|
||||
}
|
||||
},
|
||||
"trial_index": {
|
||||
name: "index",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var jsPsych = initJsPsych({
|
||||
on_finish: async function() {
|
||||
await metadata.generate(jsPsych.data.get().json());
|
||||
},
|
||||
default_iti: 250
|
||||
});
|
||||
```
|
||||
|
||||
#### Calling metadata on data loaded locally
|
||||
|
||||
|
||||
|
@ -15,10 +15,10 @@ export class PluginCache {
|
||||
* @returns {Promise<string|null>} The description of the plugin variable if found, otherwise null.
|
||||
* @throws Will throw an error if the fetch operation fails.
|
||||
*/
|
||||
async getPluginInfo(pluginType: string, variableName: string, version?) {
|
||||
async getPluginInfo(pluginType: string, variableName: string, version, extension?) {
|
||||
// fetches if it doesn't exist
|
||||
if (!(pluginType in this.pluginFields)) {
|
||||
const fields = await this.generatePluginFields(pluginType, version);
|
||||
const fields = await this.generatePluginFields(pluginType, version, extension);
|
||||
this.pluginFields[pluginType] = fields;
|
||||
}
|
||||
|
||||
@ -31,8 +31,8 @@ export class PluginCache {
|
||||
};
|
||||
}
|
||||
|
||||
private async generatePluginFields(pluginType: string, version?) {
|
||||
const script = await this.fetchScript(pluginType, version);
|
||||
private async generatePluginFields(pluginType: string, version, extension?) {
|
||||
const script = await this.fetchScript(pluginType, version, extension);
|
||||
|
||||
// parses if they exist
|
||||
if (script !== undefined && script !== null && script !== "")
|
||||
@ -42,9 +42,15 @@ export class PluginCache {
|
||||
}
|
||||
}
|
||||
|
||||
private async fetchScript(pluginType: string, version?) {
|
||||
private async fetchScript(pluginType: string, version: string, extension?: boolean) {
|
||||
// implement logic here how to use version field
|
||||
// match upon name (extension version) and name ->
|
||||
// const unpkgUrl = `https://unpkg.com/@jspsych/plugin-${pluginType}/src/index.ts`;
|
||||
console.log(
|
||||
"fetchScript parameters: pluginType (" + pluginType + "), version (",
|
||||
version,
|
||||
"), extension(" + extension + ")"
|
||||
); // console logging each fetch
|
||||
const unpkgUrl = `http://localhost:3000/plugin/${pluginType}/index.ts`;
|
||||
|
||||
try {
|
||||
@ -57,7 +63,7 @@ export class PluginCache {
|
||||
pluginType,
|
||||
"with error",
|
||||
error,
|
||||
"Note: if you are using a plugin not in the main JsPsych branch this will always fail."
|
||||
"Note: if you are using a plugin not supported the main JsPsych branch this will always fail."
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
|
@ -300,8 +300,10 @@ export default class JsPsychMetadata {
|
||||
// variables can be thought of mapping of one column in a row
|
||||
const version = observation["version"] ? observation["version"] : null; // changed
|
||||
const pluginType = observation["trial_type"];
|
||||
|
||||
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"]);
|
||||
|
||||
for (const variable in observation) {
|
||||
@ -314,16 +316,16 @@ export default class JsPsychMetadata {
|
||||
await this.generateMetadata(variable, value, pluginType, version);
|
||||
extensionType
|
||||
? extensionType.forEach((ext, index) =>
|
||||
this.generateMetadata(variable, value, ext, extensionVersion[index])
|
||||
this.generateMetadata(variable, value, ext, extensionVersion[index], true)
|
||||
) // verify
|
||||
: console.log("No extensionType");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async generateMetadata(variable, value, pluginType, version?) {
|
||||
private async generateMetadata(variable, value, pluginType, version, extension?) {
|
||||
// probably should work in a call to the plugin here
|
||||
const pluginInfo = await this.getPluginInfo(pluginType, variable, version);
|
||||
const pluginInfo = await this.getPluginInfo(pluginType, variable, version, extension);
|
||||
const description = pluginInfo["description"];
|
||||
const new_description = description
|
||||
? { [pluginType]: description }
|
||||
@ -423,7 +425,7 @@ export default class JsPsychMetadata {
|
||||
* @returns {Promise<string|null>} The description of the plugin variable if found, otherwise null.
|
||||
* @throws Will throw an error if the fetch operation fails.
|
||||
*/
|
||||
private async getPluginInfo(pluginType: string, variableName: string, version?) {
|
||||
return this.pluginCache.getPluginInfo(pluginType, variableName, version);
|
||||
private async getPluginInfo(pluginType: string, variableName: string, version, extension?) {
|
||||
return this.pluginCache.getPluginInfo(pluginType, variableName, version, extension);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user