Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
735 views
�
�F�V; �@sKddlZddlZddlmZejje�Zejje�ddl	m
Z
ddlZddlm
Z
ddddd	d
dgZGdd
�d
e�ZGdd�dee
j�ZGdd�de�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd	�d	e�ZGdd�de�ZdS)�N)�md5)�display)�save_youtube_cc�	MoocVideo�PreprintReference�MoocDiscussion�MoocCheckboxesAssessment�MoocMultipleChoiceAssessment�MoocPeerAssessment�MoocSelfAssessmentc@seZdZdd�ZdS)�
MoocComponentcCsdj|jjt|j��S)Nz
{0}(**{1}))�format�	__class__�__name__�repr�param)�self�r�../code/edx_components.py�__repr__szMoocComponent.__repr__N)r�
__module__�__qualname__rrrrrrsrc	s4eZdZdddddd�fdd�Z�S)rNZ720��truecs�t�}	|	d=|	d=|	d=|	d=|	d=|	d=|j|	�||d<d||d	<d
}
|dk	r�|
j||�|d<n||_tt|�j|d
ddd�dS)z@A video component of an EdX mooc embeddable in IPython notebook.�kwargsrr�id�src_location�resZyoutube_id_1_0z1.00:ZyoutubezPhttp://delftxdownloads.tudelft.nl/TOPOCMx-QuantumKnots/TOPOCMx-{0}-video.{1}.mp4N�source�relrZcc_load_policy�)�locals�updater
r�superr�__init__)rrrr�display_nameZdownload_trackZdownload_videoZ
show_captionsr�tmp�loc)rrrr$s	

	zMoocVideo.__init__)rrrr$rr)rrrs	c@s.eZdZdddd�Zdd�ZdS)rrTcCs;d}||_||_||_tj||�|_dS)z0Formatted basic information from arxiv preprint.z*http://export.arxiv.org/api/query?id_list=N)�index�
show_abstract�description�
feedparser�parse�data)rr(r*r)Zarxiv_queryrrrr$,s
			zPreprintReference.__init__cCs�|j}|j}|ddd}d|d}|d||f7}|d7}|djd	d
�|dddD��7}|d7}|jr�|d
7}||ddd7}|d7}n|jr�|d|j7}n|S)N�entriesr�titlez<h3 class="title mathjax">z</h3>zB<p><a href=http://arxiv.org/abs/%s>http://arxiv.org/abs/%s</a><br>z<div class="authors">z, css|]}|jVqdS)N)�name)�.0�authorrrr�	<genexpr>>sz0PreprintReference._repr_html_.<locals>.<genexpr>�authorsz
</div></p>z(<p><blockquote class="abstract mathjax">�summaryz</blockquote></p>z<p><b>Hint:</b> %s </p>)r-r(�joinr)r*)rr-�indr/�srrr�_repr_html_5s		
,
	

	zPreprintReference._repr_html_N)rrrr$r9rrrrr+s	c@s7eZdZddddddd�Zdd	�ZdS)
r
���	�Nc
	Ksld|_t�}|d=|d=|j|�ttdd��}|j�}	WdQX|	|d<||_dS)Nz�<p><b> Read one of the above papers and see how it is
related to the current topic.</b></p>
<p><b>In the live version of the course, you would need to write a summary which is then assessed by your peers.</b></p>rrz/xmls/openassessment_peer.xml�r�openassessment_peer)�placeholderr!r"�open�
module_dir�readr)
rZ
must_gradeZmust_be_graded_by�due�
review_due�url_namerr&�content_filer?rrrr$Ms		

zMoocPeerAssessment.__init__cCs|jS)N)r@)rrrrr9aszMoocPeerAssessment._repr_html_)rrrr$r9rrrrr
Lsc@s1eZdZddddd�Zdd�ZdS)rr<r=Nc	Kslt�}|d=|d=|j|�d|_ttdd��}|j�}WdQX||d<||_dS)Nrrz�<p><b> MoocSelfAssessment description</b></p>
<p><b>In the live version of the course, you would need to share your solution and grade yourself.</b></p>z/xmls/openassessment_self.xmlr>�openassessment_self)r!r"r@rArBrCr)rrDrErFrr&rGrHrrrr$fs	
	
zMoocSelfAssessment.__init__cCs|jS)N)r@)rrrrr9xszMoocSelfAssessment._repr_html_)rrrr$r9rrrrresc@s:eZdZdddd�Zdd�Zdd�Zd	S)
r��QuestioncKs1t�}|d=|d=|j|�||_dS)z�
        MoocCheckboxesAssessment component

        input types
        -----------

        question : string
        answers : list of strings
        correct_answers : list of int

        rrN)r!r"r)r�question�answers�correct_answers�max_attemptsr%rr&rrrr$}s
	
z!MoocCheckboxesAssessment.__init__cCs+|j}d|d}|d7}|dj|d�7}|d7}djt|d�d	krdd
nd�}g}x'|dD]}|j|d|�q~W|djd
d�|D��7}|d7}y|d|dd7}Wntk
r�YnX|d7}|jtt|�jd��j	�|�S)Nz<h4>%s</h4>rKz<form><input type="checkbox">  z<br><input type="checkbox">  rLz</form>zThe correct answer{0}:<br>rMr zs arez isz, css|]}|VqdS)Nr)r1�trrrr3�sz:MoocCheckboxesAssessment._get_html_repr.<locals>.<genexpr>�.z<br><i>�explanationz</i>a
        <button title="Click to show/hide content" type="button"
        onclick="if(document.getElementById('{0}')
         .style.display=='none') {{document.getElementById('{0}')
         .style.display=''}}else{{document.getElementById('{0}')
         .style.display='none'}}">Show answer</button>

        <div id="{0}" style="display:none">
        {1} <br>
        </div>    zutf-8)
rr6r
�len�append�KeyErrorrr�encode�	hexdigest)rrr8�answerr&�irrr�_get_html_repr�s(	

	 

	z'MoocCheckboxesAssessment._get_html_reprcCs
|j�S)N)rY)rrrrr9�sz$MoocCheckboxesAssessment._repr_html_N)rrrr$rYr9rrrrr|s c@s:eZdZdddd�Zdd�Zdd�Zd	S)
r	rIrJcKs1t�}|d=|d=|j|�||_dS)z�
        MoocMultipleChoiceAssessment component

        Parameters:
        -----------

        question : string
        answers : list of strings
        correct_answers : int

        rrN)r!r"r)rrKrL�correct_answerrNr%rr&rrrr$�s
	
z%MoocMultipleChoiceAssessment.__init__cCs�|j}d|d}|d7}x(|dD]}|d||d7}q,W|d7}d}||d|d	7}y|d
|dd7}Wntk
r�YnX|d
7}|jtt|�jd��j�|�S)Nz<h4>%s</h4>rKz<form>rLz-<input type="radio" name="answer" value="%s">z<br>z</form>zThe correct answer is: <br>rZz<br><i>rQz</i>ad
        <button title="Click to show/hide content" type="button"
        onclick="if(document.getElementById('{0}')
         .style.display=='none') {{document.getElementById('{0}')
         .style.display=''}}else{{document.getElementById('{0}')
         .style.display='none'}}">Show answer</button>

        <div id="{0}" style="display:none">{1}</div>zutf-8)rrTr
rrrUrV)rrr8�ansrWrrrrY�s	


z+MoocMultipleChoiceAssessment._get_html_reprcCs
|j�S)N)rY)rrrrr9�sz(MoocMultipleChoiceAssessment._repr_html_N)rrrr$rYr9rrrrr	�sc@s.eZdZdddd�Zdd�ZdS)rNcKs�t�}|d=|d=|j|�|dkr=||d<n|dkrxt|jd�|jd��j�|d<n||_dS)Nrrr%zutf-8�
discussion_id)r!r"rrUrVr)rZdiscussion_categoryZdiscussion_targetr%r\rr&rrrr$�s	

/zMoocDiscussion.__init__cCsdj|jd�S)NzY<p><b>Discussion</b> entitled '{0}' is available in the online version of the course.</p>r%)r
r)rrrrr9�szMoocDiscussion._repr_html_)rrrr$r9rrrrr�s)�sys�os�hashlibr�path�dirname�__file__rB�extend�IPythonrr+Zgetyoutubeccr�__all__�objectr�YouTubeVideorrr
rrr	rrrrr�<module>s$	!81