<commit_before>import controlP5.*;

/* =Interface
-------------------------------*/

ControlP5 cp5;

ControlGroup introG;
ControlGroup trialG;
ControlGroup doneG;

Textarea introText;
Textarea doneText;

Textlabel eqLabel;
Textlabel answerLabel;
Textlabel rightLabel;
Textlabel wrongLabel;

Textfield answerText;
Button submitButton;

color BG_COLOR = color(250, 250, 250);
color RIGHT_COLOR = color(31, 95, 31);
color WRONG_COLOR = color(255, 0, 0);
color IF_BG = color(236, 236, 236);
color IF_FG = color(220, 220, 220);
color IF_LABEL = color(0, 0, 0);
color IF_VALUE = color(0, 0, 0);
color IF_ACTIVE = color(232, 47, 47);

/* =Experiment
-------------------------------*/

// Application states
final int INTRO = 0;
final int PRACTICE = 1;
final int EXPERIMENT = 2;
final int DONE = 3;
int thisState = INTRO;

boolean nextTrial = false;
float trialEnd;
float TRIAL_PAUSE = 1000;

// Questions and answers
ArrayList questions, answers;
String question, answer;

// Response fields
int trialAttempts;
float trialStart, lastStart, trialTime;
float answerTime;
float cheatTime;

// Experiment data collection output
String dataFilePath;
PrintWriter out;

void setup() {
  // set up app window
  size(400, 400);
  frameRate(25);

  // create interface
  cp5 = new ControlP5(this);

  cp5.setColorForeground(IF_FG);
  cp5.setColorBackground(IF_BG);
  cp5.setColorLabel(IF_LABEL);
  cp5.setColorValue(IF_VALUE);
  cp5.setColorActive(IF_ACTIVE);

  introG = cp5.addGroup("intro", 0, 0, 400);
  introText = cp5.addTextarea("introText", "INTRO TEXT HERE", 0, 0, 400, 400);
  introText.setGroup("intro");

  trialG = cp5.addGroup("trial", 0, 0, 400);
  eqLabel = cp5.addTextlabel("equation", "++++++++++", 10, 50);
  answerLabel = cp5.addTextlabel("answerLabel", "++++++++++", 10, 140);
  rightLabel = cp5.addTextlabel("right", "Correct", 10, 20);
  wrongLabel = cp5.addTextlabel("wrong", "Incorrect - Please Try Again", 10, 20);
  answerText = cp5.addTextfield("answer", 10, 80, 35, 20);
  submitButton = cp5.addButton("submitButton", 10, 50, 80, 50, 20);
  submitButton.setCaptionLabel("Submit");

  answerText.keepFocus(true);
  eqLabel.setGroup("trial");
  answerLabel.setGroup("trial");
  rightLabel.setGroup("trial");
  wrongLabel.setGroup("trial");
  answerText.setGroup("trial");
  submitButton.setGroup("trial");
  eqLabel.setColorValue(IF_VALUE);
  answerLabel.setColorValue(IF_VALUE);
  rightLabel.setColorValue(RIGHT_COLOR);
  wrongLabel.setColorValue(WRONG_COLOR);

  doneG = cp5.addGroup("done", 0, 0, 400);
  doneText = cp5.addTextarea("doneText", "DONE TEXT HERE", 0, 0, 400, 400);
  doneText.setGroup("done");

  // start intro interface
  doIntro();
}

void draw() {
  background(BG_COLOR);

  // advance to next trial when necessary
  if (thisState == EXPERIMENT
      && nextTrial
      && (millis() - trialEnd > TRIAL_PAUSE)) {
    nextTrial = false;

    // prepare & display interface
    question = (String) questions.remove(0);
    answer = (String) answers.remove(0);
    showTrial();

    // init response fields
    trialAttempts = 0;
    trialStart = millis(); lastStart = trialStart;
    answerTime = 0; cheatTime = 0;
  }
}

// answer textfield event handler
// check submitted answer, inform subject, continue or repeat if right/wrong
void answer(String val) {
  if (thisState == EXPERIMENT) {
    trialAttempts++;

    if (answer.equals(val)) {
      // right: show subject, pause, then continue
      rightLabel.show();
      wrongLabel.hide();

      if (questions.size() > 0) {
        // advance to next trial as long as there are more
        nextTrial = true;

        // calculate completion times
        float doneTime = millis();
        trialTime = doneTime - trialStart;
        answerTime = doneTime - lastStart;

        // record this trial
        String record = String.format("%.0f,%d,%.0f,%.0f", trialTime, trialAttempts, answerTime, cheatTime);
        out.println(record);
        out.flush();
      } else {
        // conclude experiment when trials are exhausted
        doConclusion();
      }
    } else {<commit_msg>Fix trial advance delay (mistakenly used local var)<commit_after>import controlP5.*;

/* =Interface
-------------------------------*/

ControlP5 cp5;

ControlGroup introG;
ControlGroup trialG;
ControlGroup doneG;

Textarea introText;
Textarea doneText;

Textlabel eqLabel;
Textlabel answerLabel;
Textlabel rightLabel;
Textlabel wrongLabel;

Textfield answerText;
Button submitButton;

color BG_COLOR = color(250, 250, 250);
color RIGHT_COLOR = color(31, 95, 31);
color WRONG_COLOR = color(255, 0, 0);
color IF_BG = color(236, 236, 236);
color IF_FG = color(220, 220, 220);
color IF_LABEL = color(0, 0, 0);
color IF_VALUE = color(0, 0, 0);
color IF_ACTIVE = color(232, 47, 47);

/* =Experiment
-------------------------------*/

// Application states
final int INTRO = 0;
final int PRACTICE = 1;
final int EXPERIMENT = 2;
final int DONE = 3;
int thisState = INTRO;

boolean nextTrial = false;
float trialEnd;
float TRIAL_PAUSE = 1000;

// Questions and answers
ArrayList questions, answers;
String question, answer;

// Response fields
int trialAttempts;
float trialStart, lastStart, trialTime;
float answerTime;
float cheatTime;

// Experiment data collection output
String dataFilePath;
PrintWriter out;

void setup() {
  // set up app window
  size(400, 400);
  frameRate(25);

  // create interface
  cp5 = new ControlP5(this);

  cp5.setColorForeground(IF_FG);
  cp5.setColorBackground(IF_BG);
  cp5.setColorLabel(IF_LABEL);
  cp5.setColorValue(IF_VALUE);
  cp5.setColorActive(IF_ACTIVE);

  introG = cp5.addGroup("intro", 0, 0, 400);
  introText = cp5.addTextarea("introText", "INTRO TEXT HERE", 0, 0, 400, 400);
  introText.setGroup("intro");

  trialG = cp5.addGroup("trial", 0, 0, 400);
  eqLabel = cp5.addTextlabel("equation", "++++++++++", 10, 50);
  answerLabel = cp5.addTextlabel("answerLabel", "++++++++++", 10, 140);
  rightLabel = cp5.addTextlabel("right", "Correct", 10, 20);
  wrongLabel = cp5.addTextlabel("wrong", "Incorrect - Please Try Again", 10, 20);
  answerText = cp5.addTextfield("answer", 10, 80, 35, 20);
  submitButton = cp5.addButton("submitButton", 10, 50, 80, 50, 20);
  submitButton.setCaptionLabel("Submit");

  answerText.keepFocus(true);
  eqLabel.setGroup("trial");
  answerLabel.setGroup("trial");
  rightLabel.setGroup("trial");
  wrongLabel.setGroup("trial");
  answerText.setGroup("trial");
  submitButton.setGroup("trial");
  eqLabel.setColorValue(IF_VALUE);
  answerLabel.setColorValue(IF_VALUE);
  rightLabel.setColorValue(RIGHT_COLOR);
  wrongLabel.setColorValue(WRONG_COLOR);

  doneG = cp5.addGroup("done", 0, 0, 400);
  doneText = cp5.addTextarea("doneText", "DONE TEXT HERE", 0, 0, 400, 400);
  doneText.setGroup("done");

  // start intro interface
  doIntro();
}

void draw() {
  background(BG_COLOR);

  // advance to next trial when necessary
  if (thisState == EXPERIMENT
      && nextTrial
      && (millis() - trialEnd > TRIAL_PAUSE)) {
    nextTrial = false;

    // prepare & display interface
    question = (String) questions.remove(0);
    answer = (String) answers.remove(0);
    showTrial();

    // init response fields
    trialAttempts = 0;
    trialStart = millis(); lastStart = trialStart;
    answerTime = 0; cheatTime = 0;
  }
}

// answer textfield event handler
// check submitted answer, inform subject, continue or repeat if right/wrong
void answer(String val) {
  if (thisState == EXPERIMENT) {
    trialAttempts++;

    if (answer.equals(val)) {
      // right: show subject, pause, then continue
      rightLabel.show();
      wrongLabel.hide();

      if (questions.size() > 0) {
        // advance to next trial as long as there are more
        nextTrial = true;

        // calculate completion times
        trialEnd = millis();
        trialTime = trialEnd - trialStart;
        answerTime = trialEnd - lastStart;

        // record this trial
        String record = String.format("%.0f,%d,%.0f,%.0f", trialTime, trialAttempts, answerTime, cheatTime);
        out.println(record);
        out.flush();
      } else {
        // conclude experiment when trials are exhausted
        doConclusion();
      }
    } else {
{'fraction_non_alphanumeric': 0.1478218306412139, 'fraction_numerical': 0.0398923152227117, 'mean_word_length': 3.5633724176437744, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2397070', 'n_tokens_mistral': 2928, 'n_tokens_neox': 2579, 'n_words': 706}