Skip to content
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

Widget to customize number of seeds to generate #79

Open
wants to merge 5 commits 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
2 changes: 1 addition & 1 deletion dashboard/checkit/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '0.2.6'
VERSION = '0.2.7'
10 changes: 6 additions & 4 deletions dashboard/checkit/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def outcome_submenu(bank):
seed_button = widgets.Button(description="View random seed")
build_button = widgets.Button(description="Generate seeds")
images_button = widgets.Button(description="Gen seeds+graphics")
amount_box = widgets.IntText(value = 1000)
description = modifiedOutput()
generated = modifiedOutput()
output = modifiedOutput()
Expand Down Expand Up @@ -91,9 +92,9 @@ def build(*args):
o = outcomes_dropdown.value
output.clear_output()
with output:
display(Markdown("Generating 1,000 seeds..."))
display(Markdown(f"Generating {amount_box.value} seeds..."))
with output:
o.generate_exercises(regenerate=True)
o.generate_exercises(amount=amount_box.value,regenerate=True)
reset(only_generated=True)
with output:
display(Markdown("Done!"))
Expand All @@ -102,9 +103,9 @@ def images(*args):
o = outcomes_dropdown.value
output.clear_output()
with output:
display(Markdown("Generating 1,000 seeds with graphics... (this can take some time)"))
display(Markdown(f"Generating {amount_box.value} seeds with graphics... (this can take some time)"))
with output:
o.generate_exercises(regenerate=True,images=True)
o.generate_exercises(amount=amount_box.value,regenerate=True,images=True)
reset(only_generated=True)
with output:
display(Markdown("Done!"))
Expand All @@ -117,6 +118,7 @@ def images(*args):

display(outcomes_dropdown)
display(widgets.HBox([preview_button,seed_button,build_button,images_button]))
display(widgets.HBox([widgets.Label(value="Generate how many seeds? "), amount_box]))
display(description)
display(generated)
display(output)
Expand Down
5 changes: 3 additions & 2 deletions dashboard/checkit/outcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def to_dict(self,regenerate=False):

def preview_exercises(self):
preview_json = os.path.join(self.build_path(),"preview.json")
# hardcode: previews generate 10 seeds
sage(self,preview_json,preview=True,images=True)
with open(os.path.join(preview_json)) as f:
data = json.load(f)['seeds']
Expand Down Expand Up @@ -96,14 +97,14 @@ def build_path(self):
def seeds_json_path(self):
return os.path.join(self.build_path(),"seeds.json")

def generate_exercises(self,regenerate=False,images=False):
def generate_exercises(self,amount=1000,regenerate=False,images=False):
if not regenerate:
try:
self.load_exercises()
return
except RuntimeError:
pass # generation is necessary
sage(self,self.seeds_json_path(),preview=False,images=images)
sage(self,self.seeds_json_path(),amount=amount,preview=False,images=images)
self.load_exercises(reload=True)


Expand Down
13 changes: 7 additions & 6 deletions dashboard/checkit/wrapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import subprocess, os, tempfile, shutil
from ..utils import working_directory

def sage(outcome,output_path,preview=True,images=False):
def sage(outcome,output_path,amount=1000,preview=True,images=False):
"""
Wraps generator and builds to a seeds.json file at output_path
"""
Expand All @@ -18,11 +18,12 @@ def sage(outcome,output_path,preview=True,images=False):
with working_directory(outcome.bank.abspath()):
cmds = [
"sage",
os.path.join(tmpdir,"wrapper.sage"),
outcome.generator_path(),
output_path,
preview_s,
os.path.join(tmpdir,"wrapper.sage"), #arg index 0
outcome.generator_path(), #1
output_path, #2
preview_s, #3
str(amount), #4
]
if images:
cmds += ["images"]
cmds += ["images"] #5
subprocess.run(cmds,check=True)
8 changes: 4 additions & 4 deletions dashboard/checkit/wrapper/wrapper.sage
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ def json_ready(obj):
else:
return str(latex(obj))

# sage /path/to/wrapper.sage /path/to/generator.sage /path/to/output/seeds.json preview|build images?
if len(sys.argv) >= 4:
# sage /path/to/wrapper.sage /path/to/generator.sage /path/to/output/seeds.json preview|build amount images?
if len(sys.argv) >= 5:
# this script should be called from the root directory of the bank
# so loads in the generator file work as intended
generator_path = sys.argv[1]
Expand All @@ -206,15 +206,15 @@ if len(sys.argv) >= 4:
if sys.argv[3].lower() == "preview":
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we ignore the amount if we're set to "preview". So I think it's better to simply omit the amount=10 earlier as it's misleading (it will use the default 1000 instead, but that's happily ignored here).

OR previews could support variable #s of seeds (maybe you really want to preview just 1 seed, or 100). But that's more work for minimal benefit?

amount = 10
else:
amount = 1_000
amount = Integer(sys.argv[4])
seeds = []
for i in range(amount):
if sys.argv[3].lower() == "preview":
set_random_seed()
seed_int = int(randrange(1_000))
else:
seed_int = int(i)
gen_images = (len(sys.argv) >= 5 and sys.argv[4]=="images")
gen_images = (len(sys.argv) >= 6 and sys.argv[5]=="images")
generator.roll_data(seed=seed_int)
seed = {"seed":seed_int,"data":json_ready(generator.get_data())}
if gen_images:
Expand Down