Skip to content

Commit

Permalink
clean up dataset page, and move half-baked to analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
mccalluc committed Oct 16, 2024
1 parent b98acd9 commit 02c4ec9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
24 changes: 24 additions & 0 deletions dp_creator_ii/app/analysis_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from dp_creator_ii.mock_data import mock_data, ColumnDef
from dp_creator_ii.app.plots import plot_error_bars_with_cutoff
from dp_creator_ii.csv_helper import read_field_names


def analysis_ui():
Expand All @@ -13,10 +14,12 @@ def analysis_ui():
"the number of bins for the histogram, "
"and its relative share of the privacy budget."
),
ui.output_text("csv_name"),
ui.markdown(
"[TODO: Column selection]"
"(https://github.com/opendp/dp-creator-ii/issues/33)"
),
ui.output_text("csv_fields"),
ui.markdown(
"What is your privacy budget for this release? "
"Values above 1 will add less noise to the data, "
Expand All @@ -39,6 +42,27 @@ def analysis_ui():


def analysis_server(input, output, session):
@reactive.calc
def csv_name_calc():
csv_path_from_ui = input.csv_path_from_ui()
if csv_path_from_ui is not None:
return csv_path_from_ui[0]["datapath"]

@render.text
def csv_name():
return csv_name_calc()

@reactive.calc
def csv_fields_calc():
csv_path_from_ui = input.csv_path_from_ui()
if csv_path_from_ui is None:
return None
return read_field_names(csv_path_from_ui[0]["datapath"])

@render.text
def csv_fields():
return csv_fields_calc()

@render.plot()
def plot_preview():
min_x = 0
Expand Down
30 changes: 1 addition & 29 deletions dp_creator_ii/app/dataset_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from shiny import ui, reactive, render

from dp_creator_ii import get_arg_parser
from dp_creator_ii.csv_helper import read_field_names
from dp_creator_ii.app.ui_helpers import output_code_sample
from dp_creator_ii.template import make_privacy_unit_block

Expand All @@ -24,16 +23,11 @@ def dataset_ui():

return ui.nav_panel(
"Select Dataset",
"TODO: Pick dataset",
ui.input_file("csv_path_from_ui", "Choose CSV file", accept=[".csv"]),
"CSV path from either CLI or UI:",
ui.output_text("csv_path"),
"CSV fields:",
ui.input_file("csv_path_from_ui", "Choose CSV file:", accept=[".csv"]),
ui.markdown(
"How many rows of the CSV can one individual contribute to? "
'This is the "unit of privacy" which will be protected.'
),
ui.output_text("csv_fields"),
ui.input_numeric("contributions", "Contributions", args.contributions),
output_code_sample("unit_of_privacy_python"),
ui.input_action_button("go_to_analysis", "Define analysis"),
Expand All @@ -46,28 +40,6 @@ def dataset_server(input, output, session):

csv_path_from_cli_value = reactive.value(args.csv_path)

@reactive.calc
def csv_path_calc():
csv_path_from_ui = input.csv_path_from_ui()
if csv_path_from_ui is not None:
return csv_path_from_ui[0]["datapath"]
return csv_path_from_cli_value.get()

@render.text
def csv_path():
return csv_path_calc()

@reactive.calc
def csv_fields_calc():
path = csv_path_calc()
if path is None:
return None
return read_field_names(path)

@render.text
def csv_fields():
return csv_fields_calc()

@render.code
def unit_of_privacy_python():
contributions = input.contributions()
Expand Down

0 comments on commit 02c4ec9

Please sign in to comment.