Skip to content

Commit

Permalink
implemented temporary fix for displaying metadata, need to conform to…
Browse files Browse the repository at this point in the history
… v8 standards, ready to begin writing method to write metadata
  • Loading branch information
vzhang03 committed Jun 7, 2024
1 parent 9697a97 commit 1fb9919
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
10 changes: 9 additions & 1 deletion examples/timeline-variables.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@
<script src="../packages/plugin-html-keyboard-response/dist/index.browser.js"></script>
<script src="../packages/plugin-image-keyboard-response/dist/index.browser.js"></script>
<script src="../packages/plugin-preload/dist/index.browser.js"></script>
<script src="../packages/metadata/dist/index.browser.js"></script>
<link rel="stylesheet" href="../packages/jspsych/css/jspsych.css">
</head>
<body></body>
<script>

var jsPsych = initJsPsych({
on_finish: function() {
jsPsych.data.displayData();
metadata.generate(jsPsych.data.get().json());

// metadata.saveAsJsonFile();
jsPsych.data.displayData();
metadata.displayMetadata(jsPsych.getDisplayElement());
},
default_iti: 250
});

var metadata = new jsPsychMetadata(); // could declare with jsPsych to show the after


// manually preload the image files, since they are passed to the image-keyboard-response stimulus parameter
// through timeline variables, and therefore cannot be automatically preloaded
var images = ['img/happy_face_1.jpg', 'img/happy_face_2.jpg', 'img/happy_face_3.jpg'];
Expand Down
4 changes: 2 additions & 2 deletions packages/metadata/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { makeNodeRollupConfig } from "@jspsych/config/rollup";
import { makeRollupConfig } from "@jspsych/config/rollup";

export default makeNodeRollupConfig();
export default makeRollupConfig("jsPsychMetadata");
24 changes: 19 additions & 5 deletions packages/metadata/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { VariablesMap } from "./VariablesMap";
* @class JsPsychMetadata
* @typedef {JsPsychMetadata}
*/
export class JsPsychMetadata {
export default class JsPsychMetadata {
/**
* Field that contains all metadata fields that aren't represented as a list.
*
Expand Down Expand Up @@ -213,15 +213,16 @@ export class JsPsychMetadata {
*
* @param {string} [elementId="jspsych-metadata-display"] - Id for how to style the metadata. Defaults to default styling.
*/
displayMetadata(elementId = "jspsych-metadata-display") {
displayMetadata(display_element) {
const elementId = "jspsych-metadata-display";
const metadata_string = JSON.stringify(this.getMetadata(), null, 2);
const display_element = this.JsPsych.getDisplayElement();
// const display_element = this.JsPsych.getDisplayElement();
display_element.innerHTML += `<p id="jspsych-metadata-header">Metadata</p><pre id="${elementId}" class="jspsych-preformat"></pre>`;
document.getElementById(elementId).textContent = metadata_string;
document.getElementById(elementId).textContent += metadata_string;
}

/**
* Method that begins a download for the dataset_dea.cription.json at the end of experiment.
* Method that begins a download for the dataset_description.json at the end of experiment.
* Allows you to download the metadat.
*/
saveAsJsonFile(): void {
Expand All @@ -238,4 +239,17 @@ export class JsPsychMetadata {

URL.revokeObjectURL(url);
}

generate(data) {
if (typeof data === "string") {
data = JSON.parse(data);
}

for (const data_point of data) {
// console.log("NEW ELEMENT \n")
console.log(data_point);
}

return this.getMetadata();
}
}

0 comments on commit 1fb9919

Please sign in to comment.