-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Text (yaml) report for download (#181)
* pyyaml dep * stub reports block * fix flakey test of weight * half-way there! * add confidence and accuracy * stub inputs * csv_path * generate report and drop in tmp * text report download works * "please wait" * test each download * use original column names in our report * CSV report (#182) * use original column names in our report * flatten util * checkpoint on CSV report; tests not passing * csv report works * add a test * button grid * factor out button function * update test to match * add epsilon to report * remove params when we can just get it from self * Add column info to report
- Loading branch information
Showing
10 changed files
with
218 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
demo.csv | ||
report.txt | ||
report.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,9 @@ | |
# + | ||
QUERIES_BLOCK | ||
# - | ||
|
||
# The code below produces a summary report. | ||
|
||
# + | ||
REPORTS_BLOCK | ||
# - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
NAME: { | ||
"histogram": dict(zip(*df_to_columns(IDENTIFIER_HISTOGRAM))), | ||
"accuracy": IDENTIFIER_ACCURACY, | ||
"confidence": CONFIDENCE, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from yaml import dump | ||
from pathlib import Path | ||
import csv | ||
|
||
|
||
# https://stackoverflow.com/a/6027615/10727889 | ||
def flatten_dict(dictionary, parent_key=""): | ||
""" | ||
Walk tree to return flat dictionary. | ||
>>> from pprint import pp | ||
>>> pp(flatten_dict({ | ||
... "inputs": { | ||
... "data": "fake.csv" | ||
... }, | ||
... "outputs": { | ||
... "a column": { | ||
... "(0, 1]": 24, | ||
... "(1, 2]": 42, | ||
... } | ||
... } | ||
... })) | ||
{'inputs: data': 'fake.csv', | ||
'outputs: a column: (0, 1]': 24, | ||
'outputs: a column: (1, 2]': 42} | ||
""" | ||
separator = ": " | ||
items = [] | ||
for key, value in dictionary.items(): | ||
new_key = parent_key + separator + key if parent_key else key | ||
if isinstance(value, dict): | ||
items.extend(flatten_dict(value, new_key).items()) | ||
else: | ||
items.append((new_key, value)) | ||
return dict(items) | ||
|
||
|
||
report = { | ||
"inputs": { | ||
"data": CSV_PATH, | ||
"epsilon": EPSILON, | ||
"columns": COLUMNS, | ||
}, | ||
"outputs": OUTPUTS, | ||
} | ||
|
||
print(dump(report)) | ||
Path(TXT_REPORT_PATH).write_text(dump(report)) | ||
|
||
flat_report = flatten_dict(report) | ||
with Path(CSV_REPORT_PATH).open(mode="w", newline="") as handle: | ||
writer = csv.writer(handle) | ||
for kv_pair in flat_report.items(): | ||
writer.writerow(kv_pair) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ dependencies = [ | |
"jupyter-client", | ||
"nbconvert", | ||
"ipykernel", | ||
"pyyaml", | ||
] | ||
|
||
[project.scripts] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ scipy<1.14 | |
# Conversion: | ||
jupytext | ||
jupyter-client | ||
pyyaml | ||
nbconvert | ||
ipykernel | ||
# May also require: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters