Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add task navigation and loading by index #138

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 59 additions & 22 deletions apps/js/testing_interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -173,33 +175,65 @@ 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];
$.getJSON(task["download_url"], function(json) {
try {
train = json['train'];
test = json['test'];
} catch (e) {
errorMsg('Bad file format');
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);
})
.error(function(){
errorMsg('Error loading task');
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";

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);

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');
});
}

function randomTask() {
loadTask(null);
}

function loadTaskByIndex() {
const taskIndex = document.getElementById('task_index_input').value;
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?')
Expand Down Expand Up @@ -272,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) {
Expand Down Expand Up @@ -378,4 +413,6 @@ $(document).ready(function () {
}
}
});

load_training_tasks()
});
9 changes: 9 additions & 0 deletions apps/testing_interface.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<br />
<input type="file" class="load_task"/>
<button onclick="randomTask()" id="random_task_btn">Random task</button>

<!-- Add new input for task index -->
<input type="number" id="task_index_input" placeholder="Enter task index">
<button onclick="loadTaskByIndex()" id="load_task_by_index_btn">Load by Index</button>

</div>
</div>
<div id="workspace">
Expand All @@ -48,6 +53,10 @@
<input type="file" id="load_task_file_input" class="load_task" style="display: none;"/>
<input type="button" value="Browse..." onclick="document.getElementById('load_task_file_input').click();" />
<button onclick="randomTask()" id="random_task_btn"> Random... </button>

<button onclick="previousTask()" id="prev_task_btn">Previous Task</button>
<button onclick="nextTask()" id="next_task_btn">Next Task</button>

<p>
<label id='task_name' for="random_task_btn"> Task name: </label>
<p>
Expand Down