Let's Dive into It


When I decided to use the Iowa Gambling Task for my master's thesis, I faced a challenge. There weren't many online versions of the task available. So, I took it upon myself to learn Python and JavaScript to adapt the task for online use.

gambling pic.jpg

How I did it


My goal was to make the Iowa Gambling Task work online. This meant shifting from using a Python-based desktop app to a more flexible online format. It wasn't just about coding skills; I had to understand how to turn psychological tasks into something digital.

Below are some code snippets I used to make the transition from desktop to online:

Python

allCards = data.importConditions("CONDITIONS.csv")
A_cards = list(filter(lambda x: x["DECK_NAME"] == "A", allCards))
B_cards = list(filter(lambda x: x["DECK_NAME"] == "B", allCards))
C_cards = list(filter(lambda x: x["DECK_NAME"] == "C", allCards))
D_cards = list(filter(lambda x: x["DECK_NAME"] == "D", allCards))

shuffle(A_cards)
shuffle(B_cards)
shuffle(C_cards)
shuffle(D_cards)

totalReps = 100

ALL_FEEDBACK_TEXTS = [deck11, deck22, deck33, deck44]

# This will be looped through to check if the decks
# are empty: [<nameOfCardDeck>, <list of image stims associated with deck>]
DECKS_AND_IMAGES = [[A_cards, [A, DECK_11]],
                    [B_cards, [B, DECK_21]],
                    [C_cards, [C, DECK_31]],
                    [D_cards, [D, DECK_41]],
                    ]

for deckIms in DECKS_AND_IMAGES:
    deck = deckIms[0]
    ims = deckIms[1]
    # check if deck is empty, if so, change image
    if not deck:
        for im in ims:
           im.image = deckEmptyImg

JavaScript

// add-on: list(s: string): string[]
function list(s) {
  // if s is a string, we return a list of its characters
  if (typeof s === "string") return s.split("");
  // otherwise we return s:
  else return s;
}

A_cards = new TrialHandler({
  psychoJS: psychoJS,
  nReps: 1,
  method: TrialHandler.Method.RANDOM,
  extraInfo: expInfo,
  originPath: undefined,
  trialList: "CONDITIONS.csv",
  seed: undefined,
  name: "allCards",
});

B_cards = new TrialHandler({
  psychoJS: psychoJS,
  nReps: 1,
  method: TrialHandler.Method.RANDOM,
  extraInfo: expInfo,
  originPath: undefined,
  trialList: "CONDITIONS.csv",
  seed: undefined,
  name: "allCards",
});

C_cards = new TrialHandler({
  psychoJS: psychoJS,
  nReps: 1,
  method: TrialHandler.Method.RANDOM,
  extraInfo: expInfo,
  originPath: undefined,
  trialList: "CONDITIONS.csv",
  seed: undefined,
  name: "allCards",
});

D_cards = new TrialHandler({
  psychoJS: psychoJS,
  nReps: 1,
  method: TrialHandler.Method.RANDOM,
  extraInfo: expInfo,
  originPath: undefined,
  trialList: "CONDITIONS.csv",
  seed: undefined,
  name: "allCards",
});

E_cards = new TrialHandler({
  psychoJS: psychoJS,
  nReps: 1,
  method: TrialHandler.Method.RANDOM,
  extraInfo: expInfo,
  originPath: undefined,
  trialList: "CONDITIONS.csv",
  seed: undefined,
  name: "allCards",
});

A_cards.trialList = A_cards.trialList
  .slice(0, A_cards.trialList.length)
  .filter((x) => x["DECK_NAME"] === "A");
B_cards.trialList = B_cards.trialList
  .slice(0, B_cards.trialList.length)
  .filter((x) => x["DECK_NAME"] === "B");
C_cards.trialList = C_cards.trialList
  .slice(0, C_cards.trialList.length)
  .filter((x) => x["DECK_NAME"] === "C");
D_cards.trialList = D_cards.trialList
  .slice(0, D_cards.trialList.length)
  .filter((x) => x["DECK_NAME"] === "D");

totalReps = 100;
ALL_FEEDBACK_TEXTS = [deck11, deck22, deck33, deck44];
DECKS_AND_IMAGES = [
    [A_cards, [A, DECK_11]],
    [B_cards, [B, DECK_21]],
    [C_cards, [C, DECK_31]],
    [D_cards, [D, DECK_41]]
];
for (var deckIms, _pj_c = 0, _pj_a = DECKS_AND_IMAGES, _pj_b = _pj_a.length;
    (_pj_c < _pj_b); _pj_c += 1) {
    deckIms = _pj_a[_pj_c];
    var deck = deckIms[0];
    var ims = deckIms[1];
    if ((!deck)) {
        for (var im, _pj_f = 0, _pj_d = ims, _pj_e = _pj_d.length;
            (_pj_f < _pj_e); _pj_f += 1) {
            var im = _pj_d[_pj_f];
            im.image = deckEmptyImg;
        }
    }
}
psychoJS.eventManager.clearEvents();

What I found out


Learning Python and JavaScript wasn't just about making the Iowa Gambling Task work online. It also helped me become better at analyzing complex data. This journey taught me how important technical skills are in modern psychological research.

card decks.png