Skip to content

more demo defaults #437

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
43 changes: 27 additions & 16 deletions dp_wizard/shiny/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
from shiny import ui, reactive, Inputs, Outputs, Session

from dp_wizard.utils.argparse_helpers import CLIInfo
from dp_wizard.utils.csv_helper import read_csv_names
from dp_wizard.utils.csv_helper import read_csv_names, name_to_id
from dp_wizard.shiny import (
about_panel,
analysis_panel,
dataset_panel,
results_panel,
feedback_panel,
)
from dp_wizard.utils.code_generators.analyses import histogram


app_ui = ui.page_bootstrap(
Expand Down Expand Up @@ -89,27 +90,37 @@ def _clip(n: float, lower_bound: float, upper_bound: float) -> float:

def make_server_from_cli_info(cli_info: CLIInfo):
def server(input: Inputs, output: Outputs, session: Session): # pragma: no cover
if cli_info.is_demo:
initial_contributions = 10
initial_private_csv_path = Path(__file__).parent.parent / "tmp" / "demo.csv"
demo = cli_info.is_demo

initial_contributions = 1 if not demo else 10
initial_private_csv_path = (
Path() if not demo else Path(__file__).parent.parent / "tmp" / "demo.csv"
)

if demo:
_make_demo_csv(initial_private_csv_path, initial_contributions)
initial_column_names = read_csv_names(Path(initial_private_csv_path))
initial_column_names = read_csv_names(initial_private_csv_path)
demo_col = "grade"
assert (
demo_col in initial_column_names
), f"{demo_col} not in {initial_column_names}"
id = name_to_id(demo_col)
else:
initial_contributions = 1
initial_private_csv_path = ""
initial_column_names = []
id = "typing placeholder: shouldn't be used"

contributions = reactive.value(initial_contributions)
private_csv_path = reactive.value(str(initial_private_csv_path))
column_names = reactive.value(initial_column_names)

contributions = reactive.value(1 if not demo else initial_contributions)
public_csv_path = reactive.value("")
analysis_types = reactive.value({})
lower_bounds = reactive.value({})
upper_bounds = reactive.value({})
bin_counts = reactive.value({})
private_csv_path = reactive.value(
"" if not demo else str(initial_private_csv_path)
)
column_names = reactive.value(initial_column_names)
analysis_types = reactive.value({} if not demo else {id: histogram.name})
lower_bounds = reactive.value({} if not demo else {id: 0.0})
upper_bounds = reactive.value({} if not demo else {id: 100.0})
bin_counts = reactive.value({} if not demo else {id: 10})
groups = reactive.value([])
weights = reactive.value({})
weights = reactive.value({} if not demo else {id: str(1)})
epsilon = reactive.value(1.0)
released = reactive.value(False)

Expand Down
2 changes: 1 addition & 1 deletion dp_wizard/shiny/results_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def button(

def _strip_ansi(e):
"""
>>> e = Exception('\x1B[0;31mValueError\x1B[0m: ...')
>>> e = Exception('\x1b[0;31mValueError\x1b[0m: ...')
>>> _strip_ansi(e)
'ValueError: ...'
"""
Expand Down
Loading