Commit bbd05a9c authored by William Paul Liggett's avatar William Paul Liggett

Log Data to CSV: Modified some aspects to handle the user's activity data....

Log Data to CSV: Modified some aspects to handle the user's activity data. It's not fully operational yet though.
parent dff35fb4
......@@ -53,10 +53,10 @@ function getCurrentDatetime() {
// Determines when to record the user's activity, such as when they press the space bar during a test.
var ov_record_user_activity = false;
// Documents how well the user is doing during a test. The data is eventually submitted to the server.
// Multidimensional Array: Documents how well the user is doing during a test. The data is eventually submitted to the server.
// Note: We don't need the following cells as we can create the information on the server: "SID", "Target", "Distractor", "FalseAlarm", and "Correct"
// The heading of each cell is listed below:
var ov_user_activity_array = ["TimeStamp", "Type", "Block", "GlobalTrialCounter", "CurrentTrial", "ov_random_letter_is_o", "RT"];
// The heading of each cell is listed below, but the heading will not be repeated for new rows.
var ov_user_activity_array = [["GlobalTrialCounter", "CurrentTrial", "TimeStamp", "Type", "Block", "ov_random_letter_is_o", "RT"]];
// Records the datetime in ms since the Unix epoch. It'll be set once the test actually begins.
var ov_test_began_datetime = -1;
......@@ -69,6 +69,12 @@ var ov_test_type = "";
// Block 0 = Practice. Block 1 = 1st 2-min period. Block 2 = 2nd 2-min period. Block 3 = 3rd 2-min period. And so on.
var ov_test_block = -1;
// A test block is a subset of a 12-min test. For now, each block is divided into 2-min periods.
const OV_TEST_BLOCK_EACH_DURATION = parseFloat(120000); // 2 minutes = 120,000 ms
// Used to increment the `ov_test_block' var every 2-minutes when needed by identifying the setInterval() ID.
var ov_test_block_timer_id = -1;
// Primarily used to outputting the time of the current random letter to the CSV.
//var ov_current_random_letter_time_as_string = "";
......@@ -89,6 +95,7 @@ var ov_current_trial_counter = 0;
// Response Time (RT): Measure the time in ms of how long it took them to press the space bar after a random letter was displayed.
// Note: It doesn't matter if the random letter was the correct letter 'O' as the RT is logged whenever the user presses the
// space bar or is set to -1 to indicate that the user did not respond to a random letter.
var ov_participant_response_time_previously = -1;
var ov_participant_response_time = -1;
;(function(window, $) {
......@@ -126,6 +133,11 @@ var ov_participant_response_time = -1;
// Increments by one each time a new random letter is shown to the user. Eventually output in the CSV.
++ov_global_trial_counter;
// Current Trial Counter: ONLY the Actual Test (experiment), as the Practice Test will just log zeroes.
if(ov_test_type === "E") {
++ov_current_trial_counter;
}
// Letter: O
if(random_int === 0) {
chosen_letter = "letter_o";
......@@ -188,24 +200,35 @@ var ov_participant_response_time = -1;
// Hides the letter once the duration length is reached.
$("span." + chosen_letter).addClass("hidden");
}, DISPLAY_LETTER_DURATION);
// Logs the activity to the JS array as a new row for each letter shown to the user.
// Note: The `ov_subject_id' var was defined already by the PHP script.
// The title headings are: "GlobalTrialCounter", "CurrentTrial", "TimeStamp", "Type", "Block", "ov_random_letter_is_o", "RT"
ov_user_activity_array.push([ov_global_trial_counter, ov_current_trial_counter, ov_current_random_letter_datetime, ov_test_type, ov_test_block, ov_random_letter_is_o, ov_participant_response_time]);
}
// Shows the vigilance test (small background circles and flashing random letters) when needed.
function showVigilanceDisplay(banner_text = "") {
function showVigilanceDisplay(banner_text = "", each_test_block_duration = 0) {
// Let's the primary keydown() script know that any space bar presses should be counted in the user activity array.
ov_record_user_activity = true;
// Outputs the "Practice Test" banner when needed.
// Outputs the "Practice Test" banner.
if(banner_text !== "") {
$("#vigilance_display_banner_text").html(banner_text); // This is a Practice Test.
$("#vigilance_display_extra_text").html(" ");
ov_test_type = "P"; // Practice Test. Included as part of the user's activity array.
ov_test_block = 0; // The practice test block is always 0.
}
// This is a real test/experiment.
else {
$("#vigilance_display_banner_text").html(" "); // This is a real experiment.
$("#vigilance_display_banner_text").html(" ");
$("#vigilance_display_extra_text").html(" ");
ov_test_type = "E"; // Actual Test (experiment). Included as part of the user's activity array.
// Increments the test block number and then does this every 2-min until a hideVigilanceDisplay() is called later.
++ov_test_block;
ov_test_block_timer_id = setInterval(function() {++ov_test_block; }, OV_TEST_BLOCK_EACH_DURATION);
}
$("#VigilanceDisplay").removeClass("hidden");
......@@ -216,6 +239,9 @@ var ov_participant_response_time = -1;
// Let's the primary keydown() script know that any space bar presses should NOT be counted in the user activity array.
ov_record_user_activity = false;
// Stops incrementing the test block number every 2-min until a showVigilanceDisplay() is called again.
clearInterval(ov_test_block_timer_id);
// Outputs the "Break" banner when needed.
if(banner_text !== "") {
$("#vigilance_display_banner_text").html(banner_text);
......@@ -235,6 +261,7 @@ var ov_participant_response_time = -1;
// Stops the test and submits the user's activity array (space bar responses) to the server.
function concludeTest() {
ov_record_user_activity = false;
clearInterval(ov_test_block_timer_id);
$("#VigilanceDisplay").remove();
$("#vigilance_display_banner_text").html("Test Complete");
$("#vigilance_display_extra_text").html("We know this test was difficult, so we thank you very much for participating!");
......@@ -251,16 +278,15 @@ var ov_participant_response_time = -1;
// THIS WORKS, BUT IS ONLY USEFUL FOR DEBUGGING.
//$("#testing_spacebar").append("@");
// !@#$ ... THIS MAY NOT BE NEEDED.
// The user's previous response time.
ov_participant_response_time_previously = ov_participant_response_time;
// The user's pressed the space bar at this time in ms (Unix epoch from 1970).
ov_participant_response_time = Date.now();
// The time right now.
//var ov_current_datetime = new Date();
// THIS NEEDS TO BE MOVED OUT OF HERE. THE USER ACTIVITY SHOULD BE COMPARED AGAINST WHETHER THEIR RT WAS W/IN RAND LETTER SHOWN.
// Logs the activity to the JS array for the user.
// Note: The `ov_subject_id' var was defined already by the PHP script.
// The title headings are: "SID", "TimeStamp", "Type", "Block", "GlobalTrialCounter", "CurrentTrial", "Target", "Distractor", "FalseAlarm", "RT", "Correct"
//ov_user_activity_array.push(ov_subject_id, ov_timestamp, ov_test_type);
}
});
......@@ -277,12 +303,14 @@ var ov_participant_response_time = -1;
var thirty_seconds_in_ms = parseFloat(30000); // 30 seconds = 30,000 ms [Used between the practice and the real test.]
var practice_time_in_ms = thirty_seconds_in_ms; // Practice Test is only 30 seconds for now.
//var twelve_minutes_in_ms = parseFloat(720000); // 12 minutes = 720,000 ms
//var four_minutes_in_ms = parseFloat(240000); // 4 minutes = 240,000 ms
var twelve_minutes_in_ms = parseFloat(720000); // 12 minutes = 720,000 ms
var four_minutes_in_ms = parseFloat(240000); // 4 minutes = 240,000 ms
// Inaccurate... TESTING VALUES.
var twelve_minutes_in_ms = parseFloat(20000); // 20 seconds
var four_minutes_in_ms = parseFloat(10000); // 10 seconds
//var twelve_minutes_in_ms = parseFloat(20000); // 20 seconds
//var four_minutes_in_ms = parseFloat(10000); // 10 seconds
//var twelve_minutes_in_ms = parseFloat(360000); // 6 minutes = 360,000 ms
//var four_minutes_in_ms = parseFloat(240000); // 4 minutes = 240,000 ms
// -----------------------------------------------------------------------------------------------------------------
// The `ov_test_condition' var was set via PHP, which changes depending on which condition the user is assigned to.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment