Skip to content

Commit

Permalink
reverting to unique carton counts
Browse files Browse the repository at this point in the history
  • Loading branch information
nrminor committed Oct 21, 2024
1 parent 9f2671f commit 5a20602
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
22 changes: 1 addition & 21 deletions assets/positivity_tally.tsv
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
Processing Plant State Total Cartons Negative Cartons Positive Cartons Latest Date Sampled
CA 1 1 0 2024-05-20
CO 24 10 14 2024-10-07
FL 1 1 0 2024-05-20
IA 10 10 0 2024-07-30
ID 1 1 0 2024-05-20
IL 3 3 0 2024-06-17
IN 6 5 1 2024-07-02
KS 2 2 0 2024-07-02
KY 6 3 3 2024-07-02
MI 31 5 26 2024-10-07
MN 6 6 0 2024-07-02
MO 4 2 2 2024-09-10
NC 2 2 0 2024-09-24
NY 6 4 2 2024-09-24
OH 5 5 0 2024-07-28
OR 1 1 0 2024-05-20
TX 3 1 2 2024-06-05
UT 1 1 0 2024-05-02
VA 2 2 0 2024-07-02
WI 104 93 11 2024-10-07

21 changes: 11 additions & 10 deletions scripts/positivity_tally.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3

"""
This script processes detection results for HPAI (Highly Pathogenic Avian Influenza) and generates a summary report.
This script processes detection results for HPAI (Highly Pathogenic Avian Influenza)
and generates a summary report.
Usage:
python positivity_tally.py <input_file> <output_file>
Expand All @@ -20,9 +21,9 @@
Output:
The script will generate a TSV file with the following columns:
- Processing Plant State: State where the processing plant is located
- Total Cartons: Total number of cartons tested
- Positive Cartons: Number of cartons that tested positive for HPAI
- Negative Cartons: Number of cartons that tested negative for HPAI
- Total Cartons: Total number of unique cartons tested
- Positive Cartons: Number of unique cartons that tested positive for HPAI
- Negative Cartons: Number of unique cartons that tested negative for HPAI
- Latest Date Sampled: Most recent date when samples were taken for each state
Required libraries:
Expand Down Expand Up @@ -64,7 +65,7 @@ def tally_all_cartons(detections: pl.LazyFrame) -> pl.LazyFrame:
"""
Tally all cartons in the detection results.
This function counts the total number of cartons for each processing plant state.
This function counts the total number of unique cartons for each processing plant state.
Args:
detections (pl.LazyFrame): A LazyFrame containing the detection results.
Expand All @@ -75,7 +76,7 @@ def tally_all_cartons(detections: pl.LazyFrame) -> pl.LazyFrame:
return (
detections.select("Processing Plant State", "carton")
.group_by("Processing Plant State")
.len()
.n_unique()
.rename({"len": "Total Cartons"})
)

Expand All @@ -85,7 +86,7 @@ def count_positive_detections(detections: pl.LazyFrame) -> pl.LazyFrame:
Count the number of positive HPAI detections for each processing plant state.
This function filters the detections for positive HPAI results,
counts the number of positive cartons for each state, and renames
counts the number of unique positive cartons for each state, and renames
the resulting column.
Args:
Expand All @@ -98,7 +99,7 @@ def count_positive_detections(detections: pl.LazyFrame) -> pl.LazyFrame:
detections.filter(pl.col("positive_for_HPAI").eq(True)) # noqa: FBT003
.select("Processing Plant State", "carton")
.group_by("Processing Plant State")
.len() # this should be changed to `.n_unique()` for unique cartons only
.n_unique() # this should be changed to `.n_unique()` for unique cartons only
.rename({"len": "Positive Cartons"})
)

Expand All @@ -108,7 +109,7 @@ def count_negative_detections(detections: pl.LazyFrame) -> pl.LazyFrame:
Count the number of negative HPAI detections for each processing plant state.
This function filters the detections for negative HPAI results,
counts the number of negative cartons for each state, and renames
counts the number of unique negative cartons for each state, and renames
the resulting column.
Args:
Expand All @@ -121,7 +122,7 @@ def count_negative_detections(detections: pl.LazyFrame) -> pl.LazyFrame:
detections.filter(pl.col("positive_for_HPAI").eq(False)) # noqa: FBT003
.select("Processing Plant State", "carton")
.group_by("Processing Plant State")
.len() # this should be changed to `.n_unique()` for unique cartons only
.n_unique() # this should be changed to `.n_unique()` for unique cartons only
.rename({"len": "Negative Cartons"})
)

Expand Down

0 comments on commit 5a20602

Please sign in to comment.