From 7d2986979ab3829bdd4213872822ccf7243a4f7c Mon Sep 17 00:00:00 2001 From: Zoe Nguyen-Ramirez Date: Thu, 19 Sep 2024 17:14:47 -0700 Subject: [PATCH 1/2] add loading by index --- apps/js/testing_interface.js | 28 ++++++++++++++++++++-------- apps/testing_interface.html | 5 +++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/apps/js/testing_interface.js b/apps/js/testing_interface.js index 51d26a4b3..f01b6324c 100644 --- a/apps/js/testing_interface.js +++ b/apps/js/testing_interface.js @@ -173,11 +173,14 @@ function loadTaskFromFile(e) { reader.readAsText(file); } -function randomTask() { - var subset = "training"; - $.getJSON("https://api.github.com/repos/fchollet/ARC/contents/data/" + subset, function(tasks) { - var task_index = Math.floor(Math.random() * tasks.length) - var task = tasks[task_index]; +function loadTask(index) { + const subset = "training"; + const apiUrl = `https://api.github.com/repos/fchollet/ARC/contents/data/${subset}`; + const downloadUrlTemplate = "https://api.github.com/repos/fchollet/ARC/contents/data/%s"; + + $.getJSON(apiUrl, function(tasks) { + const task = index === null ? tasks[Math.floor(Math.random() * tasks.length)] : tasks[index]; + $.getJSON(task["download_url"], function(json) { try { train = json['train']; @@ -187,9 +190,9 @@ function randomTask() { return; } loadJSONTask(train, test); - //$('#load_task_file_input')[0].value = ""; - infoMsg("Loaded task training/" + task["name"]); - display_task_name(task['name'], task_index, tasks.length); + + infoMsg(`Loaded task ${task.name}`); + display_task_name(task.name, index, tasks.length); }) .error(function(){ errorMsg('Error loading task'); @@ -200,6 +203,15 @@ function randomTask() { }); } +function randomTask() { + loadTask(null); +} + +function loadTaskByIndex() { + const taskIndex = document.getElementById('task_index_input').value; + loadTask(parseInt(taskIndex)); +} + function nextTestInput() { if (TEST_PAIRS.length <= CURRENT_TEST_PAIR_INDEX + 1) { errorMsg('No next test input. Pick another file?') diff --git a/apps/testing_interface.html b/apps/testing_interface.html index 3b4dcff01..e997eab13 100644 --- a/apps/testing_interface.html +++ b/apps/testing_interface.html @@ -22,6 +22,11 @@
+ + + + +
From b47cbf6088413b11f06d2c28b62b9368863da392 Mon Sep 17 00:00:00 2001 From: Zoe Nguyen-Ramirez Date: Thu, 19 Sep 2024 17:44:21 -0700 Subject: [PATCH 2/2] add navigation buttons to move among tasks --- apps/js/testing_interface.js | 67 +++++++++++++++++++++++++----------- apps/testing_interface.html | 4 +++ 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/apps/js/testing_interface.js b/apps/js/testing_interface.js index f01b6324c..c66422247 100644 --- a/apps/js/testing_interface.js +++ b/apps/js/testing_interface.js @@ -11,6 +11,8 @@ var EDITION_GRID_HEIGHT = 500; var EDITION_GRID_WIDTH = 500; var MAX_CELL_SIZE = 100; +var task_index = -1 +var training_tasks; function resetTask() { CURRENT_INPUT_GRID = new Grid(3, 3); @@ -173,33 +175,45 @@ function loadTaskFromFile(e) { reader.readAsText(file); } -function loadTask(index) { +async function load_training_tasks() +{ const subset = "training"; const apiUrl = `https://api.github.com/repos/fchollet/ARC/contents/data/${subset}`; + + try { + const response = await $.ajax({ + url: apiUrl, + dataType: 'json' + }); + + training_tasks = response; + } catch (error) { + errorMsg('Error loading task list'); + throw error; + } +} + +function loadTask(index) { const downloadUrlTemplate = "https://api.github.com/repos/fchollet/ARC/contents/data/%s"; - $.getJSON(apiUrl, function(tasks) { - const task = index === null ? tasks[Math.floor(Math.random() * tasks.length)] : tasks[index]; + task_index = index === null ? Math.floor(Math.random() * training_tasks.length) : index; + const task = training_tasks[task_index]; + + $.getJSON(task["download_url"], function(json) { + try { + train = json['train']; + test = json['test']; + } catch (e) { + errorMsg('Bad file format'); + return; + } + loadJSONTask(train, test); - $.getJSON(task["download_url"], function(json) { - try { - train = json['train']; - test = json['test']; - } catch (e) { - errorMsg('Bad file format'); - return; - } - loadJSONTask(train, test); - - infoMsg(`Loaded task ${task.name}`); - display_task_name(task.name, index, tasks.length); - }) - .error(function(){ - errorMsg('Error loading task'); - }); + infoMsg(`Loaded task ${task.name}`); + display_task_name(task.name, task_index, training_tasks.length); }) .error(function(){ - errorMsg('Error loading task list'); + errorMsg('Error loading task'); }); } @@ -212,6 +226,14 @@ function loadTaskByIndex() { loadTask(parseInt(taskIndex)); } +function previousTask() { + loadTask((task_index - 1 + training_tasks.length) % training_tasks.length); +} + +function nextTask() { + loadTask((task_index + 1) % training_tasks.length); +} + function nextTestInput() { if (TEST_PAIRS.length <= CURRENT_TEST_PAIR_INDEX + 1) { errorMsg('No next test input. Pick another file?') @@ -284,7 +306,8 @@ function initializeSelectable() { // Initial event binding. -$(document).ready(function () { +$(function () { + $('#symbol_picker').find('.symbol_preview').click(function(event) { symbol_preview = $(event.target); $('#symbol_picker').find('.symbol_preview').each(function(i, preview) { @@ -390,4 +413,6 @@ $(document).ready(function () { } } }); + + load_training_tasks() }); diff --git a/apps/testing_interface.html b/apps/testing_interface.html index e997eab13..1031a5b40 100644 --- a/apps/testing_interface.html +++ b/apps/testing_interface.html @@ -53,6 +53,10 @@ + + + +