From b8b24e04d7a450cac6e9a8a99e4fcce98ddb8016 Mon Sep 17 00:00:00 2001 From: Tom Schierenbeck Date: Tue, 2 Apr 2024 12:23:44 +0200 Subject: [PATCH] Added self assessment quiz. --- doc/conf.py | 14 +- doc/index.rst | 1 + doc/requirements.txt | 7 +- examples/door.ipynb | 2422 +++++++++++++++++++++++++++----- examples/product_spaces.ipynb | 178 +-- examples/self_assessment.ipynb | 1044 ++++++++++++++ 6 files changed, 3248 insertions(+), 418 deletions(-) create mode 100644 examples/self_assessment.ipynb diff --git a/doc/conf.py b/doc/conf.py index faba1d5..7abee84 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -40,21 +40,33 @@ # ones. extensions = [ 'sphinx.ext.autodoc', - 'sphinx.ext.doctest', 'sphinx.ext.coverage', 'sphinx.ext.mathjax', 'sphinx.ext.viewcode', 'sphinx_rtd_theme', 'autoapi.extension', + 'sphinxcontrib.bibtex', 'nbsphinx', 'sphinx_gallery.load_style', + "myst_nb" +] + +myst_enable_extensions = [ + "amsmath", + "colon_fence", + "deflist", + "dollarmath", + "html_image", ] # ----------- autoapi setup ------------- autoapi_dirs = ['../src'] inheritance_graph_attrs = dict(rankdir="TB",) +myst_dmath_double_inline = True +# -- Bibliography configuration ---------------------------------------------- +bibtex_bibfiles = ['references.bib'] # Add any paths that contain templates here, relative to this directory. templates_path = ['templates'] diff --git a/doc/index.rst b/doc/index.rst index fe18133..a7fbdd1 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -99,6 +99,7 @@ Examples examples/example examples/product_spaces examples/logo_generation + examples/self_assessment .. toctree:: :maxdepth: 2 diff --git a/doc/requirements.txt b/doc/requirements.txt index 2908769..7748e53 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -1,4 +1,9 @@ +-r ../requirements.txt sphinx_rtd_theme sphinx-autoapi +sphinxcontrib-bibtex nbsphinx -sphinx_gallery \ No newline at end of file +sphinx-gallery +myst-nb +random-events +pillow \ No newline at end of file diff --git a/examples/door.ipynb b/examples/door.ipynb index f988504..2e81f18 100644 --- a/examples/door.ipynb +++ b/examples/door.ipynb @@ -2,13 +2,13 @@ "cells": [ { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { - "end_time": "2024-03-28T11:49:10.440780Z", - "start_time": "2024-03-28T11:49:10.420290Z" + "end_time": "2024-04-02T06:11:00.232894Z", + "start_time": "2024-04-02T06:11:00.190359Z" } }, "outputs": [ @@ -61,18 +61,18 @@ 7, 6 ], - "legendgroup": "140525813576272", + "legendgroup": "139680682919344", "name": "Event", "showlegend": true, "x": [ - 0, - 0, 2, 2, - 0, - 0, + 4, + 4, 2, - 2 + 2, + 4, + 4 ], "y": [ 5, @@ -141,28 +141,28 @@ 7, 6 ], - "legendgroup": "140525813576272", + "legendgroup": "139680682919344", "name": "Event", "showlegend": false, "x": [ - 4, - 4, - 6, - 6, - 4, - 4, - 6, - 6 + 0, + 0, + 1, + 1, + 0, + 0, + 1, + 1 ], "y": [ - 5, + 0, 10, 10, - 5, - 5, + 0, + 0, 10, 10, - 5 + 0 ], "z": [ 0, @@ -221,28 +221,28 @@ 7, 6 ], - "legendgroup": "140525813576272", + "legendgroup": "139680682919344", "name": "Event", "showlegend": false, "x": [ - 2, - 2, - 4, - 4, - 2, - 2, - 4, - 4 + 5, + 5, + 6, + 6, + 5, + 5, + 6, + 6 ], "y": [ - 5, + 0, 10, 10, - 5, - 5, + 0, + 0, 10, 10, - 5 + 0 ], "z": [ 0, @@ -301,16 +301,16 @@ 7, 6 ], - "legendgroup": "140525813576272", + "legendgroup": "139680682919344", "name": "Event", "showlegend": false, "x": [ - 0, - 0, 2, 2, - 0, - 0, + 2, + 2, + 2, + 2, 2, 2 ], @@ -329,10 +329,10 @@ 0, 0, 0, - 10, - 10, - 10, - 10 + 6, + 6, + 6, + 6 ], "type": "mesh3d" }, @@ -381,18 +381,18 @@ 7, 6 ], - "legendgroup": "140525813576272", + "legendgroup": "139680682919344", "name": "Event", "showlegend": false, "x": [ - 4, - 4, - 6, - 6, - 4, - 4, - 6, - 6 + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2 ], "y": [ 0, @@ -405,10 +405,10 @@ 0 ], "z": [ - 0, - 0, - 0, - 0, + 8, + 8, + 8, + 8, 10, 10, 10, @@ -461,27 +461,27 @@ 7, 6 ], - "legendgroup": "140525813576272", + "legendgroup": "139680682919344", "name": "Event", "showlegend": false, "x": [ + 1, + 1, 2, 2, - 2.5, - 2.5, - 2, + 1, + 1, 2, - 2.5, - 2.5 + 2 ], "y": [ 0, - 5, - 5, + 4, + 4, 0, 0, - 5, - 5, + 4, + 4, 0 ], "z": [ @@ -489,10 +489,10 @@ 0, 0, 0, - 6, - 6, - 6, - 6 + 10, + 10, + 10, + 10 ], "type": "mesh3d" }, @@ -541,34 +541,34 @@ 7, 6 ], - "legendgroup": "140525813576272", + "legendgroup": "139680682919344", "name": "Event", "showlegend": false, "x": [ + 1, + 1, 2, 2, - 2.5, - 2.5, - 2, + 1, + 1, 2, - 2.5, - 2.5 + 2 ], "y": [ - 0, 5, - 5, - 0, - 0, + 10, + 10, 5, 5, - 0 + 10, + 10, + 5 ], "z": [ - 8, - 8, - 8, - 8, + 0, + 0, + 0, + 0, 10, 10, 10, @@ -621,28 +621,28 @@ 7, 6 ], - "legendgroup": "140525813576272", + "legendgroup": "139680682919344", "name": "Event", "showlegend": false, "x": [ - 3.5, - 3.5, - 4, - 4, - 3.5, - 3.5, - 4, - 4 + 1, + 1, + 2, + 2, + 1, + 1, + 2, + 2 ], "y": [ - 0, + 4, 5, 5, - 0, - 0, + 4, + 4, 5, 5, - 0 + 4 ], "z": [ 0, @@ -701,34 +701,1954 @@ 7, 6 ], - "legendgroup": "140525813576272", + "legendgroup": "139680682919344", "name": "Event", "showlegend": false, "x": [ - 3.5, - 3.5, + 1, + 1, + 2, + 2, + 1, + 1, + 2, + 2 + ], + "y": [ 4, + 5, + 5, 4, - 3.5, - 3.5, 4, + 5, + 5, 4 ], - "y": [ + "z": [ + 7, + 7, + 7, + 7, + 10, + 10, + 10, + 10 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, 5, + 6, 5, + 2, 0, + 1, + 6, + 3 + ], + "k": [ 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, 5, 5, - 0 + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 4, + 4, + 5, + 5, + 4, + 4, + 5, + 5 + ], + "y": [ + 0, + 3, + 3, + 0, + 0, + 3, + 3, + 0 + ], + "z": [ + 0, + 0, + 0, + 0, + 10, + 10, + 10, + 10 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 4, + 4, + 5, + 5, + 4, + 4, + 5, + 5 + ], + "y": [ + 4, + 10, + 10, + 4, + 4, + 10, + 10, + 4 + ], + "z": [ + 0, + 0, + 0, + 0, + 10, + 10, + 10, + 10 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 4, + 4, + 5, + 5, + 4, + 4, + 5, + 5 + ], + "y": [ + 3, + 4, + 4, + 3, + 3, + 4, + 4, + 3 + ], + "z": [ + 0, + 0, + 0, + 0, + 7, + 7, + 7, + 7 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 4, + 4, + 5, + 5, + 4, + 4, + 5, + 5 + ], + "y": [ + 3, + 4, + 4, + 3, + 3, + 4, + 4, + 3 + ], + "z": [ + 8, + 8, + 8, + 8, + 10, + 10, + 10, + 10 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 4, + 4, + 4, + 4, + 4, + 4, + 4, + 4 + ], + "y": [ + 0, + 2, + 2, + 0, + 0, + 2, + 2, + 0 + ], + "z": [ + 0, + 0, + 0, + 0, + 10, + 10, + 10, + 10 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 4, + 4, + 4, + 4, + 4, + 4, + 4, + 4 + ], + "y": [ + 3, + 10, + 10, + 3, + 3, + 10, + 10, + 3 + ], + "z": [ + 0, + 0, + 0, + 0, + 10, + 10, + 10, + 10 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 2, + 2, + 2.5, + 2.5, + 2, + 2, + 2.5, + 2.5 + ], + "y": [ + 0, + 2, + 2, + 0, + 0, + 2, + 2, + 0 + ], + "z": [ + 0, + 0, + 0, + 0, + 6, + 6, + 6, + 6 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 2, + 2, + 2.5, + 2.5, + 2, + 2, + 2.5, + 2.5 + ], + "y": [ + 0, + 2, + 2, + 0, + 0, + 2, + 2, + 0 + ], + "z": [ + 8, + 8, + 8, + 8, + 10, + 10, + 10, + 10 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 2, + 2, + 2.5, + 2.5, + 2, + 2, + 2.5, + 2.5 + ], + "y": [ + 3, + 5, + 5, + 3, + 3, + 5, + 5, + 3 + ], + "z": [ + 0, + 0, + 0, + 0, + 6, + 6, + 6, + 6 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 2, + 2, + 2.5, + 2.5, + 2, + 2, + 2.5, + 2.5 + ], + "y": [ + 3, + 5, + 5, + 3, + 3, + 5, + 5, + 3 + ], + "z": [ + 8, + 8, + 8, + 8, + 10, + 10, + 10, + 10 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 3.5, + 3.5, + 4, + 4, + 3.5, + 3.5, + 4, + 4 + ], + "y": [ + 0, + 2, + 2, + 0, + 0, + 2, + 2, + 0 + ], + "z": [ + 0, + 0, + 0, + 0, + 6, + 6, + 6, + 6 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 3.5, + 3.5, + 4, + 4, + 3.5, + 3.5, + 4, + 4 + ], + "y": [ + 0, + 2, + 2, + 0, + 0, + 2, + 2, + 0 + ], + "z": [ + 8, + 8, + 8, + 8, + 10, + 10, + 10, + 10 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 3.5, + 3.5, + 4, + 4, + 3.5, + 3.5, + 4, + 4 + ], + "y": [ + 3, + 5, + 5, + 3, + 3, + 5, + 5, + 3 + ], + "z": [ + 0, + 0, + 0, + 0, + 6, + 6, + 6, + 6 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 3.5, + 3.5, + 4, + 4, + 3.5, + 3.5, + 4, + 4 + ], + "y": [ + 3, + 5, + 5, + 3, + 3, + 5, + 5, + 3 + ], + "z": [ + 8, + 8, + 8, + 8, + 10, + 10, + 10, + 10 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 2.5, + 2.5, + 3.5, + 3.5, + 2.5, + 2.5, + 3.5, + 3.5 + ], + "y": [ + 0, + 2, + 2, + 0, + 0, + 2, + 2, + 0 + ], + "z": [ + 0, + 0, + 0, + 0, + 3, + 3, + 3, + 3 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 2.5, + 2.5, + 3.5, + 3.5, + 2.5, + 2.5, + 3.5, + 3.5 + ], + "y": [ + 0, + 2, + 2, + 0, + 0, + 2, + 2, + 0 + ], + "z": [ + 8, + 8, + 8, + 8, + 10, + 10, + 10, + 10 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 2.5, + 2.5, + 3.5, + 3.5, + 2.5, + 2.5, + 3.5, + 3.5 + ], + "y": [ + 3, + 5, + 5, + 3, + 3, + 5, + 5, + 3 + ], + "z": [ + 0, + 0, + 0, + 0, + 3, + 3, + 3, + 3 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 2.5, + 2.5, + 3.5, + 3.5, + 2.5, + 2.5, + 3.5, + 3.5 + ], + "y": [ + 3, + 5, + 5, + 3, + 3, + 5, + 5, + 3 + ], + "z": [ + 8, + 8, + 8, + 8, + 10, + 10, + 10, + 10 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 4, + 4, + 4, + 4, + 4, + 4, + 4, + 4 + ], + "y": [ + 2, + 3, + 3, + 2, + 2, + 3, + 3, + 2 + ], + "z": [ + 0, + 0, + 0, + 0, + 8, + 8, + 8, + 8 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 4, + 4, + 4, + 4, + 4, + 4, + 4, + 4 + ], + "y": [ + 2, + 3, + 3, + 2, + 2, + 3, + 3, + 2 + ], + "z": [ + 9, + 9, + 9, + 9, + 10, + 10, + 10, + 10 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 2, + 2, + 2.5, + 2.5, + 2, + 2, + 2.5, + 2.5 + ], + "y": [ + 2, + 3, + 3, + 2, + 2, + 3, + 3, + 2 + ], + "z": [ + 0, + 0, + 0, + 0, + 6, + 6, + 6, + 6 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 2, + 2, + 2.5, + 2.5, + 2, + 2, + 2.5, + 2.5 + ], + "y": [ + 2, + 3, + 3, + 2, + 2, + 3, + 3, + 2 + ], + "z": [ + 9, + 9, + 9, + 9, + 10, + 10, + 10, + 10 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 3.5, + 3.5, + 4, + 4, + 3.5, + 3.5, + 4, + 4 + ], + "y": [ + 2, + 3, + 3, + 2, + 2, + 3, + 3, + 2 + ], + "z": [ + 0, + 0, + 0, + 0, + 6, + 6, + 6, + 6 + ], + "type": "mesh3d" + }, + { + "color": "grey", + "flatshading": true, + "i": [ + 7, + 0, + 0, + 0, + 4, + 4, + 6, + 6, + 4, + 0, + 3, + 2 + ], + "j": [ + 3, + 4, + 1, + 2, + 5, + 6, + 5, + 2, + 0, + 1, + 6, + 3 + ], + "k": [ + 0, + 7, + 2, + 3, + 6, + 7, + 1, + 1, + 5, + 5, + 7, + 6 + ], + "legendgroup": "139680682919344", + "name": "Event", + "showlegend": false, + "x": [ + 3.5, + 3.5, + 4, + 4, + 3.5, + 3.5, + 4, + 4 + ], + "y": [ + 2, + 3, + 3, + 2, + 2, + 3, + 3, + 2 ], "z": [ - 8, - 8, - 8, - 8, + 9, + 9, + 9, + 9, 10, 10, 10, @@ -781,7 +2701,7 @@ 7, 6 ], - "legendgroup": "140525813576272", + "legendgroup": "139680682919344", "name": "Event", "showlegend": false, "x": [ @@ -795,14 +2715,14 @@ 3.5 ], "y": [ - 0, - 5, - 5, - 0, - 0, - 5, - 5, - 0 + 2, + 3, + 3, + 2, + 2, + 3, + 3, + 2 ], "z": [ 0, @@ -861,7 +2781,7 @@ 7, 6 ], - "legendgroup": "140525813576272", + "legendgroup": "139680682919344", "name": "Event", "showlegend": false, "x": [ @@ -875,20 +2795,20 @@ 3.5 ], "y": [ - 0, - 5, - 5, - 0, - 0, - 5, - 5, - 0 + 2, + 3, + 3, + 2, + 2, + 3, + 3, + 2 ], "z": [ - 8, - 8, - 8, - 8, + 9, + 9, + 9, + 9, 10, 10, 10, @@ -941,7 +2861,7 @@ 7, 6 ], - "legendgroup": "140526905190288", + "legendgroup": "139680683003280", "name": "Event", "showlegend": true, "x": [ @@ -1021,7 +2941,7 @@ 7, 6 ], - "legendgroup": "140526905190288", + "legendgroup": "139680683003280", "name": "Event", "showlegend": false, "x": [ @@ -1101,9 +3021,9 @@ 7, 6 ], - "legendgroup": "140526501139600", + "legendgroup": "139680683003280", "name": "Event", - "showlegend": true, + "showlegend": false, "x": [ 1, 1, @@ -1115,24 +3035,24 @@ 2 ], "y": [ - 0, + 4, 5, 5, - 0, - 0, + 4, + 4, 5, 5, - 0 + 4 ], "z": [ 6, 6, 6, 6, - 8, - 8, - 8, - 8 + 7, + 7, + 7, + 7 ], "type": "mesh3d" }, @@ -1181,7 +3101,7 @@ 7, 6 ], - "legendgroup": "140526501139600", + "legendgroup": "139680683003280", "name": "Event", "showlegend": false, "x": [ @@ -1195,104 +3115,24 @@ 5 ], "y": [ - 0, - 5, - 5, - 0, - 0, - 5, - 5, - 0 - ], - "z": [ - 6, - 6, - 6, - 6, - 8, - 8, - 8, - 8 - ], - "type": "mesh3d" - }, - { - "color": "#bcbd22", - "flatshading": true, - "i": [ - 7, - 0, - 0, - 0, - 4, + 3, 4, - 6, - 6, 4, - 0, 3, - 2 - ], - "j": [ 3, 4, - 1, - 2, - 5, - 6, - 5, - 2, - 0, - 1, - 6, + 4, 3 ], - "k": [ - 0, + "z": [ + 7, 7, - 2, - 3, - 6, 7, - 1, - 1, - 5, - 5, 7, - 6 - ], - "legendgroup": "140526501139600", - "name": "Event", - "showlegend": false, - "x": [ - 2, - 2, - 2.5, - 2.5, - 2, - 2, - 2.5, - 2.5 - ], - "y": [ - 0, - 5, - 5, - 0, - 0, - 5, - 5, - 0 - ], - "z": [ - 8, 8, 8, 8, - 9, - 9, - 9, - 9 + 8 ], "type": "mesh3d" }, @@ -1341,108 +3181,28 @@ 7, 6 ], - "legendgroup": "140526501139600", + "legendgroup": "139680683003280", "name": "Event", "showlegend": false, "x": [ - 3.5, - 3.5, + 2, + 2, 4, 4, - 3.5, - 3.5, + 2, + 2, 4, 4 ], "y": [ - 0, - 5, - 5, - 0, - 0, - 5, - 5, - 0 - ], - "z": [ - 8, - 8, - 8, - 8, - 9, - 9, - 9, - 9 - ], - "type": "mesh3d" - }, - { - "color": "#bcbd22", - "flatshading": true, - "i": [ - 7, - 0, - 0, - 0, - 4, - 4, - 6, - 6, - 4, - 0, + 2, 3, - 2 - ], - "j": [ 3, - 4, - 1, - 2, - 5, - 6, - 5, 2, - 0, - 1, - 6, - 3 - ], - "k": [ - 0, - 7, 2, 3, - 6, - 7, - 1, - 1, - 5, - 5, - 7, - 6 - ], - "legendgroup": "140526501139600", - "name": "Event", - "showlegend": false, - "x": [ - 2.5, - 2.5, - 3.5, - 3.5, - 2.5, - 2.5, - 3.5, - 3.5 - ], - "y": [ - 0, - 5, - 5, - 0, - 0, - 5, - 5, - 0 + 3, + 2 ], "z": [ 8, @@ -2288,7 +4048,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -2314,22 +4074,30 @@ "keyhole_rod = Event({y: portion.closedopen(0, 5), x: portion.closedopen(2.5, 3.5), z: portion.closedopen(3, 6)})\n", "keyhole |= keyhole_rod\n", "\n", - "keyhole_outer_ring = (Event({y: portion.closedopen(0, 5), x: portion.closedopen(1, 5), z: portion.closedopen(6, 8)}) | \n", - " Event({y: portion.closedopen(0, 5), x: portion.closedopen(2, 4), z: portion.closedopen(8, 9)})) \n", - "keyhole_outer_ring = keyhole_outer_ring.difference(keyhole)\n", "keyhole_teeth = ComplexEvent([])\n", - "\n", - "for event in keyhole_outer_ring.events:\n", - " ...\n", - "\n", + "keyhole_teeth |= Event({y: portion.closedopen(4, 5), z: portion.closedopen(6, 7), x: portion.openclosed(1, 2)})\n", + "keyhole_teeth |= Event({y: portion.closedopen(3, 4), z: portion.closedopen(7, 8), x: portion.openclosed(4, 5)})\n", + "keyhole_teeth |= Event({y: portion.closedopen(2, 3), z: portion.closedopen(8, 9), x: portion.openclosed(2, 4)})\n", + "keyhole |= keyhole_teeth\n", "\n", "lock = lock.difference(keyhole)\n", "fig = go.Figure()\n", "fig.add_traces(lock.plot(color=\"grey\"))\n", "fig.add_traces(keyhole.plot(gold))\n", - "fig.add_traces(keyhole_outer_ring.plot(gold))\n", "fig.show()" ] + }, + { + "cell_type": "markdown", + "source": [ + "# Task\n", + "\n", + "Open the door to more powerful tools by crafting the key to this lock." + ], + "metadata": { + "collapsed": false + }, + "id": "c0d592a9fdb0ea1b" } ], "metadata": { diff --git a/examples/product_spaces.ipynb b/examples/product_spaces.ipynb index d0f8fff..07501f2 100644 --- a/examples/product_spaces.ipynb +++ b/examples/product_spaces.ipynb @@ -40,13 +40,13 @@ }, { "cell_type": "code", - "execution_count": 96, + "execution_count": 20, "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { - "end_time": "2024-03-28T11:47:54.695815Z", - "start_time": "2024-03-28T11:47:54.647783Z" + "end_time": "2024-04-02T09:51:19.991441Z", + "start_time": "2024-04-02T09:51:19.952560Z" } }, "outputs": [ @@ -77,7 +77,7 @@ "\n", "A $\\sigma$ algebra is a set of sets that contains all set-differences that can be constructed by combining arbitrary subsets of said set. Furthermore, it contains all countable unions of sets and all infinite intersection of the set. More formally, according to Kolmogoroff: \n", "\n", - "Let $E$ be a space of elementary events. Consider the powerset $2^E$ and le $\\Im \\subset 2^E$ be a set of subsets of $E$. Elements of $\\Im$ are called random events. If $\\Im$ satisfies the following properties,it is called a $\\sigma$-algebra.\n", + "Let $E$ be a space of elementary events. Consider the powerset $2^E$ and let $\\Im \\subset 2^E$ be a set of subsets of $E$. Elements of $\\Im$ are called random events. If $\\Im$ satisfies the following properties,it is called a $\\sigma$-algebra.\n", "\n", "1. $E \\in \\Im$\n", "2. $(A, B) \\in \\Im \\Rightarrow (A - B) \\in \\Im$\n", @@ -97,9 +97,9 @@ "outputs": [ { "data": { - "text/plain": "[set(),\n {'a'},\n {'b'},\n {'c'},\n {'a', 'b'},\n {'a', 'c'},\n {'b', 'c'},\n {'a', 'b', 'c'}]" + "text/plain": "[set(),\n {'b'},\n {'a'},\n {'c'},\n {'a', 'b'},\n {'b', 'c'},\n {'a', 'c'},\n {'a', 'b', 'c'}]" }, - "execution_count": 97, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -118,12 +118,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:54.739063Z", - "start_time": "2024-03-28T11:47:54.735669Z" + "end_time": "2024-04-02T09:51:20.038164Z", + "start_time": "2024-04-02T09:51:20.032278Z" } }, "id": "efd225f025a25755", - "execution_count": 97 + "execution_count": 21 }, { "cell_type": "markdown", @@ -142,7 +142,7 @@ "data": { "text/plain": "True" }, - "execution_count": 98, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -153,12 +153,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:54.747531Z", - "start_time": "2024-03-28T11:47:54.739940Z" + "end_time": "2024-04-02T09:51:20.047924Z", + "start_time": "2024-04-02T09:51:20.039449Z" } }, "id": "4718cfb47e7aabf5", - "execution_count": 98 + "execution_count": 22 }, { "cell_type": "markdown", @@ -181,12 +181,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:54.753107Z", - "start_time": "2024-03-28T11:47:54.748289Z" + "end_time": "2024-04-02T09:51:20.053313Z", + "start_time": "2024-04-02T09:51:20.048824Z" } }, "id": "dc64275c217072e", - "execution_count": 99 + "execution_count": 23 }, { "cell_type": "markdown", @@ -211,12 +211,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:54.758169Z", - "start_time": "2024-03-28T11:47:54.753794Z" + "end_time": "2024-04-02T09:51:20.058955Z", + "start_time": "2024-04-02T09:51:20.054664Z" } }, "id": "e7dc354bb8a70a12", - "execution_count": 100 + "execution_count": 24 }, { "cell_type": "markdown", @@ -234,7 +234,7 @@ }, { "cell_type": "code", - "execution_count": 101, + "execution_count": 25, "outputs": [ { "name": "stdout", @@ -254,8 +254,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:54.765596Z", - "start_time": "2024-03-28T11:47:54.759202Z" + "end_time": "2024-04-02T09:51:20.064966Z", + "start_time": "2024-04-02T09:51:20.059978Z" } }, "id": "27ea010bc8892833" @@ -307,7 +307,7 @@ "data": { "text/plain": "[('bowl', 'blue'),\n ('bowl', 'green'),\n ('bowl', 'red'),\n ('cup', 'blue'),\n ('cup', 'green'),\n ('cup', 'red'),\n ('spoon', 'blue'),\n ('spoon', 'green'),\n ('spoon', 'red')]" }, - "execution_count": 102, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -319,12 +319,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:54.771290Z", - "start_time": "2024-03-28T11:47:54.766273Z" + "end_time": "2024-04-02T09:51:20.073772Z", + "start_time": "2024-04-02T09:51:20.070335Z" } }, "id": "379cef1a50307c47", - "execution_count": 102 + "execution_count": 26 }, { "cell_type": "markdown", @@ -344,7 +344,7 @@ "data": { "text/plain": "[('bowl', 'blue'), ('cup', 'blue')]" }, - "execution_count": 103, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -356,12 +356,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:54.776384Z", - "start_time": "2024-03-28T11:47:54.772103Z" + "end_time": "2024-04-02T09:51:20.087600Z", + "start_time": "2024-04-02T09:51:20.083501Z" } }, "id": "a53e718226f00339", - "execution_count": 103 + "execution_count": 27 }, { "cell_type": "markdown", @@ -383,12 +383,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:54.781173Z", - "start_time": "2024-03-28T11:47:54.777788Z" + "end_time": "2024-04-02T09:51:20.098242Z", + "start_time": "2024-04-02T09:51:20.095769Z" } }, "id": "1bb140fb470e3cf7", - "execution_count": 104 + "execution_count": 28 }, { "cell_type": "markdown", @@ -407,7 +407,7 @@ "data": { "text/plain": "{Symbolic(item): ('bowl', 'cup'), Symbolic(color): ('blue', 'red')}" }, - "execution_count": 105, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } @@ -419,12 +419,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:54.787017Z", - "start_time": "2024-03-28T11:47:54.783981Z" + "end_time": "2024-04-02T09:51:20.202437Z", + "start_time": "2024-04-02T09:51:20.198914Z" } }, "id": "b74c89bfbed07d6f", - "execution_count": 105 + "execution_count": 29 }, { "cell_type": "markdown", @@ -443,7 +443,7 @@ "data": { "text/plain": "\"{color: ('blue',), item: ('bowl',)} u {item: ('cup',), color: ('red',)}\"" }, - "execution_count": 106, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -455,12 +455,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:54.796483Z", - "start_time": "2024-03-28T11:47:54.792970Z" + "end_time": "2024-04-02T09:51:20.219275Z", + "start_time": "2024-04-02T09:51:20.215974Z" } }, "id": "7fd789bf96187ca1", - "execution_count": 106 + "execution_count": 30 }, { "cell_type": "markdown", @@ -498,7 +498,7 @@ }, { "cell_type": "code", - "execution_count": 107, + "execution_count": 31, "outputs": [ { "data": { @@ -1371,7 +1371,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -1389,8 +1389,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:54.810736Z", - "start_time": "2024-03-28T11:47:54.805069Z" + "end_time": "2024-04-02T09:51:20.255477Z", + "start_time": "2024-04-02T09:51:20.245566Z" } }, "id": "a86b223360f60725" @@ -1410,13 +1410,13 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": 32, "outputs": [ { "data": { "text/plain": "{Continuous(x): [2,3] | [4,5] | [6,7], Continuous(y): [10,15] | [25,27]}" }, - "execution_count": 108, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -1428,8 +1428,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:54.907908Z", - "start_time": "2024-03-28T11:47:54.904410Z" + "end_time": "2024-04-02T09:51:20.298050Z", + "start_time": "2024-04-02T09:51:20.294964Z" } }, "id": "86d42ecd896bef10" @@ -1446,7 +1446,7 @@ }, { "cell_type": "code", - "execution_count": 109, + "execution_count": 33, "outputs": [ { "data": { @@ -2379,7 +2379,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -2393,8 +2393,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:54.951792Z", - "start_time": "2024-03-28T11:47:54.943952Z" + "end_time": "2024-04-02T09:51:20.312794Z", + "start_time": "2024-04-02T09:51:20.305798Z" } }, "id": "7d81de549d20f02b" @@ -2411,7 +2411,7 @@ }, { "cell_type": "code", - "execution_count": 110, + "execution_count": 34, "outputs": [ { "data": { @@ -4637,7 +4637,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -4654,8 +4654,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:55.040208Z", - "start_time": "2024-03-28T11:47:54.994045Z" + "end_time": "2024-04-02T09:51:20.339999Z", + "start_time": "2024-04-02T09:51:20.328159Z" } }, "id": "da2b51a986fa9d05" @@ -4691,7 +4691,7 @@ "data": [ { "fill": "toself", - "legendgroup": "140005024656640", + "legendgroup": "140492324370704", "line": { "color": "#636EFA" }, @@ -4730,7 +4730,7 @@ }, { "fill": "toself", - "legendgroup": "140005024656640", + "legendgroup": "140492324370704", "line": { "color": "#636EFA" }, @@ -5609,7 +5609,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -5626,12 +5626,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:55.051862Z", - "start_time": "2024-03-28T11:47:55.041304Z" + "end_time": "2024-04-02T09:51:20.375293Z", + "start_time": "2024-04-02T09:51:20.364330Z" } }, "id": "97f6f80a61c8abaf", - "execution_count": 111 + "execution_count": 35 }, { "cell_type": "markdown", @@ -5695,7 +5695,7 @@ 7, 6 ], - "legendgroup": "140005025507264", + "legendgroup": "140492324628992", "name": "Event", "showlegend": true, "x": [ @@ -5775,7 +5775,7 @@ 7, 6 ], - "legendgroup": "140005025507264", + "legendgroup": "140492324628992", "name": "Event", "showlegend": false, "x": [ @@ -5855,7 +5855,7 @@ 7, 6 ], - "legendgroup": "140005025507264", + "legendgroup": "140492324628992", "name": "Event", "showlegend": false, "x": [ @@ -5935,7 +5935,7 @@ 7, 6 ], - "legendgroup": "140005025507264", + "legendgroup": "140492324628992", "name": "Event", "showlegend": false, "x": [ @@ -6015,7 +6015,7 @@ 7, 6 ], - "legendgroup": "140005025507264", + "legendgroup": "140492324628992", "name": "Event", "showlegend": false, "x": [ @@ -6095,7 +6095,7 @@ 7, 6 ], - "legendgroup": "140005025507264", + "legendgroup": "140492324628992", "name": "Event", "showlegend": false, "x": [ @@ -6979,7 +6979,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -7000,12 +7000,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:55.064229Z", - "start_time": "2024-03-28T11:47:55.052570Z" + "end_time": "2024-04-02T09:51:20.393157Z", + "start_time": "2024-04-02T09:51:20.378761Z" } }, "id": "9e47b2f884e4c9dd", - "execution_count": 112 + "execution_count": 36 }, { "cell_type": "markdown", @@ -7030,7 +7030,7 @@ "data": [ { "fill": "toself", - "legendgroup": "140005025311904", + "legendgroup": "140492324775056", "line": { "color": "#636EFA" }, @@ -7057,7 +7057,7 @@ }, { "fill": "toself", - "legendgroup": "140005025311904", + "legendgroup": "140492324775056", "line": { "color": "#636EFA" }, @@ -7084,7 +7084,7 @@ }, { "fill": "toself", - "legendgroup": "140005025311904", + "legendgroup": "140492324775056", "line": { "color": "#636EFA" }, @@ -7111,7 +7111,7 @@ }, { "fill": "toself", - "legendgroup": "140005025311904", + "legendgroup": "140492324775056", "line": { "color": "#636EFA" }, @@ -7978,7 +7978,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -7999,12 +7999,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:55.077692Z", - "start_time": "2024-03-28T11:47:55.065240Z" + "end_time": "2024-04-02T09:51:20.404082Z", + "start_time": "2024-04-02T09:51:20.394205Z" } }, "id": "b8916038b2521a38", - "execution_count": 113 + "execution_count": 37 }, { "cell_type": "markdown", @@ -8025,7 +8025,7 @@ "data": [ { "fill": "toself", - "legendgroup": "140005024511456", + "legendgroup": "140492324629904", "line": { "color": "#636EFA" }, @@ -8052,7 +8052,7 @@ }, { "fill": "toself", - "legendgroup": "140005024511456", + "legendgroup": "140492324629904", "line": { "color": "#636EFA" }, @@ -8091,7 +8091,7 @@ }, { "fill": "toself", - "legendgroup": "140005024511456", + "legendgroup": "140492324629904", "line": { "color": "#636EFA" }, @@ -8118,7 +8118,7 @@ }, { "fill": "toself", - "legendgroup": "140005024511456", + "legendgroup": "140492324629904", "line": { "color": "#636EFA" }, @@ -8997,7 +8997,7 @@ "plotlyServerURL": "https://plot.ly" } }, - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" @@ -9011,12 +9011,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-03-28T11:47:55.089737Z", - "start_time": "2024-03-28T11:47:55.078484Z" + "end_time": "2024-04-02T09:51:20.416310Z", + "start_time": "2024-04-02T09:51:20.404794Z" } }, "id": "510b80164a41cfc", - "execution_count": 114 + "execution_count": 38 }, { "cell_type": "markdown", diff --git a/examples/self_assessment.ipynb b/examples/self_assessment.ipynb new file mode 100644 index 0000000..0c041bd --- /dev/null +++ b/examples/self_assessment.ipynb @@ -0,0 +1,1044 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "511a12a53c44b9d2", + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, + "source": [ + "# Self Assessment Test\n", + "\n", + "In this notebook, you can check how well you understand the concepts of the sigma algebra and the implementation in this package." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "initial_id", + "metadata": { + "ExecuteTime": { + "end_time": "2024-04-02T10:02:21.588488Z", + "start_time": "2024-04-02T10:02:21.581395Z" + }, + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "remove-input" + ] + }, + "outputs": [ + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/javascript": [ + "var questionsfOkJVCInIPRm=[{\"question\": \"Which shapes can be represented using the sigma algebra?\", \"type\": \"many_choice\", \"answers\": [{\"answer\": \"Triangles\", \"correct\": false}, {\"answer\": \"Squares\", \"correct\": true}, {\"answer\": \"Circles\", \"correct\": false}, {\"answer\": \"Rectangles\", \"correct\": true}, {\"answer\": \"Cubes\", \"correct\": true}, {\"answer\": \"Lines\", \"correct\": true}, {\"answer\": \"Trapezoids\", \"correct\": false}, {\"answer\": \"Parallelograms\", \"correct\": false}, {\"answer\": \"Pyramids\", \"correct\": false}, {\"answer\": \"Hyper-Rectangles\", \"correct\": true}]}];\n", + " // Make a random ID\n", + "function makeid(length) {\n", + " var result = [];\n", + " var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n", + " var charactersLength = characters.length;\n", + " for (var i = 0; i < length; i++) {\n", + " result.push(characters.charAt(Math.floor(Math.random() * charactersLength)));\n", + " }\n", + " return result.join('');\n", + "}\n", + "\n", + "// Choose a random subset of an array. Can also be used to shuffle the array\n", + "function getRandomSubarray(arr, size) {\n", + " var shuffled = arr.slice(0), i = arr.length, temp, index;\n", + " while (i--) {\n", + " index = Math.floor((i + 1) * Math.random());\n", + " temp = shuffled[index];\n", + " shuffled[index] = shuffled[i];\n", + " shuffled[i] = temp;\n", + " }\n", + " return shuffled.slice(0, size);\n", + "}\n", + "\n", + "function printResponses(responsesContainer) {\n", + " var responses=JSON.parse(responsesContainer.dataset.responses);\n", + " var stringResponses='IMPORTANT!To preserve this answer sequence for submission, when you have finalized your answers:
  1. Copy the text in this cell below \"Answer String\"
  2. Double click on the cell directly below the Answer String, labeled \"Replace Me\"
  3. Select the whole \"Replace Me\" text
  4. Paste in your answer string and press shift-Enter.
  5. Save the notebook using the save icon or File->Save Notebook menu item



  6. Answer String:
    ';\n", + " console.log(responses);\n", + " responses.forEach((response, index) => {\n", + " if (response) {\n", + " console.log(index + ': ' + response);\n", + " stringResponses+= index + ': ' + response +\"
    \";\n", + " }\n", + " });\n", + " responsesContainer.innerHTML=stringResponses;\n", + "}\n", + "function check_mc() {\n", + " var id = this.id.split('-')[0];\n", + " //var response = this.id.split('-')[1];\n", + " //console.log(response);\n", + " //console.log(\"In check_mc(), id=\"+id);\n", + " //console.log(event.srcElement.id) \n", + " //console.log(event.srcElement.dataset.correct) \n", + " //console.log(event.srcElement.dataset.feedback)\n", + "\n", + " var label = event.srcElement;\n", + " //console.log(label, label.nodeName);\n", + " var depth = 0;\n", + " while ((label.nodeName != \"LABEL\") && (depth < 20)) {\n", + " label = label.parentElement;\n", + " console.log(depth, label);\n", + " depth++;\n", + " }\n", + "\n", + "\n", + "\n", + " var answers = label.parentElement.children;\n", + "\n", + " //console.log(answers);\n", + "\n", + "\n", + " // Split behavior based on multiple choice vs many choice:\n", + " var fb = document.getElementById(\"fb\" + id);\n", + "\n", + "\n", + "\n", + "\n", + " if (fb.dataset.numcorrect == 1) {\n", + " // What follows is for the saved responses stuff\n", + " var outerContainer = fb.parentElement.parentElement;\n", + " var responsesContainer = document.getElementById(\"responses\" + outerContainer.id);\n", + " if (responsesContainer) {\n", + " //console.log(responsesContainer);\n", + " var response = label.firstChild.innerText;\n", + " if (label.querySelector(\".QuizCode\")){\n", + " response+= label.querySelector(\".QuizCode\").firstChild.innerText;\n", + " }\n", + " console.log(response);\n", + " //console.log(document.getElementById(\"quizWrap\"+id));\n", + " var qnum = document.getElementById(\"quizWrap\"+id).dataset.qnum;\n", + " console.log(\"Question \" + qnum);\n", + " //console.log(id, \", got numcorrect=\",fb.dataset.numcorrect);\n", + " var responses=JSON.parse(responsesContainer.dataset.responses);\n", + " console.log(responses);\n", + " responses[qnum]= response;\n", + " responsesContainer.setAttribute('data-responses', JSON.stringify(responses));\n", + " printResponses(responsesContainer);\n", + " }\n", + " // End code to preserve responses\n", + " \n", + " for (var i = 0; i < answers.length; i++) {\n", + " var child = answers[i];\n", + " //console.log(child);\n", + " child.className = \"MCButton\";\n", + " }\n", + "\n", + "\n", + "\n", + " if (label.dataset.correct == \"true\") {\n", + " // console.log(\"Correct action\");\n", + " if (\"feedback\" in label.dataset) {\n", + " fb.textContent = jaxify(label.dataset.feedback);\n", + " } else {\n", + " fb.textContent = \"Correct!\";\n", + " }\n", + " label.classList.add(\"correctButton\");\n", + "\n", + " fb.className = \"Feedback\";\n", + " fb.classList.add(\"correct\");\n", + "\n", + " } else {\n", + " if (\"feedback\" in label.dataset) {\n", + " fb.textContent = jaxify(label.dataset.feedback);\n", + " } else {\n", + " fb.textContent = \"Incorrect -- try again.\";\n", + " }\n", + " //console.log(\"Error action\");\n", + " label.classList.add(\"incorrectButton\");\n", + " fb.className = \"Feedback\";\n", + " fb.classList.add(\"incorrect\");\n", + " }\n", + " }\n", + " else {\n", + " var reset = false;\n", + " var feedback;\n", + " if (label.dataset.correct == \"true\") {\n", + " if (\"feedback\" in label.dataset) {\n", + " feedback = jaxify(label.dataset.feedback);\n", + " } else {\n", + " feedback = \"Correct!\";\n", + " }\n", + " if (label.dataset.answered <= 0) {\n", + " if (fb.dataset.answeredcorrect < 0) {\n", + " fb.dataset.answeredcorrect = 1;\n", + " reset = true;\n", + " } else {\n", + " fb.dataset.answeredcorrect++;\n", + " }\n", + " if (reset) {\n", + " for (var i = 0; i < answers.length; i++) {\n", + " var child = answers[i];\n", + " child.className = \"MCButton\";\n", + " child.dataset.answered = 0;\n", + " }\n", + " }\n", + " label.classList.add(\"correctButton\");\n", + " label.dataset.answered = 1;\n", + " fb.className = \"Feedback\";\n", + " fb.classList.add(\"correct\");\n", + "\n", + " }\n", + " } else {\n", + " if (\"feedback\" in label.dataset) {\n", + " feedback = jaxify(label.dataset.feedback);\n", + " } else {\n", + " feedback = \"Incorrect -- try again.\";\n", + " }\n", + " if (fb.dataset.answeredcorrect > 0) {\n", + " fb.dataset.answeredcorrect = -1;\n", + " reset = true;\n", + " } else {\n", + " fb.dataset.answeredcorrect--;\n", + " }\n", + "\n", + " if (reset) {\n", + " for (var i = 0; i < answers.length; i++) {\n", + " var child = answers[i];\n", + " child.className = \"MCButton\";\n", + " child.dataset.answered = 0;\n", + " }\n", + " }\n", + " label.classList.add(\"incorrectButton\");\n", + " fb.className = \"Feedback\";\n", + " fb.classList.add(\"incorrect\");\n", + " }\n", + " // What follows is for the saved responses stuff\n", + " var outerContainer = fb.parentElement.parentElement;\n", + " var responsesContainer = document.getElementById(\"responses\" + outerContainer.id);\n", + " if (responsesContainer) {\n", + " //console.log(responsesContainer);\n", + " var response = label.firstChild.innerText;\n", + " if (label.querySelector(\".QuizCode\")){\n", + " response+= label.querySelector(\".QuizCode\").firstChild.innerText;\n", + " }\n", + " console.log(response);\n", + " //console.log(document.getElementById(\"quizWrap\"+id));\n", + " var qnum = document.getElementById(\"quizWrap\"+id).dataset.qnum;\n", + " console.log(\"Question \" + qnum);\n", + " //console.log(id, \", got numcorrect=\",fb.dataset.numcorrect);\n", + " var responses=JSON.parse(responsesContainer.dataset.responses);\n", + " if (label.dataset.correct == \"true\") {\n", + " if (typeof(responses[qnum]) == \"object\"){\n", + " if (!responses[qnum].includes(response))\n", + " responses[qnum].push(response);\n", + " } else{\n", + " responses[qnum]= [ response ];\n", + " }\n", + " } else {\n", + " responses[qnum]= response;\n", + " }\n", + " console.log(responses);\n", + " responsesContainer.setAttribute('data-responses', JSON.stringify(responses));\n", + " printResponses(responsesContainer);\n", + " }\n", + " // End save responses stuff\n", + "\n", + "\n", + "\n", + " var numcorrect = fb.dataset.numcorrect;\n", + " var answeredcorrect = fb.dataset.answeredcorrect;\n", + " if (answeredcorrect >= 0) {\n", + " fb.textContent = feedback + \" [\" + answeredcorrect + \"/\" + numcorrect + \"]\";\n", + " } else {\n", + " fb.textContent = feedback + \" [\" + 0 + \"/\" + numcorrect + \"]\";\n", + " }\n", + "\n", + "\n", + " }\n", + "\n", + " if (typeof MathJax != 'undefined') {\n", + " var version = MathJax.version;\n", + " console.log('MathJax version', version);\n", + " if (version[0] == \"2\") {\n", + " MathJax.Hub.Queue([\"Typeset\", MathJax.Hub]);\n", + " } else if (version[0] == \"3\") {\n", + " MathJax.typeset([fb]);\n", + " }\n", + " } else {\n", + " console.log('MathJax not detected');\n", + " }\n", + "\n", + "}\n", + "\n", + "function make_mc(qa, shuffle_answers, outerqDiv, qDiv, aDiv, id) {\n", + " var shuffled;\n", + " if (shuffle_answers == \"True\") {\n", + " //console.log(shuffle_answers+\" read as true\");\n", + " shuffled = getRandomSubarray(qa.answers, qa.answers.length);\n", + " } else {\n", + " //console.log(shuffle_answers+\" read as false\");\n", + " shuffled = qa.answers;\n", + " }\n", + "\n", + "\n", + " var num_correct = 0;\n", + "\n", + "\n", + "\n", + " shuffled.forEach((item, index, ans_array) => {\n", + " //console.log(answer);\n", + "\n", + " // Make input element\n", + " var inp = document.createElement(\"input\");\n", + " inp.type = \"radio\";\n", + " inp.id = \"quizo\" + id + index;\n", + " inp.style = \"display:none;\";\n", + " aDiv.append(inp);\n", + "\n", + " //Make label for input element\n", + " var lab = document.createElement(\"label\");\n", + " lab.className = \"MCButton\";\n", + " lab.id = id + '-' + index;\n", + " lab.onclick = check_mc;\n", + " var aSpan = document.createElement('span');\n", + " aSpan.classsName = \"\";\n", + " //qDiv.id=\"quizQn\"+id+index;\n", + " if (\"answer\" in item) {\n", + " aSpan.innerHTML = jaxify(item.answer);\n", + " //aSpan.innerHTML=item.answer;\n", + " }\n", + " lab.append(aSpan);\n", + "\n", + " // Create div for code inside question\n", + " var codeSpan;\n", + " if (\"code\" in item) {\n", + " codeSpan = document.createElement('span');\n", + " codeSpan.id = \"code\" + id + index;\n", + " codeSpan.className = \"QuizCode\";\n", + " var codePre = document.createElement('pre');\n", + " codeSpan.append(codePre);\n", + " var codeCode = document.createElement('code');\n", + " codePre.append(codeCode);\n", + " codeCode.innerHTML = item.code;\n", + " lab.append(codeSpan);\n", + " //console.log(codeSpan);\n", + " }\n", + "\n", + " //lab.textContent=item.answer;\n", + "\n", + " // Set the data attributes for the answer\n", + " lab.setAttribute('data-correct', item.correct);\n", + " if (item.correct) {\n", + " num_correct++;\n", + " }\n", + " if (\"feedback\" in item) {\n", + " lab.setAttribute('data-feedback', item.feedback);\n", + " }\n", + " lab.setAttribute('data-answered', 0);\n", + "\n", + " aDiv.append(lab);\n", + "\n", + " });\n", + "\n", + " if (num_correct > 1) {\n", + " outerqDiv.className = \"ManyChoiceQn\";\n", + " } else {\n", + " outerqDiv.className = \"MultipleChoiceQn\";\n", + " }\n", + "\n", + " return num_correct;\n", + "\n", + "}\n", + "function check_numeric(ths, event) {\n", + "\n", + " if (event.keyCode === 13) {\n", + " ths.blur();\n", + "\n", + " var id = ths.id.split('-')[0];\n", + "\n", + " var submission = ths.value;\n", + " if (submission.indexOf('/') != -1) {\n", + " var sub_parts = submission.split('/');\n", + " //console.log(sub_parts);\n", + " submission = sub_parts[0] / sub_parts[1];\n", + " }\n", + " //console.log(\"Reader entered\", submission);\n", + "\n", + " if (\"precision\" in ths.dataset) {\n", + " var precision = ths.dataset.precision;\n", + " // console.log(\"1:\", submission)\n", + " submission = Math.round((1 * submission + Number.EPSILON) * 10 ** precision) / 10 ** precision;\n", + " // console.log(\"Rounded to \", submission, \" precision=\", precision );\n", + " }\n", + "\n", + "\n", + " //console.log(\"In check_numeric(), id=\"+id);\n", + " //console.log(event.srcElement.id) \n", + " //console.log(event.srcElement.dataset.feedback)\n", + "\n", + " var fb = document.getElementById(\"fb\" + id);\n", + " fb.style.display = \"none\";\n", + " fb.textContent = \"Incorrect -- try again.\";\n", + "\n", + " var answers = JSON.parse(ths.dataset.answers);\n", + " //console.log(answers);\n", + "\n", + " var defaultFB = \"\";\n", + " var correct;\n", + " var done = false;\n", + " answers.every(answer => {\n", + " //console.log(answer.type);\n", + "\n", + " correct = false;\n", + " // if (answer.type==\"value\"){\n", + " if ('value' in answer) {\n", + " if (submission == answer.value) {\n", + " if (\"feedback\" in answer) {\n", + " fb.textContent = jaxify(answer.feedback);\n", + " } else {\n", + " fb.textContent = jaxify(\"Correct\");\n", + " }\n", + " correct = answer.correct;\n", + " //console.log(answer.correct);\n", + " done = true;\n", + " }\n", + " // } else if (answer.type==\"range\") {\n", + " } else if ('range' in answer) {\n", + " //console.log(answer.range);\n", + " if ((submission >= answer.range[0]) && (submission < answer.range[1])) {\n", + " fb.textContent = jaxify(answer.feedback);\n", + " correct = answer.correct;\n", + " //console.log(answer.correct);\n", + " done = true;\n", + " }\n", + " } else if (answer.type == \"default\") {\n", + " defaultFB = answer.feedback;\n", + " }\n", + " if (done) {\n", + " return false; // Break out of loop if this has been marked correct\n", + " } else {\n", + " return true; // Keep looking for case that includes this as a correct answer\n", + " }\n", + " });\n", + "\n", + " if ((!done) && (defaultFB != \"\")) {\n", + " fb.innerHTML = jaxify(defaultFB);\n", + " //console.log(\"Default feedback\", defaultFB);\n", + " }\n", + "\n", + " fb.style.display = \"block\";\n", + " if (correct) {\n", + " ths.className = \"Input-text\";\n", + " ths.classList.add(\"correctButton\");\n", + " fb.className = \"Feedback\";\n", + " fb.classList.add(\"correct\");\n", + " } else {\n", + " ths.className = \"Input-text\";\n", + " ths.classList.add(\"incorrectButton\");\n", + " fb.className = \"Feedback\";\n", + " fb.classList.add(\"incorrect\");\n", + " }\n", + "\n", + " // What follows is for the saved responses stuff\n", + " var outerContainer = fb.parentElement.parentElement;\n", + " var responsesContainer = document.getElementById(\"responses\" + outerContainer.id);\n", + " if (responsesContainer) {\n", + " console.log(submission);\n", + " var qnum = document.getElementById(\"quizWrap\"+id).dataset.qnum;\n", + " //console.log(\"Question \" + qnum);\n", + " //console.log(id, \", got numcorrect=\",fb.dataset.numcorrect);\n", + " var responses=JSON.parse(responsesContainer.dataset.responses);\n", + " console.log(responses);\n", + " if (submission == ths.value){\n", + " responses[qnum]= submission;\n", + " } else {\n", + " responses[qnum]= ths.value + \"(\" + submission +\")\";\n", + " }\n", + " responsesContainer.setAttribute('data-responses', JSON.stringify(responses));\n", + " printResponses(responsesContainer);\n", + " }\n", + " // End code to preserve responses\n", + "\n", + " if (typeof MathJax != 'undefined') {\n", + " var version = MathJax.version;\n", + " console.log('MathJax version', version);\n", + " if (version[0] == \"2\") {\n", + " MathJax.Hub.Queue([\"Typeset\", MathJax.Hub]);\n", + " } else if (version[0] == \"3\") {\n", + " MathJax.typeset([fb]);\n", + " }\n", + " } else {\n", + " console.log('MathJax not detected');\n", + " }\n", + " return false;\n", + " }\n", + "\n", + "}\n", + "\n", + "function isValid(el, charC) {\n", + " //console.log(\"Input char: \", charC);\n", + " if (charC == 46) {\n", + " if (el.value.indexOf('.') === -1) {\n", + " return true;\n", + " } else if (el.value.indexOf('/') != -1) {\n", + " var parts = el.value.split('/');\n", + " if (parts[1].indexOf('.') === -1) {\n", + " return true;\n", + " }\n", + " }\n", + " else {\n", + " return false;\n", + " }\n", + " } else if (charC == 47) {\n", + " if (el.value.indexOf('/') === -1) {\n", + " if ((el.value != \"\") && (el.value != \".\")) {\n", + " return true;\n", + " } else {\n", + " return false;\n", + " }\n", + " } else {\n", + " return false;\n", + " }\n", + " } else if (charC == 45) {\n", + " var edex = el.value.indexOf('e');\n", + " if (edex == -1) {\n", + " edex = el.value.indexOf('E');\n", + " }\n", + "\n", + " if (el.value == \"\") {\n", + " return true;\n", + " } else if (edex == (el.value.length - 1)) { // If just after e or E\n", + " return true;\n", + " } else {\n", + " return false;\n", + " }\n", + " } else if (charC == 101) { // \"e\"\n", + " if ((el.value.indexOf('e') === -1) && (el.value.indexOf('E') === -1) && (el.value.indexOf('/') == -1)) {\n", + " // Prev symbol must be digit or decimal point:\n", + " if (el.value.slice(-1).search(/\\d/) >= 0) {\n", + " return true;\n", + " } else if (el.value.slice(-1).search(/\\./) >= 0) {\n", + " return true;\n", + " } else {\n", + " return false;\n", + " }\n", + " } else {\n", + " return false;\n", + " }\n", + " } else {\n", + " if (charC > 31 && (charC < 48 || charC > 57))\n", + " return false;\n", + " }\n", + " return true;\n", + "}\n", + "\n", + "function numeric_keypress(evnt) {\n", + " var charC = (evnt.which) ? evnt.which : evnt.keyCode;\n", + "\n", + " if (charC == 13) {\n", + " check_numeric(this, evnt);\n", + " } else {\n", + " return isValid(this, charC);\n", + " }\n", + "}\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "function make_numeric(qa, outerqDiv, qDiv, aDiv, id) {\n", + "\n", + "\n", + "\n", + " //console.log(answer);\n", + "\n", + "\n", + " outerqDiv.className = \"NumericQn\";\n", + " aDiv.style.display = 'block';\n", + "\n", + " var lab = document.createElement(\"label\");\n", + " lab.className = \"InpLabel\";\n", + " lab.textContent = \"Type numeric answer here:\";\n", + " aDiv.append(lab);\n", + "\n", + " var inp = document.createElement(\"input\");\n", + " inp.type = \"text\";\n", + " //inp.id=\"input-\"+id;\n", + " inp.id = id + \"-0\";\n", + " inp.className = \"Input-text\";\n", + " inp.setAttribute('data-answers', JSON.stringify(qa.answers));\n", + " if (\"precision\" in qa) {\n", + " inp.setAttribute('data-precision', qa.precision);\n", + " }\n", + " aDiv.append(inp);\n", + " //console.log(inp);\n", + "\n", + " //inp.addEventListener(\"keypress\", check_numeric);\n", + " //inp.addEventListener(\"keypress\", numeric_keypress);\n", + " /*\n", + " inp.addEventListener(\"keypress\", function(event) {\n", + " return numeric_keypress(this, event);\n", + " }\n", + " );\n", + " */\n", + " //inp.onkeypress=\"return numeric_keypress(this, event)\";\n", + " inp.onkeypress = numeric_keypress;\n", + " inp.onpaste = event => false;\n", + "\n", + " inp.addEventListener(\"focus\", function (event) {\n", + " this.value = \"\";\n", + " return false;\n", + " }\n", + " );\n", + "\n", + "\n", + "}\n", + "function jaxify(string) {\n", + " var mystring = string;\n", + "\n", + " var count = 0;\n", + " var loc = mystring.search(/([^\\\\]|^)(\\$)/);\n", + "\n", + " var count2 = 0;\n", + " var loc2 = mystring.search(/([^\\\\]|^)(\\$\\$)/);\n", + "\n", + " //console.log(loc);\n", + "\n", + " while ((loc >= 0) || (loc2 >= 0)) {\n", + "\n", + " /* Have to replace all the double $$ first with current implementation */\n", + " if (loc2 >= 0) {\n", + " if (count2 % 2 == 0) {\n", + " mystring = mystring.replace(/([^\\\\]|^)(\\$\\$)/, \"$1\\\\[\");\n", + " } else {\n", + " mystring = mystring.replace(/([^\\\\]|^)(\\$\\$)/, \"$1\\\\]\");\n", + " }\n", + " count2++;\n", + " } else {\n", + " if (count % 2 == 0) {\n", + " mystring = mystring.replace(/([^\\\\]|^)(\\$)/, \"$1\\\\(\");\n", + " } else {\n", + " mystring = mystring.replace(/([^\\\\]|^)(\\$)/, \"$1\\\\)\");\n", + " }\n", + " count++;\n", + " }\n", + " loc = mystring.search(/([^\\\\]|^)(\\$)/);\n", + " loc2 = mystring.search(/([^\\\\]|^)(\\$\\$)/);\n", + " //console.log(mystring,\", loc:\",loc,\", loc2:\",loc2);\n", + " }\n", + "\n", + " //console.log(mystring);\n", + " return mystring;\n", + "}\n", + "\n", + "\n", + "function show_questions(json, mydiv) {\n", + " console.log('show_questions');\n", + " //var mydiv=document.getElementById(myid);\n", + " var shuffle_questions = mydiv.dataset.shufflequestions;\n", + " var num_questions = mydiv.dataset.numquestions;\n", + " var shuffle_answers = mydiv.dataset.shuffleanswers;\n", + " var max_width = mydiv.dataset.maxwidth;\n", + "\n", + " if (num_questions > json.length) {\n", + " num_questions = json.length;\n", + " }\n", + "\n", + " var questions;\n", + " if ((num_questions < json.length) || (shuffle_questions == \"True\")) {\n", + " //console.log(num_questions+\",\"+json.length);\n", + " questions = getRandomSubarray(json, num_questions);\n", + " } else {\n", + " questions = json;\n", + " }\n", + "\n", + " //console.log(\"SQ: \"+shuffle_questions+\", NQ: \" + num_questions + \", SA: \", shuffle_answers);\n", + "\n", + " // Iterate over questions\n", + " questions.forEach((qa, index, array) => {\n", + " //console.log(qa.question); \n", + "\n", + " var id = makeid(8);\n", + " //console.log(id);\n", + "\n", + "\n", + " // Create Div to contain question and answers\n", + " var iDiv = document.createElement('div');\n", + " //iDiv.id = 'quizWrap' + id + index;\n", + " iDiv.id = 'quizWrap' + id;\n", + " iDiv.className = 'Quiz';\n", + " iDiv.setAttribute('data-qnum', index);\n", + " iDiv.style.maxWidth =max_width+\"px\";\n", + " mydiv.appendChild(iDiv);\n", + " // iDiv.innerHTML=qa.question;\n", + " \n", + " var outerqDiv = document.createElement('div');\n", + " outerqDiv.id = \"OuterquizQn\" + id + index;\n", + " // Create div to contain question part\n", + " var qDiv = document.createElement('div');\n", + " qDiv.id = \"quizQn\" + id + index;\n", + " \n", + " if (qa.question) {\n", + " iDiv.append(outerqDiv);\n", + "\n", + " //qDiv.textContent=qa.question;\n", + " qDiv.innerHTML = jaxify(qa.question);\n", + " outerqDiv.append(qDiv);\n", + " }\n", + "\n", + " // Create div for code inside question\n", + " var codeDiv;\n", + " if (\"code\" in qa) {\n", + " codeDiv = document.createElement('div');\n", + " codeDiv.id = \"code\" + id + index;\n", + " codeDiv.className = \"QuizCode\";\n", + " var codePre = document.createElement('pre');\n", + " codeDiv.append(codePre);\n", + " var codeCode = document.createElement('code');\n", + " codePre.append(codeCode);\n", + " codeCode.innerHTML = qa.code;\n", + " outerqDiv.append(codeDiv);\n", + " //console.log(codeDiv);\n", + " }\n", + "\n", + "\n", + " // Create div to contain answer part\n", + " var aDiv = document.createElement('div');\n", + " aDiv.id = \"quizAns\" + id + index;\n", + " aDiv.className = 'Answer';\n", + " iDiv.append(aDiv);\n", + "\n", + " //console.log(qa.type);\n", + "\n", + " var num_correct;\n", + " if ((qa.type == \"multiple_choice\") || (qa.type == \"many_choice\") ) {\n", + " num_correct = make_mc(qa, shuffle_answers, outerqDiv, qDiv, aDiv, id);\n", + " if (\"answer_cols\" in qa) {\n", + " //aDiv.style.gridTemplateColumns = 'auto '.repeat(qa.answer_cols);\n", + " aDiv.style.gridTemplateColumns = 'repeat(' + qa.answer_cols + ', 1fr)';\n", + " }\n", + " } else if (qa.type == \"numeric\") {\n", + " //console.log(\"numeric\");\n", + " make_numeric(qa, outerqDiv, qDiv, aDiv, id);\n", + " }\n", + "\n", + "\n", + " //Make div for feedback\n", + " var fb = document.createElement(\"div\");\n", + " fb.id = \"fb\" + id;\n", + " //fb.style=\"font-size: 20px;text-align:center;\";\n", + " fb.className = \"Feedback\";\n", + " fb.setAttribute(\"data-answeredcorrect\", 0);\n", + " fb.setAttribute(\"data-numcorrect\", num_correct);\n", + " iDiv.append(fb);\n", + "\n", + "\n", + " });\n", + " var preserveResponses = mydiv.dataset.preserveresponses;\n", + " console.log(preserveResponses);\n", + " console.log(preserveResponses == \"true\");\n", + " if (preserveResponses == \"true\") {\n", + " console.log(preserveResponses);\n", + " // Create Div to contain record of answers\n", + " var iDiv = document.createElement('div');\n", + " iDiv.id = 'responses' + mydiv.id;\n", + " iDiv.className = 'JCResponses';\n", + " // Create a place to store responses as an empty array\n", + " iDiv.setAttribute('data-responses', '[]');\n", + "\n", + " // Dummy Text\n", + " iDiv.innerHTML=\"Select your answers and then follow the directions that will appear here.\"\n", + " //iDiv.className = 'Quiz';\n", + " mydiv.appendChild(iDiv);\n", + " }\n", + "//console.log(\"At end of show_questions\");\n", + " if (typeof MathJax != 'undefined') {\n", + " console.log(\"MathJax version\", MathJax.version);\n", + " var version = MathJax.version;\n", + " setTimeout(function(){\n", + " var version = MathJax.version;\n", + " console.log('After sleep, MathJax version', version);\n", + " if (version[0] == \"2\") {\n", + " MathJax.Hub.Queue([\"Typeset\", MathJax.Hub]);\n", + " } else if (version[0] == \"3\") {\n", + " MathJax.typeset([mydiv]);\n", + " }\n", + " }, 500);\n", + "if (typeof version == 'undefined') {\n", + " } else\n", + " {\n", + " if (version[0] == \"2\") {\n", + " MathJax.Hub.Queue([\"Typeset\", MathJax.Hub]);\n", + " } else if (version[0] == \"3\") {\n", + " MathJax.typeset([mydiv]);\n", + " } else {\n", + " console.log(\"MathJax not found\");\n", + " }\n", + " }\n", + " }\n", + " return false;\n", + "}\n", + "/* This is to handle asynchrony issues in loading Jupyter notebooks\n", + " where the quiz has been previously run. The Javascript was generally\n", + " being run before the div was added to the DOM. I tried to do this\n", + " more elegantly using Mutation Observer, but I didn't get it to work.\n", + "\n", + " Someone more knowledgeable could make this better ;-) */\n", + "\n", + " function try_show() {\n", + " if(document.getElementById(\"fOkJVCInIPRm\")) {\n", + " show_questions(questionsfOkJVCInIPRm, fOkJVCInIPRm); \n", + " } else {\n", + " setTimeout(try_show, 200);\n", + " }\n", + " };\n", + " \n", + " {\n", + " // console.log(element);\n", + "\n", + " //console.log(\"fOkJVCInIPRm\");\n", + " // console.log(document.getElementById(\"fOkJVCInIPRm\"));\n", + "\n", + " try_show();\n", + " }\n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "from jupyterquiz import display_quiz\n", + "\n", + "q1 = {\n", + " \"question\": \"Which shapes can be represented using the sigma algebra?\",\n", + " \"type\": \"many_choice\",\n", + " \"answers\": [{\"answer\": \"Triangles\", \"correct\": False},\n", + " {\"answer\": \"Squares\", \"correct\": True},\n", + " {\"answer\": \"Circles\", \"correct\": False},\n", + " {\"answer\": \"Rectangles\", \"correct\": True},\n", + " {\"answer\": \"Cubes\", \"correct\": True},\n", + " {\"answer\": \"Lines\", \"correct\": True},\n", + " {\"answer\": \"Trapezoids\", \"correct\": False},\n", + " {\"answer\": \"Parallelograms\", \"correct\": False},\n", + " {\"answer\": \"Pyramids\", \"correct\": False},\n", + " {\"answer\": \"Hyper-Rectangles\", \"correct\": True},\n", + " ]\n", + "}\n", + "display_quiz([q1])" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "random-events", + "language": "python", + "name": "random-events" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}