From 42cbded06324bb1bd7569f6573129278b3ec44c8 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sat, 21 Nov 2020 08:51:30 +0100 Subject: [PATCH 1/3] support worksheets with multiple tasks in them --- README.md | 13 ++++++++++++- mathgenerator/mathgen.py | 30 ++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 908fe47..5e09e7a 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,19 @@ problem, solution = mathgen.genById(0) `genById(id)` generates a problem, solution set with generator id `id` in the form of a list in the format `[problem, solution]` -`makePdf(id, count)` creates a printable pdf worksheet with `count` problems generated by the generator with id `id`. +`make_pdf(id, count)` creates a printable pdf worksheet with `count` problems generated by the generator with id `id`. +### More complicated worksheets + +``` +import sys +from mathgenerator import mathgen + +worksheet = mathgen.make_worksheet("2020-11-29") +mathgen.add_section_with_task_to_worksheet(worksheet, 105, 5) +mathgen.add_section_with_task_to_worksheet(worksheet, 2, 5) +mathgen.write_pdf(worksheet) +``` ## List of Generators diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index d583ce0..1e699b8 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -11,10 +11,28 @@ def genById(id): return (generator()) -def makePdf(id, count): - generator = genList[id][2] - title = genList[id][1] - ws = Worksheet(title=title) +def make_worksheet(title): + return Worksheet(title=title) + + +def write_pdf(worksheet): + worksheet.write_pdf() + +def add_section_title(worksheet, task_id): + title = genList[task_id][1] + worksheet.add_instruction(title) + +def add_task_to_worksheet(worksheet, task_id, count): + generator = genList[task_id][2] for i in range(count): - ws.add_problem(generator()[0]) - ws.write_pdf() + worksheet.add_problem(generator()[0]) + +def add_section_with_task_to_worksheet(worksheet, task_id, count): + add_section_title(worksheet, task_id) + add_task_to_worksheet(worksheet, task_id, count) + +def make_pdf(task_id, count): + title = genList[task_id][1] + worksheet = make_worksheet(title) + add_task_to_worksheet(worksheet, task_id, count) + write_pdf(worksheet) From 17d2772549033fade74c436ce479e5ce1712abcc Mon Sep 17 00:00:00 2001 From: Luke Weiler Date: Sat, 21 Nov 2020 10:19:59 -0500 Subject: [PATCH 2/3] Lint fix --- mathgenerator/mathgen.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 1e699b8..594795e 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -18,19 +18,23 @@ def make_worksheet(title): def write_pdf(worksheet): worksheet.write_pdf() + def add_section_title(worksheet, task_id): title = genList[task_id][1] worksheet.add_instruction(title) + def add_task_to_worksheet(worksheet, task_id, count): generator = genList[task_id][2] for i in range(count): worksheet.add_problem(generator()[0]) + def add_section_with_task_to_worksheet(worksheet, task_id, count): add_section_title(worksheet, task_id) add_task_to_worksheet(worksheet, task_id, count) + def make_pdf(task_id, count): title = genList[task_id][1] worksheet = make_worksheet(title) From c7c5a0acf87ba9ad9fd035ea4b65577fc55504b4 Mon Sep 17 00:00:00 2001 From: Luke Weiler Date: Sat, 21 Nov 2020 10:22:31 -0500 Subject: [PATCH 3/3] Linter fix 2 --- mathgenerator/mathgen.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 594795e..af26ac4 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -18,23 +18,23 @@ def make_worksheet(title): def write_pdf(worksheet): worksheet.write_pdf() - + def add_section_title(worksheet, task_id): title = genList[task_id][1] worksheet.add_instruction(title) - + def add_task_to_worksheet(worksheet, task_id, count): generator = genList[task_id][2] for i in range(count): worksheet.add_problem(generator()[0]) - + def add_section_with_task_to_worksheet(worksheet, task_id, count): add_section_title(worksheet, task_id) add_task_to_worksheet(worksheet, task_id, count) - + def make_pdf(task_id, count): title = genList[task_id][1] worksheet = make_worksheet(title)