generated from gw-ospo/jupyter-book-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added mentimeter code and minor updates to tutorial
- Loading branch information
1 parent
b35541b
commit 50ab826
Showing
3 changed files
with
159 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
""" | ||
Functions to produce formatted string output in Jupyter notebooks | ||
""" | ||
|
||
__all__ = ['format_pseudocode', | ||
] | ||
|
||
__author__ = "James Cumby" | ||
__email__ = "[email protected]" | ||
|
||
|
||
|
||
def format_pseudocode(steps, order): | ||
""" Return pseudocode steps with correct indentation. | ||
Parameters | ||
---------- | ||
steps : dict | ||
Dictionary of pseudocode steps with integer keys | ||
order : list | ||
List of integers defining order of steps | ||
""" | ||
|
||
indent = 0 | ||
shift = -1 | ||
output = '' | ||
|
||
# for step in order: | ||
# indent += shift | ||
# if (('IF' in steps[step]) or ('FOR' in steps[step])) and shift == 0: | ||
# indent -= 4 | ||
# if steps[step][-1] == '.': | ||
# count = 0 | ||
# for character in steps[step][::-1]: | ||
# if character != '.': | ||
# break | ||
# else: | ||
# count += 1 | ||
# indent -= 4*count | ||
# output += " "*indent + steps[step]+'\n' | ||
# shift = 0 | ||
# if ('IF' in steps[step]) or ('FOR' in steps[step]): | ||
# shift = 4 | ||
# if ('CONTINUE' in steps[step]): | ||
# shift = -8 | ||
|
||
for step in order: | ||
output += " "*indent + steps[step]+'\n' | ||
if steps[step][-1] == ':': | ||
indent += 4 | ||
elif steps[step][-1] == '.': | ||
count = 0 | ||
for character in steps[step][::-1]: | ||
if character != '.': | ||
break | ||
else: | ||
count += 1 | ||
indent -= 4*count | ||
if 'CONTINUE' in steps[step]: | ||
indent -= 8 | ||
|
||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
Class to help display mentimeter votes and results within a Jupyter Notebook | ||
""" | ||
|
||
__author__ = 'James Cumby' | ||
__email__ = '[email protected]' | ||
|
||
__all__ = ['Mentimeter',] | ||
|
||
from IPython.display import IFrame, HTML | ||
|
||
class Mentimeter(): | ||
""" Produce HTML code suitable from mentimeter links""" | ||
|
||
def __init__(self, vote=None, result=None): | ||
""" Set up vote and result (display) links. """ | ||
self.vote = vote | ||
self.display = result | ||
|
||
def _vote_iframe(self): | ||
""" Generate IFrame HTML for voting page. """ | ||
if self.vote is not None: | ||
if self.display is not None: | ||
width='30%' | ||
else: | ||
width='70%' | ||
return "<iframe src={} height=100% width={}></iframe>".format(self.vote, width) | ||
else: | ||
return "" | ||
|
||
def _display_iframe(self): | ||
""" Generate IFrame HTML for results page. """ | ||
if self.display is not None: | ||
if self.vote is not None: | ||
width='69%' | ||
else: | ||
width='90%' | ||
return "<iframe src={} height=100% width={}></iframe>".format(self.display, width) | ||
else: | ||
return "" | ||
|
||
def _single_div(self): | ||
""" Combine voting and results iframes (as required) into single div """ | ||
return "<div style='width:100%; height:40vh;'> {} </div>".format(self._vote_iframe() + self._display_iframe()) | ||
|
||
def show(self): | ||
""" Return the ipython HTML object containing the iframes """ | ||
return HTML(self._single_div()) | ||
|