Verified Commit 1948ba42 authored by Anton Akhmerov's avatar Anton Akhmerov
Browse files

prune obsolete scaffolding

parent 89c76eea
Pipeline #81668 passed with stages
in 45 minutes and 55 seconds
......@@ -8,8 +8,6 @@ execute_ipynbs:
stage: build
script:
- jupyter-book build src
# Workaround of https://github.com/executablebooks/MyST-NB/issues/287
- cp src/_static/mystnb.css src/_build/html/_static/
artifacts:
paths:
- src/_build/html
......
......@@ -15,11 +15,9 @@ sys.path.extend(module_dir)
__all__ = [
"MoocVideo",
"MoocDiscussion",
"MoocCheckboxesAssessment",
"MoocMultipleChoiceAssessment",
"MoocSelfAssessment",
"Video",
"Checkboxes",
"MultipleChoice",
]
......@@ -38,48 +36,11 @@ def _replace_latex_delimiters(text):
return re.sub(r"\$(.+?)\$", (lambda match: fr"\({match.group(1)}\)"), text)
class MoocComponent:
def _repr_mimebundle_(self, include, exclude):
return {
"application/vnd.edx.olxml+xml": ElementTree.tostring(
self.xml, encoding="unicode"
),
}
class MoocVideo(MoocComponent, display.YouTubeVideo):
class Video(display.YouTubeVideo):
def __init__(
self,
id,
src_location=None,
res="720",
display_name="",
download_track="true",
download_video="true",
show_captions="true",
**kwargs,
):
"""A video component of an EdX mooc embeddable in IPython notebook."""
self.xml = Element(
"video",
attrib=dict(
youtube=f"1.00:{id}",
youtube_id_1_0=id,
display_name=display_name,
download_track=download_track,
download_video=download_video,
show_captions=show_captions,
**kwargs,
),
)
if src_location is not None:
self.xml.attrib["source"] = (
"http://delftxdownloads.tudelft.nl/TOPOCMx-QuantumKnots/"
f"TOPOCMx-{src_location}-video.{res}.mp4"
)
super().__init__(id, rel=0, cc_load_policy=1)
def _repr_html_(self):
......@@ -89,43 +50,16 @@ class MoocVideo(MoocComponent, display.YouTubeVideo):
)
class MoocSelfAssessment(MoocComponent):
def __init__(self):
self.placeholder = (
"<p><b> MoocSelfAssessment description</b></p>\n"
"<p><b>In the live version of the course, you would "
"need to share your solution and grade yourself."
"</b></p>"
)
content_filename = module_dir + "/xmls/openassessment_self.xml"
with open(content_filename, "r") as content_file:
self.xml = xml = ElementTree.fromstring(content_file.read())
assessment = xml.find("assessments").find("assessment")
xml.attrib["submission_start"] = "2001-12-31T10:00:00Z"
xml.attrib["submission_due"] = "2100-12-31T10:00:00Z"
assessment.attrib["start"] = "2001-12-31T10:00:00Z"
assessment.attrib["due"] = "2100-12-31T10:00:00Z"
def _repr_html_(self):
return self.placeholder
class MoocCheckboxesAssessment(MoocComponent):
class Checkboxes:
def __init__(
self,
question,
answers,
correct_answers,
max_attempts=2,
display_name="Question",
explanation=None,
):
"""
MoocCheckboxesAssessment component
A checkboxes html component
input types
-----------
......@@ -135,29 +69,6 @@ class MoocCheckboxesAssessment(MoocComponent):
correct_answers : list of int
"""
self.xml = xml = Element(
"problem",
attrib=dict(display_name=display_name, max_attempts=str(max_attempts),),
)
sub = SubElement(xml, "choiceresponse")
SubElement(sub, "label").text = _replace_latex_delimiters(question)
SubElement(sub, "description").text = "Select the answers that match"
sub = SubElement(sub, "checkboxgroup")
sub.attrib["direction"] = "vertical"
for i, ans in enumerate(answers):
choice = SubElement(sub, "choice")
if i in correct_answers:
choice.attrib["correct"] = "true"
else:
choice.attrib["correct"] = "false"
choice.text = _replace_latex_delimiters(ans)
if explanation is not None:
_add_solution(xml, _replace_latex_delimiters(explanation))
self.question = question
self.answers = answers
self.correct_answers = correct_answers
......@@ -195,18 +106,16 @@ class MoocCheckboxesAssessment(MoocComponent):
return s.format(secrets.token_urlsafe(20), answer)
class MoocMultipleChoiceAssessment(MoocComponent):
class MultipleChoice:
def __init__(
self,
question,
answers,
correct_answer,
max_attempts=2,
display_name="Question",
explanation=None,
):
"""
MoocMultipleChoiceAssessment component
Multiple choice question html component
Parameters:
-----------
......@@ -216,29 +125,6 @@ class MoocMultipleChoiceAssessment(MoocComponent):
correct_answers : int
"""
self.xml = xml = Element(
"problem",
attrib=dict(display_name=display_name, max_attempts=str(max_attempts),),
)
sub = SubElement(xml, "multiplechoiceresponse")
SubElement(sub, "label").text = _replace_latex_delimiters(question)
SubElement(sub, "description").text = "Select the correct answer"
sub = SubElement(sub, "choicegroup")
sub.attrib["type"] = "MultipleChoice"
for i, ans in enumerate(answers):
choice = SubElement(sub, "choice")
if i == correct_answer:
choice.attrib["correct"] = "true"
else:
choice.attrib["correct"] = "false"
choice.text = _replace_latex_delimiters(ans)
if explanation is not None:
_add_solution(xml, _replace_latex_delimiters(explanation))
self.question = question
self.answers = answers
self.correct_answer = correct_answer
......@@ -267,35 +153,3 @@ class MoocMultipleChoiceAssessment(MoocComponent):
<div id="{0}" style="display:none">{1}</div>"""
)
return s.format(secrets.token_urlsafe(20), answer)
class MoocDiscussion(MoocComponent):
def __init__(
self,
discussion_category,
discussion_target,
display_name=None,
discussion_id=None,
**kwargs,
):
discussion_id = md5(
discussion_category.encode("utf-8") + discussion_target.encode("utf-8")
).hexdigest()
self.xml = Element(
"discussion",
attrib=dict(
discussion_category=discussion_category,
discussion_target=discussion_target,
display_name=(display_name or discussion_target),
discussion_id=discussion_id,
url_name=discussion_id,
**kwargs,
),
)
self.display_name = display_name or discussion_target
def _repr_html_(self):
return (
f"<p><b>Discussion</b> {self.display_name}"
" is available in the EdX version of the course.</p>"
)
../website_assets/static/hv_widgets_settings.css
\ No newline at end of file
......@@ -18,13 +18,13 @@ from IPython import display
from IPython.display import display_html
from matplotlib import pyplot as plt
import edx_components
import components
import functions
from pfapack import pfaffian as pf
from edx_components import *
from components import *
from functions import *
init_mooc_nb = [
init_course = [
"np",
"matplotlib",
"kwant",
......@@ -38,7 +38,7 @@ init_mooc_nb = [
"display_html",
]
__all__ = init_mooc_nb + edx_components.__all__ + functions.__all__
__all__ = init_course + components.__all__ + functions.__all__
# Adjust printing of matrices, and numpy printing of numbers.
......@@ -75,9 +75,9 @@ def pretty_fmt_complex(num, digits=2):
def print_information():
print(
"Populated the namespace with:\n"
+ ", ".join(init_mooc_nb)
+ "\nfrom code/edx_components:\n"
+ ", ".join(edx_components.__all__)
+ ", ".join(init_course)
+ "\nfrom code/components:\n"
+ ", ".join(components.__all__)
+ "\nfrom code/functions:\n"
+ ", ".join(functions.__all__)
)
......
/**
* Calico Jupyter Notebooks Extensions
*
* Copyright (c) The Calico Project
* http://calicoproject.org/ICalico
*
* Released under the BSD Simplified License
*
**/
function ip_version() {
if (IPython.version[0] === "2")
return 2;
else if (IPython.version[0] === "3")
return 3;
else
throw "IPython version not supported";
}
function break_into_sections(index) {
if (ip_version() === 2)
return 0;
var cells = IPython.notebook.get_cells();
var count = 0; // count below index, or -1
// go in reverse order to keep index accurate
for (var i = cells.length - 1; i > -1; i--) {
var cell = cells[i];
var rendered = cell.rendered;
// consider it for breaking:
if (cell.cell_type === "markdown") {
var text = cell.get_text();
if (text.match(/^#+Table of Contents/))
continue;
var lines = text.split(/\n/g);
if (lines.length > 1) {
// possibly break up
var state = "ok";
var current = "";
var cell_texts = [];
for (var line_no in lines) {
var line = lines[line_no];
if (state === "ok") {
if (line.indexOf('```') === 0) {
// set state to fence: allows for longer fences
state = line.substr(0, line.search("[^`]"));
current += line + "\n";
} else if (line.indexOf('#') === 0) {
if (current !== "") {
cell_texts.push(current.trim());
}
current = "";
cell_texts.push(line);
} else {
current += line + "\n";
}
} else { // in block
if (line.indexOf(state) === 0) {
state = "ok";
current += line + "\n";
cell_texts.push(current.trim());
current = "";
} else {
current += line + "\n";
}
}
} // for
// anything left over:
if (current.trim() !== "") {
cell_texts.push(current.trim());
}
if (cell_texts.length > 1) {
var current_cell = IPython.notebook.get_cell(i);
var added = 0;
for (var j = 0; j < cell_texts.length; j++) {
if (cell_texts[j].trim() !== "") {
if (added === 0) {
current_cell.set_text(cell_texts[j]);
if (rendered) {
current_cell.render();
}
} else {
if (i === index) {
count = -1; // nope, can't do it
} else if (i < index && count !== -1) {
count++;
}
var new_cell = IPython.notebook.insert_cell_below("markdown", i + added - 1);
new_cell.set_text(cell_texts[j]);
if (rendered) {
new_cell.render();
}
}
added++;
}
}
}
}
}
}
return count;
}
function is_heading(cell) {
if (ip_version() === 2)
return (cell.cell_type === "heading");
else
return (cell.cell_type === "markdown" && cell.get_text().indexOf("#") === 0)
}
function get_heading_text(cell) {
if (ip_version() === 2)
return cell.get_text();
else if (cell.get_text().indexOf("######") === 0)
return cell.get_text().substring(6).trim();
else if (cell.get_text().indexOf("#####") === 0)
return cell.get_text().substring(5).trim();
else if (cell.get_text().indexOf("####") === 0)
return cell.get_text().substring(4).trim();
else if (cell.get_text().indexOf("###") === 0)
return cell.get_text().substring(3).trim();
else if (cell.get_text().indexOf("##") === 0)
return cell.get_text().substring(2).trim();
else if (cell.get_text().indexOf("#") === 0)
return cell.get_text().substring(1).trim();
else return "";
}
function repeat(pattern, count) {
if (count < 1) return '';
var result = '';
while (count > 1) {
if (count & 1) result += pattern;
count >>= 1, pattern += pattern;
}
return result + pattern;
}
function set_heading_text(cell, text) {
var rendered = cell.rendered;
cell.unrender();
if (ip_version() === 2)
cell.set_text(text);
else {
var level = get_level(cell);
cell.set_text( repeat("#", level) + " " + text)
}
if (rendered) {
cell.render();
}
}
function get_level(cell) {
if (ip_version() === 2)
return cell.level;
else if (cell.get_text().indexOf("######") === 0)
return 6;
else if (cell.get_text().indexOf("#####") === 0)
return 5;
else if (cell.get_text().indexOf("####") === 0)
return 4;
else if (cell.get_text().indexOf("###") === 0)
return 3;
else if (cell.get_text().indexOf("##") === 0)
return 2;
else if (cell.get_text().indexOf("#") === 0)
return 1;
else return 0;
}
function get_last_cell_index_in_section(level, index) {
var current = index;
while (IPython.notebook.is_valid_cell_index(current + 1)) {
var cell = IPython.notebook.get_cell(current + 1);
if (is_heading(cell) && get_level(cell) <= level) {
return current;
}
current++;
}
return current;
}
function get_index_level_above(level, index) {
var current = current = index - 1;
while (IPython.notebook.is_valid_cell_index(current)) {
var cell = IPython.notebook.get_cell(current);
if (is_heading(cell) && get_level(cell) <= level) {
return current;
}
current--;
}
return undefined;
}
function get_index_level_below(level, index) {
var current = current = index + 1;
while (IPython.notebook.is_valid_cell_index(current)) {
var cell = IPython.notebook.get_cell(current);
if (is_heading(cell) && get_level(cell) <= level) {
return current;
}
current++;
}
return undefined;
}
function section_label() {
// Label headings with numbers, or toggle them off
// If there is a table of contents, re-do it
break_into_sections();
var cells = IPython.notebook.get_cells();
var levels = [0,0,0,0,0,0];
var current_level = 1;
var flag = false;
var alert_text = "";
var alert_flag = false;
var remove_numbering = true;
for (var i = 0; i < cells.length; i++) {
var cell = cells[i];
if (is_heading(cell)) {
if (cell.get_text().match(/^#+Table of Contents/))
continue;
if (cell.get_text().match(/^#+References/))
continue;
var level = get_level(cell);
if (level >= current_level) { //just keep incrementing
current_level = level;
levels[level-1]++;
} else { //went back a level
levels[current_level-1] = 0;
if (current_level-level > 1) { //Skipped levels in between
for (var j = 1; j < current_level-level; j++) { //back-prop the zeros
levels[current_level - 1 - j] = 0;
}
}
levels[level -1]++;
current_level = level;
}
var error = false;
var error_no_begin = 0;
var error_no_end = 0;
var error_heading_label = "";
var heading_label = ""; //Generate the appropriate number for the heading
for (var k = 0; k < level; k++) {
if (levels[k] == 0) {
if (!error) {
error_heading_label = heading_label;
error = true;
error_no_begin = k;
} else {
error_no_end = k + 2;
}
}
heading_label += levels[k];
if (level-k == 1 && level > 1) {
break;
}
heading_label += ".";
}
if (error) {
if (error_no_end == 0) {
error_no_end = error_no_begin + 2;
}
if (error_heading_label == "") {
if (!flag) {
var temp1 = "Notebook begins with a Header " + error_no_end + " cell." + "\n";
alert_text += temp1;
alert_flag = true;
flag = true;
}
} else{
var temp = "You placed a Header " + error_no_end + " cell under a Header " + error_no_begin + " cell in section " + error_heading_label +"\n";
alert_text += temp;
alert_flag = true;
}
}
var heading_text = get_heading_text(cell);
var old_header = heading_text;
var re = /(?:\d*\.*)*\s*(.*)/;
var match = heading_text.match(re);
if (match) {
heading_text = heading_label + " " + match[1];
} else {
heading_text = heading_label;
}
if (old_header != heading_text) {
remove_numbering = false;
replace_links(old_header, heading_text);
}
heading_text = heading_text.trim();
set_heading_text(cell, heading_text);
}
}
if (alert_flag) {
alert(alert_text);
}
if (remove_numbering) {
for (var i = 0; i < cells.length; i++) {
var cell = cells[i];
if (is_heading(cell)) {
if (cell.get_text().match(/^#+Table of Contents/))
continue;
if (cell.get_text().match(/^#+References/))
continue;
var heading_text = get_heading_text(cell);
old_header = heading_text;
var re = /(?:\d*\.*)*\s*(.*)/;
var match = heading_text.match(re);
if (match) {
heading_text = match[1];
}
set_heading_text(cell, heading_text);
replace_links(old_header, heading_text);
}
}
}
// If there is a Table of Contents, replace it:
var cells = IPython.notebook.get_cells();
for (var i = 0; i < cells.length; i++) {
var cell = cells[i];
if (cell.cell_type == "markdown") {
var cell_text = cell.get_text();
var match = cell_text.match(/^#+Table of Contents/);
if (match) {
table_of_contents();
break;
}
}