// Numbas version: finer_feedback_settings {"name": "Download text file extension", "extensions": ["download-text-file"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Download text file extension", "tags": [], "metadata": {"description": "

This question demonstrates how to use the \"Download a text file\" extension to create a link to download a file containing text created from question variables.

", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "

The \"download a file\" extension makes it easy to provide a text file that the student should download.

\n

It provides a function download_link(filename, content, link_text). If you don't give link_text, the link reads \"Download filename\".

", "advice": "", "rulesets": {}, "extensions": ["download-text-file"], "variables": {"xs": {"name": "xs", "group": "Ungrouped variables", "definition": "repeat(random(1..100),n)", "description": "", "templateType": "anything"}, "ys": {"name": "ys", "group": "Ungrouped variables", "definition": "repeat(random(-200..100#0),n)", "description": "", "templateType": "anything"}, "n": {"name": "n", "group": "Ungrouped variables", "definition": "10", "description": "", "templateType": "anything"}, "letters": {"name": "letters", "group": "Ungrouped variables", "definition": "repeat(random(split(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\",\"\")),n)", "description": "", "templateType": "anything"}, "with_commas": {"name": "with_commas", "group": "Ungrouped variables", "definition": "repeat(random(1..10)+\",\"+random(11..20),n)", "description": "", "templateType": "anything"}, "with_quotes": {"name": "with_quotes", "group": "Ungrouped variables", "definition": "map('\"{x}\"',x,letters)", "description": "", "templateType": "anything"}, "table_x_y_letter": {"name": "table_x_y_letter", "group": "Ungrouped variables", "definition": "table(zip(xs,ys,letters),[\"$X$\",\"$Y$\",\"Letter\"])", "description": "", "templateType": "anything"}, "x_y_letter_csv": {"name": "x_y_letter_csv", "group": "Ungrouped variables", "definition": "csv(zip(xs,ys,letters),[\"X\",\"Y\",\"Letter\"])", "description": "", "templateType": "anything"}, "list_of_dicts": {"name": "list_of_dicts", "group": "Ungrouped variables", "definition": "repeat(\n [\n \"word\": join(repeat(random(split(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\",\"\")),5),\"\"),\n \"frequency\": random(1..99)\n ],\n n\n)", "description": "", "templateType": "anything"}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["n", "xs", "ys", "letters", "with_commas", "with_quotes", "table_x_y_letter", "x_y_letter_csv", "list_of_dicts"], "variable_groups": [], "functions": {}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "information", "useCustomName": true, "customName": "Text files", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

Here's a text file containing the text \"Hello there\": {download_link(\"hi.txt\",\"Hello there\")}.

\n

Here's the same file, but with different link text: {download_link(\"hi.txt\",\"Hello there\",\"Your very own hello file\")}.

\n

And here's a text file containing a list of numbers, one on each line: {download_link(\"numbers.txt\",join(xs,\"\\n\"))}.

"}, {"type": "information", "useCustomName": true, "customName": "CSV files", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

The extension also provides a function csv(rows,headers). rows should be a list of lists of values. headers is an optional list of strings to put above the first row.

\n

Here's a table of data:

\n

{table_x_y_letter}

\n

As a CSV file, it looks like this:

\n
{x_y_letter_csv}
\n

{download_link(\"x-y-a.csv\",x_y_letter_csv)}

\n

Here's a CSV file with commas and quote characters in the entries, that are automatically escaped for you:

\n
{csv(zip(with_commas,with_quotes))}
\n

{download_link(\"with-weird-characters.csv\",csv(zip(with_commas,with_quotes)))}

\n

Or you can give a dictionary, mapping headers to columns:

\n
{csv([\"X\":xs,\"Y\":ys,\"weird data with commas\":with_commas])}
\n

{download_link(\"from-dictionary.csv\",csv([\"X\":xs,\"Y\":ys,\"weird data with commas\":with_commas]))}

\n

Or you can give a list of dictionaries. There's a column for each distinct key in the dictionaries.

\n
{csv(list_of_dicts)}
\n

{download_link(\"from-dictionary.csv\",csv(list_of_dicts))}

"}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "type": "question", "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}