Skip to content

Instantly share code, notes, and snippets.

@beneater
Created March 30, 2012 21:50
Show Gist options
  • Save beneater/2255628 to your computer and use it in GitHub Desktop.
Save beneater/2255628 to your computer and use it in GitHub Desktop.
Power mode topic migration shtuff
//
// Set map layout
//
function setLayout( data ) {
jQuery.ajax({
url: "/api/v1/maplayout",
type: "PUT",
contentType: "application/json",
data: JSON.stringify( data ),
complete: function( a, result ) {
console.log( result + ": Set map layout" );
}
});
}
jQuery.getJSON( 'http://www.eater.net/khan/layout?callback=?' );
//
// Update exercise positions/prereqs/covers
//
function addExerciseCallback( data ) {
var total = 0;
var done = 0;
jQuery.each( data, function( n, exercise ) {
if ( !exercise.exercise_model.summative ) {
total++;
jQuery.ajax({
url: "/api/v1/exercises/" + exercise.exercise,
type: "PUT",
data: JSON.stringify( exercise.exercise_model ),
contentType: "application/json; charset=utf-8",
complete: function( a, result ) {
done++;
console.log( result + " (" + done + "/" + total + "): Update exercise " + exercise.exercise );
}
});
}
});
}
jQuery.getJSON( 'http://www.eater.net/khan/exercises-new?callback=?' );
//
// Also manually move summatives so they are in reasonable positions pre-retirement:
//
// * Arithmetic challenge: 0, 20
// * Pre-algebra challenge: -3, 29
// * Algebra challenge: -7, 49
// * Trigonometry challenge: -16, 50
//
//
// Remove all exercises from topics:
//
jQuery.ajax({
url: "/api/v1/topicversion/edit/topictree",
type: "GET",
complete: function( a, b ) {
var total = 0;
var done = 0;
var topictree = JSON.parse( a.responseText )
var removeExerciseFromTopic = function( exercise, topic ) {
total++;
jQuery.ajax({
url: "/api/v1/topic/" + topic + "/deletechild",
type: "POST",
data: {
kind: "Exercise",
id: exercise.name
},
complete: function( a, result ) {
done++;
console.log( result + " (" + done + "/" + total + "): Remove " + exercise.name + " from " + topic );
}
});
}
var processTopic = function( topic ) {
jQuery.each( topic.children, function( n, child ) {
if ( child.kind === "Topic" ) {
processTopic( child );
} else if ( child.kind === "Exercise" ) {
removeExerciseFromTopic( child, topic.id );
}
});
}
processTopic( topictree )
}
})
//
// Create new topics
//
function addTopic( topic, parent_id ) {
topic.kind = "Topic";
jQuery.ajax({
url: "/api/v1/topic/" + topic.id,
type: "PUT",
data: JSON.stringify( topic ),
contentType: "application/json; charset=utf-8",
complete: function( a, result ) {
console.log( result + ": Create topic " + topic.id );
if ( result === "success" ) {
jQuery.ajax({
url: "/api/v1/topic/" + parent_id + "/addchild",
type: "POST",
data: {
"kind": "Topic",
"id": topic.id
},
complete: function( a, result ) {
console.log( result + ": Add topic " + topic.id + " to " + parent_id );
}
});
} else {
console.log( "failed: Add topic " + topic.id );
}
}
});
}
addTopic({ id: "telling-time", title: "Telling time" }, "arithmetic" );
addTopic({ id: "rates-and-ratios", title: "Rates and ratios" }, "arithmetic" );
addTopic({ id: "pythagorean-theorem", title: "Pythagorean theorem" }, "algebra" );
addTopic({ id: "solving-linear-equations-and-inequalities", title: "Solving linear equations and inequalities" }, "algebra" );
addTopic({ id: "equation-of-a-line", title: "Equation of a line" }, "algebra" );
addTopic({ id: "polynomials-and-quadratics", title: "Polynomials and quadratics" }, "algebra" );
addTopic({ id: "vectors", title: "Vectors" }, "linear-algebra" );
//
// Add exercises to correct topics
//
function exerciseTopicCallback( data ) {
var total = 0;
var done = 0;
jQuery.each( data, function( topic, exercises ) {
jQuery.each( exercises, function( n, exercise ) {
total++;
jQuery.ajax({
url: "/api/v1/topic/" + topic + "/addchild",
type: "POST",
data: {
"kind": "Exercise",
"id": exercise,
"pos": null
},
complete: function( a, result ) {
done++;
console.log( result + " (" + done + "/" + total + "): Add exercise " + exercise + " to topic " + topic );
}
});
})
})
}
jQuery.getJSON( 'http://www.eater.net/khan/topics?callback=?' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment