-
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.
Merge pull request #34 from smart-on-fhir/mikix/info
feat: add `info` subcommand to show computed ranges & labels
- Loading branch information
Showing
11 changed files
with
230 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""Chart Review public entry point""" | ||
|
||
__version__ = "1.1.0" | ||
__version__ = "1.2.0" |
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
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,64 @@ | ||
"""Methods for showing config & calculated setup info.""" | ||
|
||
import rich | ||
import rich.box | ||
import rich.table | ||
|
||
from chart_review import cohort | ||
|
||
|
||
def info(reader: cohort.CohortReader) -> None: | ||
""" | ||
Show project information on the console. | ||
:param reader: the cohort configuration | ||
""" | ||
console = rich.get_console() | ||
|
||
# Charts | ||
chart_table = rich.table.Table( | ||
"Annotator", | ||
"Chart Count", | ||
"Chart IDs", | ||
box=rich.box.ROUNDED, | ||
pad_edge=False, | ||
title="Annotations:", | ||
title_justify="left", | ||
title_style="bold", | ||
) | ||
for annotator in sorted(reader.note_range): | ||
notes = reader.note_range[annotator] | ||
chart_table.add_row(annotator, str(len(notes)), pretty_note_range(notes)) | ||
console.print(chart_table) | ||
console.print() | ||
|
||
# Labels | ||
console.print("Labels:", style="bold") | ||
if reader.class_labels: | ||
console.print(", ".join(sorted(reader.class_labels, key=str.casefold))) | ||
else: | ||
console.print("None", style="italic", highlight=False) | ||
|
||
|
||
def pretty_note_range(notes: set[int]) -> str: | ||
ranges = [] | ||
range_start = None | ||
prev_note = None | ||
|
||
def end_range() -> None: | ||
if prev_note is None: | ||
return | ||
if range_start == prev_note: | ||
ranges.append(str(prev_note)) | ||
else: | ||
ranges.append(f"{range_start}–{prev_note}") # en dash | ||
|
||
for note in sorted(notes): | ||
if prev_note is None or prev_note + 1 != note: | ||
end_range() | ||
range_start = note | ||
prev_note = note | ||
|
||
end_range() | ||
|
||
return ", ".join(ranges) |
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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: Info Command | ||
parent: Chart Review | ||
nav_order: 6 | ||
# audience: lightly technical folks | ||
# type: how-to | ||
--- | ||
|
||
# The Info Command | ||
|
||
The `info` command will print information about your current project. | ||
|
||
This is helpful to examine the computed list of chart ID ranges or labels. | ||
|
||
## Example | ||
|
||
```shell | ||
$ chart-review info | ||
Annotations: | ||
╭──────────┬─────────────┬──────────╮ | ||
│Annotator │ Chart Count │ Chart IDs│ | ||
├──────────┼─────────────┼──────────┤ | ||
│jane │ 3 │ 1, 3–4 │ | ||
│jill │ 4 │ 1–4 │ | ||
│john │ 3 │ 1–2, 4 │ | ||
╰──────────┴─────────────┴──────────╯ | ||
|
||
Labels: | ||
Cough, Fatigue, Headache | ||
``` | ||
|
||
## Options | ||
|
||
### `--config=PATH` | ||
|
||
Use this to point to a secondary (non-default) config file. | ||
Useful if you have multiple label setups (e.g. one grouped into a binary label and one not). | ||
|
||
### `--project-dir=DIR` | ||
|
||
Use this to run `chart-review` outside of your project dir. | ||
Config files, external annotations, etc will be looked for in that directory. |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Tests for cohort.py""" | ||
|
||
import os | ||
import tempfile | ||
import unittest | ||
|
||
from chart_review import cohort, common, config | ||
|
||
DATA_DIR = os.path.join(os.path.dirname(__file__), "data") | ||
|
||
|
||
class TestCohort(unittest.TestCase): | ||
"""Test case for basic cohort management""" | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.maxDiff = None | ||
|
||
def test_ignored_ids(self): | ||
reader = cohort.CohortReader(config.ProjectConfig(f"{DATA_DIR}/ignore")) | ||
|
||
# Confirm 3, 4, and 5 got ignored | ||
self.assertEqual( | ||
{ | ||
"adam": {1, 2}, | ||
"allison": {1, 2}, | ||
}, | ||
reader.note_range, | ||
) | ||
|
||
def test_non_existent_ids(self): | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
common.write_json( | ||
f"{tmpdir}/config.json", {"annotators": {"bob": 1}, "ranges": {"bob": ["1-5"]}} | ||
) | ||
common.write_json( | ||
f"{tmpdir}/labelstudio-export.json", | ||
[ | ||
{"id": 1, "annotations": [{"completed_by": 1}]}, # done by bob | ||
{"id": 3}, # not done by bob, but we are explicitly told it was | ||
], | ||
) | ||
reader = cohort.CohortReader(config.ProjectConfig(tmpdir)) | ||
|
||
self.assertEqual({"bob": {1, 3}}, reader.note_range) |
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