Skip to content

Script for converting PL files back to MD #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
221 changes: 221 additions & 0 deletions pl_to_md/.ipynb_checkpoints/PL to Markdown testing-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Convert from PrairieLearn format to a Markdown format"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import yaml"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Python Code section"
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {},
"outputs": [],
"source": [
"from inspect import getmembers, isfunction\n",
"import importlib\n",
"import examples.Two_blocks_connected_by_a_string.server as server_module"
]
},
{
"cell_type": "code",
"execution_count": 82,
"metadata": {},
"outputs": [],
"source": [
"path = 'examples/Two_blocks_connected_by_a_string/server.py'\n"
]
},
{
"cell_type": "code",
"execution_count": 83,
"metadata": {},
"outputs": [],
"source": [
"functions_list = getmembers(server_module, isfunction)"
]
},
{
"cell_type": "code",
"execution_count": 84,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('generate',\n",
" <function examples.Two_blocks_connected_by_a_string.server.generate(data)>),\n",
" ('grade',\n",
" <function examples.Two_blocks_connected_by_a_string.server.grade(data)>),\n",
" ('nested_dict',\n",
" <function examples.Two_blocks_connected_by_a_string.server.<lambda>()>),\n",
" ('parse',\n",
" <function examples.Two_blocks_connected_by_a_string.server.parse(data)>),\n",
" ('prepare',\n",
" <function examples.Two_blocks_connected_by_a_string.server.prepare(data)>)]"
]
},
"execution_count": 84,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"functions_list"
]
},
{
"cell_type": "code",
"execution_count": 85,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'generate'"
]
},
"execution_count": 85,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"functions_list[0][0]"
]
},
{
"cell_type": "code",
"execution_count": 86,
"metadata": {},
"outputs": [],
"source": [
"code = []\n",
"with open(path,'r') as f:\n",
" code = f.readlines()"
]
},
{
"cell_type": "code",
"execution_count": 87,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['import random as rd\\n',\n",
" 'import problem_bank_helpers as pbh\\n',\n",
" 'from collections import defaultdict\\n',\n",
" 'nested_dict = lambda: defaultdict(nested_dict)\\n',\n",
" '\\n',\n",
" 'def generate(data):\\n',\n",
" ' # Start problem code\\n',\n",
" ' \\n',\n",
" ' data2 = nested_dict()\\n',\n",
" ' \\n',\n",
" ' # store phrases etc\\n',\n",
" ' data2[\"params\"][\"vars\"][\"title\"] = \\'Two Blocks Connected by a String\\'\\n',\n",
" ' data2[\"params\"][\"vars\"][\"units\"] = \"N\"\\n',\n",
" ' \\n',\n",
" ' # Define variables in case the image is randomized in the future.\\n',\n",
" ' m1 = 1\\n',\n",
" ' m2 = 1.2\\n',\n",
" ' g = 9.81\\n',\n",
" ' \\n',\n",
" ' # store the variables in the dictionary \"params\". \\n',\n",
" ' data2[\"params\"][\"m1\"] = m1\\n',\n",
" ' \\n',\n",
" ' # define possible answers\\n',\n",
" ' # round in traditional way using pbh.roundp() and then convert to int\\n',\n",
" ' data2[\"params\"][\"part1\"][\"ans1\"][\"value\"] = int(pbh.roundp(m1*g, decimals = 0)) \\n',\n",
" ' data2[\"params\"][\"part1\"][\"ans1\"][\"correct\"] = False\\n',\n",
" ' \\n',\n",
" ' data2[\"params\"][\"part1\"][\"ans2\"][\"value\"] = int(pbh.roundp(m2*g, decimals = 0))\\n',\n",
" ' data2[\"params\"][\"part1\"][\"ans2\"][\"correct\"] = True\\n',\n",
" ' \\n',\n",
" ' data2[\"params\"][\"part1\"][\"ans3\"][\"value\"] = int(pbh.roundp(2*m2*g, decimals = 0))\\n',\n",
" ' data2[\"params\"][\"part1\"][\"ans3\"][\"correct\"] = False\\n',\n",
" ' \\n',\n",
" ' data2[\"params\"][\"part1\"][\"ans4\"][\"value\"] = int(pbh.roundp(2*m1*g, decimals = 0))\\n',\n",
" ' data2[\"params\"][\"part1\"][\"ans4\"][\"correct\"] = False\\n',\n",
" ' \\n',\n",
" ' data2[\"params\"][\"part1\"][\"ans5\"][\"value\"] = int(pbh.roundp(m2*g, decimals = 0)) + 1\\n',\n",
" ' data2[\"params\"][\"part1\"][\"ans5\"][\"correct\"] = False\\n',\n",
" ' \\n',\n",
" ' data2[\"params\"][\"part1\"][\"ans6\"][\"value\"] = int(pbh.roundp(m2*g, decimals = 0)) - 1\\n',\n",
" ' data2[\"params\"][\"part1\"][\"ans6\"][\"correct\"] = False\\n',\n",
" ' \\n',\n",
" ' # Update the data object with a new dict\\n',\n",
" ' data.update(data2)\\n',\n",
" ' \\n',\n",
" 'def prepare(data):\\n',\n",
" ' pass\\n',\n",
" ' \\n',\n",
" 'def parse(data):\\n',\n",
" ' pass\\n',\n",
" ' \\n',\n",
" 'def grade(data):\\n',\n",
" ' pass\\n',\n",
" ' \\n']"
]
},
"execution_count": 87,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"code "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for line in code:\n",
" if 'data.update(data2)' in line:\n",
" "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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": 4
}
Loading