{% extends "psynet_dashboard.html" %} {% block scripts %} {{ super() }} {% endblock %} {% block stylesheets %} {{ super() }} {% endblock %} {% block body %}

{{ title }}

To use the /basic_data endpoint in your experiment, you need to implement the get_basic_data method in your experiment class. The method should return a list of dictionaries with the data you want to expose. You can make this method as complex as you need. For example, you can add GET parameters to the endpoint, e.g. /basic_data?sheet=participant which allows to switch between different data sheets.

class Exp(psynet.experiment.Experiment):
    …

    @classmethod
    def get_basic_data(cls, context=None, **kwargs, ):
        data = {
            "trial":
                [
                # List all trials with their answers
                    {
                        "id": trial.id,
                        "answer": str(trial.answer),
                    }
                    for trial in Trial.query.filter_by(failed=False, finalized=True).all()
                ],
            "participant": [
                # List all participants with their last answer
                {
                    "id": participant.id,
                    "answer": str(participant.answer),
                }
                for participant in Participant.query.filter_by().all()
            ],
        }
        sheet = kwargs.get("sheet", "participant")
        if sheet not in data:
            raise DataError("Invalid sheet parameter")
        return data[sheet]

Here are some examples of how to load the data in R and Python.

R example

library(jsonlite)
url <- "{{ url }}"
df <- fromJSON(url)
                        
Python example

import pandas as pd
url = "{{ url }}"
df = pd.read_json(url)
                                                

Showing data from /data endpoint.

{{ data | safe }}
{% endblock %} {% block libs %} {{ super() }} {% endblock %}