Skip to content

Add pl-integer-input support #101

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

Merged
merged 1 commit into from
Jun 17, 2024
Merged
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
19 changes: 19 additions & 0 deletions src/problem_bank_scripts/problem_bank_scripts.py
Original file line number Diff line number Diff line change
@@ -950,6 +950,23 @@ def process_matrix_input(part_name, parsed_question, data_dict):
).replace("-matrix-component-input", "-matrix-input")


def process_integer_input(part_name, parsed_question, data_dict):
"""Processes markdown format integer-input questions and returns PL HTML
Args:
part_name (string): Name of the question part being processed (e.g., part1, part2, etc...)
parsed_question (dict): Dictionary of the MD-parsed question (output of `read_md_problem`)
data_dict (dict): Dictionary of the `data` dict created after running server.py using `exec()`
Returns:
html: A string of HTML that is part of the final PL question.html file.
"""

html = process_number_input(part_name, parsed_question, data_dict)

return html.replace("-number-input", "-integer-input")


def validate_multiple_choice(part_name, parsed_question, data_dict):
"""Validates a markdown format multiple-choice question
Args:
@@ -1401,6 +1418,8 @@ def process_question_pl(source_filepath, output_path=None, dev=False):
question_html += process_matrix_component_input(part, parsed_q, data2)
elif "matrix-input" in q_type:
question_html += process_matrix_input(part, parsed_q, data2)
elif "integer-input" in q_type:
question_html += f"{process_integer_input(part,parsed_q,data2)}"
else:
raise NotImplementedError(
f"This question type ({q_type}) is not yet implemented."
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
title: Median
topic: Template
author: Gavin Kendal-Freedman
source: original
template_version: 1.4
attribution: standard
partialCredit: true
singleVariant: false
showCorrectAnswer: false
outcomes:
- 6.1.1.0
- 6.1.1.1
difficulty:
- undefined
randomization:
- undefined
taxonomy:
- undefined
span:
- undefined
length:
- undefined
tags:
- unknown
assets: null
server:
imports: |
import random; random.seed(111)
from statistics import median
import problem_bank_helpers as pbh
generate: |
data2 = pbh.create_data2()
numbers = sorted(random.randint(1, 100) for _ in range(9))
# store the variables in the dictionary "params"
data2["params"]["numbers"] = numbers
# define correct answers
data2["correct_answers"]["part1_ans"] = median(numbers)
# Update the data object with a new dict
data.update(data2)
prepare: 'pass
'
parse: 'pass
'
grade: 'pass
'
part1:
type: integer-input
pl-customizations:
weight: 1
allow-blank: true
label: $n= $
myst:
substitutions:
params:
numbers:
- 22
- 25
- 28
- 41
- 51
- 54
- 64
- 79
- 81
correct_answers:
part1_ans: 51

---
# {{ params.vars.title }}
Given a list of numbers ${{ params.vars.numbers }}$, what is the `median` of the list?

## Part 1

### Answer Section

Please enter in a numeric value in.

### pl-submission-panel

Everything here will get inserted directly into the pl-submission-panel element at the end of the `question.html`.
Please remove this section if it is not application for this question.

### pl-answer-panel

Everything here will get inserted directly into an pl-answer-panel element at the end of the `question.html`.
Please remove this section if it is not application for this question.

### pl-answer-panel

Everything here will get inserted directly into an pl-answer-panel element at the end of the `question.html`.

## Rubric

This should be hidden from students until after the deadline.

## Solution

This should never be revealed to students.

## Comments

These are random comments associated with this question.

## Attribution

Problem is licensed under the [CC-BY-NC-SA 4.0 license](https://creativecommons.org/licenses/by-nc-sa/4.0/).<br> ![The Creative Commons 4.0 license requiring attribution-BY, non-commercial-NC, and share-alike-SA license.](https://raw.githubusercontent.com/firasm/bits/master/by-nc-sa.png)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"uuid": "03d2fc31-cc01-3a77-9394-05da8968db50",
"title": "Median",
"topic": "000.Template",
"tags": [
"integer-input",
"DEV"
],
"type": "v3",
"singleVariant": false,
"partialCredit": true,
"showCorrectAnswer": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<pl-question-panel>
<markdown>
Given a list of numbers ${{ params.vars.numbers }}$, what is the `median` of the list?

</markdown>
</pl-question-panel>


<!-- ######## Start of Part 1 ######## -->

<pl-question-panel>
<markdown> </markdown>
</pl-question-panel>

<pl-integer-input answers-name="part1_ans" weight = "1" allow-blank = "True" label = "$n= $" ></pl-integer-input>

<pl-submission-panel>Everything here will get inserted directly into the pl-submission-panel element at the end of the `question.html`.
Please remove this section if it is not application for this question.
</pl-submission-panel>

<pl-answer-panel>Everything here will get inserted directly into an pl-answer-panel element at the end of the `question.html`.
</pl-answer-panel>

<!-- ######## End of Part 1 ######## -->

<pl-question-panel>
<markdown>
---
Problem is licensed under the [CC-BY-NC-SA 4.0 license](https://creativecommons.org/licenses/by-nc-sa/4.0/).<br> ![The Creative Commons 4.0 license requiring attribution-BY, non-commercial-NC, and share-alike-SA license.](https://raw.githubusercontent.com/firasm/bits/master/by-nc-sa.png)
</markdown>
</pl-question-panel>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import random; random.seed(111)
from statistics import median
import problem_bank_helpers as pbh

def imports(data):
import random; random.seed(111)
from statistics import median
import problem_bank_helpers as pbh

def generate(data):
data2 = pbh.create_data2()

numbers = sorted(random.randint(1, 100) for _ in range(9))
# store the variables in the dictionary "params"
data2["params"]["numbers"] = numbers

# define correct answers
data2["correct_answers"]["part1_ans"] = median(numbers)

# Update the data object with a new dict
data.update(data2)

# Start code added automatically by problem_bank_scripts

# Convert backticks to code blocks/fences in answer choices.
pbh.backticks_to_code_tags(data2)

# Update data with data2
data.update(data2)

# End code added in by problem bank scripts

def prepare(data):
pass

def parse(data):
pass

def grade(data):
pass

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"uuid": "9880f3fb-8d29-3365-908c-d2a4eec045c7",
"title": "Median",
"topic": "000.Template",
"tags": [
"integer-input"
],
"type": "v3",
"singleVariant": false,
"partialCredit": true,
"showCorrectAnswer": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<pl-question-panel>
<markdown>
Given a list of numbers ${{ params.vars.numbers }}$, what is the `median` of the list?

</markdown>
</pl-question-panel>


<!-- ######## Start of Part 1 ######## -->

<pl-question-panel>
<markdown> </markdown>
</pl-question-panel>

<pl-integer-input answers-name="part1_ans" weight = "1" allow-blank = "True" label = "$n= $" ></pl-integer-input>

<pl-submission-panel>Everything here will get inserted directly into the pl-submission-panel element at the end of the `question.html`.
Please remove this section if it is not application for this question.
</pl-submission-panel>

<pl-answer-panel>Everything here will get inserted directly into an pl-answer-panel element at the end of the `question.html`.
</pl-answer-panel>

<!-- ######## End of Part 1 ######## -->

<pl-question-panel>
<markdown>
---
Problem is licensed under the [CC-BY-NC-SA 4.0 license](https://creativecommons.org/licenses/by-nc-sa/4.0/).<br> ![The Creative Commons 4.0 license requiring attribution-BY, non-commercial-NC, and share-alike-SA license.](https://raw.githubusercontent.com/firasm/bits/master/by-nc-sa.png)
</markdown>
</pl-question-panel>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import random; random.seed(111)
from statistics import median
import problem_bank_helpers as pbh

def imports(data):
import random; random.seed(111)
from statistics import median
import problem_bank_helpers as pbh

def generate(data):
data2 = pbh.create_data2()

numbers = sorted(random.randint(1, 100) for _ in range(9))
# store the variables in the dictionary "params"
data2["params"]["numbers"] = numbers

# define correct answers
data2["correct_answers"]["part1_ans"] = median(numbers)

# Update the data object with a new dict
data.update(data2)

# Start code added automatically by problem_bank_scripts

# Convert backticks to code blocks/fences in answer choices.
pbh.backticks_to_code_tags(data2)

# Update data with data2
data.update(data2)

# End code added in by problem bank scripts

def prepare(data):
pass

def parse(data):
pass

def grade(data):
pass

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: Median
topic: Template
author: Gavin Kendal-Freedman
source: original
template_version: 1.4
attribution: standard
partialCredit: true
singleVariant: false
showCorrectAnswer: false
outcomes:
- 6.1.1.0
- 6.1.1.1
difficulty:
- undefined
randomization:
- undefined
taxonomy:
- undefined
span:
- undefined
length:
- undefined
tags:
- unknown
assets: null
part1:
type: integer-input
pl-customizations:
weight: 1
allow-blank: true
label: $n= $
myst:
substitutions:
params_numbers:
- 22
- 25
- 28
- 41
- 51
- 54
- 64
- 79
- 81
---
# {{ params.vars.title }}
Given a list of numbers ${{ params.vars.numbers }}$, what is the `median` of the list?

## Part 1

### Answer Section

Please enter in a numeric value in.

### pl-submission-panel

Everything here will get inserted directly into the pl-submission-panel element at the end of the `question.html`.
Please remove this section if it is not application for this question.

### pl-answer-panel

Everything here will get inserted directly into an pl-answer-panel element at the end of the `question.html`.
Please remove this section if it is not application for this question.

### pl-answer-panel

Everything here will get inserted directly into an pl-answer-panel element at the end of the `question.html`.

## Attribution

Problem is licensed under the [CC-BY-NC-SA 4.0 license](https://creativecommons.org/licenses/by-nc-sa/4.0/).<br> ![The Creative Commons 4.0 license requiring attribution-BY, non-commercial-NC, and share-alike-SA license.](https://raw.githubusercontent.com/firasm/bits/master/by-nc-sa.png)
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
title: Median
topic: Template
author: Gavin Kendal-Freedman
source: original
template_version: 1.4
attribution: standard
partialCredit: true
singleVariant: false
showCorrectAnswer: false
outcomes:
- 6.1.1.0
- 6.1.1.1
difficulty:
- undefined
randomization:
- undefined
taxonomy:
- undefined
span:
- undefined
length:
- undefined
tags:
- unknown
assets:
server:
imports: |
import random; random.seed(111)
from statistics import median
import problem_bank_helpers as pbh
generate: |
data2 = pbh.create_data2()
numbers = sorted(random.randint(1, 100) for _ in range(9))
# store the variables in the dictionary "params"
data2["params"]["numbers"] = numbers
# define correct answers
data2["correct_answers"]["part1_ans"] = median(numbers)
# Update the data object with a new dict
data.update(data2)
prepare: |
pass
parse: |
pass
grade: |
pass
part1:
type: integer-input
pl-customizations:
weight: 1
allow-blank: true
label: $n= $
---
# {{ params.vars.title }}

Given a list of numbers ${{ params.vars.numbers }}$, what is the `median` of the list?

## Part 1


### Answer Section

Please enter in a numeric value in.

### pl-submission-panel

Everything here will get inserted directly into the pl-submission-panel element at the end of the `question.html`.
Please remove this section if it is not application for this question.

### pl-answer-panel

Everything here will get inserted directly into an pl-answer-panel element at the end of the `question.html`.
Please remove this section if it is not application for this question.

### pl-answer-panel

Everything here will get inserted directly into an pl-answer-panel element at the end of the `question.html`.

## Rubric

This should be hidden from students until after the deadline.

## Solution

This should never be revealed to students.

## Comments

These are random comments associated with this question.