dairy-data-tools 0.2.4__tar.gz → 0.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/CITATION.cff +2 -2
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/PKG-INFO +12 -3
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/README.md +11 -2
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/plugins/dairy-data-tools/README.md +4 -2
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/pyproject.toml +1 -1
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/tools/dairyread.py +88 -155
- dairy_data_tools-0.3.2/tools/dairytools/__init__.py +106 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/tools/dairytools/cards.py +205 -27
- dairy_data_tools-0.3.2/tools/dairytools/cli.py +586 -0
- dairy_data_tools-0.3.2/tools/dairytools/cowcard.py +537 -0
- dairy_data_tools-0.3.2/tools/dairytools/ecosystem.py +200 -0
- dairy_data_tools-0.3.2/tools/dairytools/epi.py +1163 -0
- dairy_data_tools-0.3.2/tools/dairytools/errors.py +23 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/tools/dairytools/explorer.py +42 -27
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/tools/dairytools/feeding.py +9 -15
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/tools/dairytools/herd.py +251 -50
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/tools/dairytools/io.py +154 -78
- dairy_data_tools-0.3.2/tools/dairytools/models.py +261 -0
- dairy_data_tools-0.3.2/tools/dairytools/py.typed +0 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/tools/dairytools/reference.py +7 -0
- dairy_data_tools-0.3.2/tools/dairytools/repro.py +1010 -0
- dairy_data_tools-0.3.2/tools/dairytools/stats.py +555 -0
- dairy_data_tools-0.3.2/tools/dairytools/udder.py +384 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/tools/dairytools/weekly.py +107 -104
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/tools/dairytools/weeklycard.py +45 -17
- dairy_data_tools-0.2.4/tools/dairytools/__init__.py +0 -10
- dairy_data_tools-0.2.4/tools/dairytools/cli.py +0 -251
- dairy_data_tools-0.2.4/tools/dairytools/cowcard.py +0 -233
- dairy_data_tools-0.2.4/tools/dairytools/stats.py +0 -63
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/.gitignore +0 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/LICENSE +0 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/LICENSE-skills.md +0 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/NOTICE +0 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/plugins/dairy-data-tools/LICENSE +0 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/plugins/dairy-data-tools/LICENSE-skills.md +0 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/plugins/dairy-data-tools/NOTICE +0 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/plugins/dairy-data-tools/sample-herd/README.md +0 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/tools/dairytools/commands.py +0 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/tools/dairytools/data/NOTICE-nasem.md +0 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/tools/dairytools/data/nasem_feeds.csv +0 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/tools/dairytools/nutrients.py +0 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/tools/pen_milk.py +0 -0
- {dairy_data_tools-0.2.4 → dairy_data_tools-0.3.2}/tools/ration_change.py +0 -0
|
@@ -11,9 +11,9 @@ authors:
|
|
|
11
11
|
- family-names: Lucey
|
|
12
12
|
given-names: Pádraig
|
|
13
13
|
orcid: "https://orcid.org/0000-0003-3885-2439"
|
|
14
|
-
version: 0.2
|
|
14
|
+
version: 0.3.2
|
|
15
15
|
doi: 10.5281/zenodo.23493936
|
|
16
|
-
date-released: 2026-
|
|
16
|
+
date-released: 2026-11-29
|
|
17
17
|
license: Apache-2.0
|
|
18
18
|
repository-code: "https://github.com/padge01/dairy-data-tools"
|
|
19
19
|
keywords:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: dairy-data-tools
|
|
3
|
-
Version: 0.2
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Read a dairy farm's DairyComp and EZfeed exports: the herd, each pen and cow, pen cows joined to pen feed, a weekly or visit review, and a ration change with the season taken out.
|
|
5
5
|
Project-URL: Homepage, https://github.com/padge01/dairy-data-tools
|
|
6
6
|
Project-URL: Issues, https://github.com/padge01/dairy-data-tools/issues
|
|
@@ -95,8 +95,10 @@ Save the exports every day or every month and the cards join them into each pen'
|
|
|
95
95
|
| Where | How |
|
|
96
96
|
| --- | --- |
|
|
97
97
|
| **Claude Code** | `claude plugin marketplace add padge01/dairy-data-tools`, then `claude plugin install dairy-data-tools@dairy-data-tools` |
|
|
98
|
-
| **Codex, Cursor, Gemini CLI** and other apps that read Agent Skills |
|
|
99
|
-
| **Python, no AI** (Python 3.10 or later, nothing else
|
|
98
|
+
| **Codex, Cursor, Gemini CLI** and other apps that read Agent Skills | Add the skills in this repository the way your app adds Agent Skills |
|
|
99
|
+
| **Python, no AI** (Python 3.10 or later, nothing else needed) | The same code is the [dairy-data-tools package on PyPI](https://pypi.org/project/dairy-data-tools/). With it on your computer: `dairy-data-tools pen --folder "Farm Exports" --pen 21`; `dairy-data-tools --help` lists every question |
|
|
100
|
+
|
|
101
|
+
The commands for the last two are in [the repository's README](https://github.com/padge01/dairy-data-tools#from-the-command-line).
|
|
100
102
|
|
|
101
103
|
## What's in it
|
|
102
104
|
|
|
@@ -148,6 +150,13 @@ Code under Apache-2.0 (`LICENSE`); the skills' text under CC BY 4.0 (`LICENSE-sk
|
|
|
148
150
|
keep NASEM's own terms (see `NOTICE`). Questions and fixes:
|
|
149
151
|
[issues](https://github.com/padge01/dairy-data-tools/issues).
|
|
150
152
|
|
|
153
|
+
## From the command line
|
|
154
|
+
|
|
155
|
+
| Where | Command |
|
|
156
|
+
| --- | --- |
|
|
157
|
+
| **Codex, Cursor, Gemini CLI** and other apps that read Agent Skills | `npx skills add padge01/dairy-data-tools` |
|
|
158
|
+
| **Python, no AI** | `pip install dairy-data-tools` |
|
|
159
|
+
|
|
151
160
|
## Working on it
|
|
152
161
|
|
|
153
162
|
- `plugins/dairy-data-tools/`: the plugin people install (skills, sample herd, README, licences).
|
|
@@ -76,8 +76,10 @@ Save the exports every day or every month and the cards join them into each pen'
|
|
|
76
76
|
| Where | How |
|
|
77
77
|
| --- | --- |
|
|
78
78
|
| **Claude Code** | `claude plugin marketplace add padge01/dairy-data-tools`, then `claude plugin install dairy-data-tools@dairy-data-tools` |
|
|
79
|
-
| **Codex, Cursor, Gemini CLI** and other apps that read Agent Skills |
|
|
80
|
-
| **Python, no AI** (Python 3.10 or later, nothing else
|
|
79
|
+
| **Codex, Cursor, Gemini CLI** and other apps that read Agent Skills | Add the skills in this repository the way your app adds Agent Skills |
|
|
80
|
+
| **Python, no AI** (Python 3.10 or later, nothing else needed) | The same code is the [dairy-data-tools package on PyPI](https://pypi.org/project/dairy-data-tools/). With it on your computer: `dairy-data-tools pen --folder "Farm Exports" --pen 21`; `dairy-data-tools --help` lists every question |
|
|
81
|
+
|
|
82
|
+
The commands for the last two are in [the repository's README](https://github.com/padge01/dairy-data-tools#from-the-command-line).
|
|
81
83
|
|
|
82
84
|
## What's in it
|
|
83
85
|
|
|
@@ -129,6 +131,13 @@ Code under Apache-2.0 (`LICENSE`); the skills' text under CC BY 4.0 (`LICENSE-sk
|
|
|
129
131
|
keep NASEM's own terms (see `NOTICE`). Questions and fixes:
|
|
130
132
|
[issues](https://github.com/padge01/dairy-data-tools/issues).
|
|
131
133
|
|
|
134
|
+
## From the command line
|
|
135
|
+
|
|
136
|
+
| Where | Command |
|
|
137
|
+
| --- | --- |
|
|
138
|
+
| **Codex, Cursor, Gemini CLI** and other apps that read Agent Skills | `npx skills add padge01/dairy-data-tools` |
|
|
139
|
+
| **Python, no AI** | `pip install dairy-data-tools` |
|
|
140
|
+
|
|
132
141
|
## Working on it
|
|
133
142
|
|
|
134
143
|
- `plugins/dairy-data-tools/`: the plugin people install (skills, sample herd, README, licences).
|
|
@@ -76,8 +76,10 @@ Save the exports every day or every month and the cards join them into each pen'
|
|
|
76
76
|
| Where | How |
|
|
77
77
|
| --- | --- |
|
|
78
78
|
| **Claude Code** | `claude plugin marketplace add padge01/dairy-data-tools`, then `claude plugin install dairy-data-tools@dairy-data-tools` |
|
|
79
|
-
| **Codex, Cursor, Gemini CLI** and other apps that read Agent Skills |
|
|
80
|
-
| **Python, no AI** (Python 3.10 or later, nothing else
|
|
79
|
+
| **Codex, Cursor, Gemini CLI** and other apps that read Agent Skills | Add the skills in this repository the way your app adds Agent Skills |
|
|
80
|
+
| **Python, no AI** (Python 3.10 or later, nothing else needed) | The same code is the [dairy-data-tools package on PyPI](https://pypi.org/project/dairy-data-tools/). With it on your computer: `dairy-data-tools pen --folder "Farm Exports" --pen 21`; `dairy-data-tools --help` lists every question |
|
|
81
|
+
|
|
82
|
+
The commands for the last two are in [the repository's README](https://github.com/padge01/dairy-data-tools#from-the-command-line).
|
|
81
83
|
|
|
82
84
|
## What's in it
|
|
83
85
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "dairy-data-tools"
|
|
3
|
-
version = "0.2
|
|
3
|
+
version = "0.3.2"
|
|
4
4
|
description = "Read a dairy farm's DairyComp and EZfeed exports: the herd, each pen and cow, pen cows joined to pen feed, a weekly or visit review, and a ration change with the season taken out."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "Apache-2.0"
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"""Read DairyComp and EZfeed export files. Python standard library only, read-only, no network.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Thin compatibility facade delegating DairyComp and EZfeed parsing to `dairytools.io` and statistics to
|
|
4
|
+
`dairytools.stats`, so export parsing lives in one place while `ration_change.py`, `pen_milk.py`,
|
|
5
|
+
`tools/sync_scripts.py`, and PyPI CLI entrypoints keep working identically.
|
|
5
6
|
|
|
6
7
|
Farm notes are untrusted text: event remarks, protocols and technician names are left out unless asked for, because a
|
|
7
8
|
remark can carry words that read like instructions to an AI agent.
|
|
@@ -9,59 +10,27 @@ remark can carry words that read like instructions to an AI agent.
|
|
|
9
10
|
|
|
10
11
|
from __future__ import annotations
|
|
11
12
|
|
|
12
|
-
import csv
|
|
13
|
-
import io
|
|
14
|
-
import math
|
|
15
13
|
import re
|
|
14
|
+
import sys
|
|
16
15
|
from dataclasses import dataclass, field
|
|
17
|
-
from datetime import date
|
|
16
|
+
from datetime import date
|
|
18
17
|
from pathlib import Path
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
try: # inside the installed package (dairytools.dairyread)
|
|
20
|
+
from . import io as _io
|
|
21
|
+
from . import stats as _stats
|
|
22
|
+
except ImportError: # run from tools/ or a skill's scripts/ folder
|
|
23
|
+
_here = str(Path(__file__).resolve().parent)
|
|
24
|
+
if _here not in sys.path:
|
|
25
|
+
sys.path.insert(0, _here)
|
|
26
|
+
from dairytools import io as _io # noqa: E402
|
|
27
|
+
from dairytools import stats as _stats # noqa: E402
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return raw.decode(encoding)
|
|
28
|
-
except UnicodeDecodeError:
|
|
29
|
-
continue
|
|
30
|
-
return raw.decode("latin-1", errors="replace")
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def rows_of(path: str | Path) -> list[list[str]]:
|
|
34
|
-
text = read_text(path)
|
|
35
|
-
return [[cell.strip() for cell in row] for row in csv.reader(io.StringIO(text))]
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def number(value: str | None) -> float | None:
|
|
39
|
-
"""'1,234.5', '$6.84', '57.94%', ' 77.1 ', '(1.20)' -> float (EZfeed shows negatives in brackets);
|
|
40
|
-
blank or text -> None."""
|
|
41
|
-
if value is None:
|
|
42
|
-
return None
|
|
43
|
-
text = value.strip().replace("$", "").replace(",", "").replace("%", "")
|
|
44
|
-
negative = text.startswith("(") and text.endswith(")")
|
|
45
|
-
text = text.strip("()")
|
|
46
|
-
if text in ("", "-", "."):
|
|
47
|
-
return None
|
|
48
|
-
try:
|
|
49
|
-
return -float(text) if negative else float(text)
|
|
50
|
-
except ValueError:
|
|
51
|
-
return None
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def day(value: str | None) -> date | None:
|
|
55
|
-
"""DairyComp and EZfeed dates: 11/20/25, 11/20/2025, 2025-11-20. Blank -> None."""
|
|
56
|
-
if not value:
|
|
57
|
-
return None
|
|
58
|
-
text = value.strip()
|
|
59
|
-
for fmt in ("%m/%d/%y", "%m/%d/%Y", "%Y-%m-%d"):
|
|
60
|
-
try:
|
|
61
|
-
return datetime.strptime(text, fmt).date()
|
|
62
|
-
except ValueError:
|
|
63
|
-
continue
|
|
64
|
-
return None
|
|
29
|
+
ENCODINGS = _io.ENCODINGS
|
|
30
|
+
read_text = _io.read_text
|
|
31
|
+
rows_of = _io.rows_of
|
|
32
|
+
number = _io.number
|
|
33
|
+
day = _io.parse_dc_date
|
|
65
34
|
|
|
66
35
|
|
|
67
36
|
# --- DairyComp -------------------------------------------------------------------------------------------------------
|
|
@@ -70,19 +39,14 @@ def read_cow_list(path: str | Path) -> list[dict[str, str]]:
|
|
|
70
39
|
"""A DairyComp SHOW (saved as CSV) or FILEOUT export with a header row: one dict per cow, keyed by item name (ID, PEN, LACT...).
|
|
71
40
|
|
|
72
41
|
Handles the padded values a saved report has and the empty last column it often ends with."""
|
|
73
|
-
|
|
74
|
-
if not
|
|
75
|
-
raise ValueError(f"{path}: the file is empty")
|
|
76
|
-
header = [name.upper() for name in rows[0]]
|
|
77
|
-
while header and header[-1] == "":
|
|
78
|
-
header.pop()
|
|
79
|
-
if "ID" not in header:
|
|
42
|
+
raw_rows = _io.read_dc_export(path)
|
|
43
|
+
if not raw_rows or "ID" not in raw_rows[0]:
|
|
80
44
|
raise ValueError(f"{path}: no ID column in the first row; export the list with its header row")
|
|
81
45
|
cows = []
|
|
82
|
-
for row in
|
|
83
|
-
cow = {
|
|
84
|
-
if cow.get("ID"
|
|
85
|
-
continue
|
|
46
|
+
for row in raw_rows:
|
|
47
|
+
cow = {k: ("" if v is None else v) for k, v in row.items() if k and k != "_spilled"}
|
|
48
|
+
if not cow.get("ID") or cow["ID"].lower().startswith("total"):
|
|
49
|
+
continue
|
|
86
50
|
cows.append(cow)
|
|
87
51
|
return cows
|
|
88
52
|
|
|
@@ -96,30 +60,34 @@ def read_events(path: str | Path, include_remarks: bool = False) -> list[dict]:
|
|
|
96
60
|
"""A DairyComp EVENTS export (ID, BDAT, LACT, Event, DIM, Date, Remark, ...): one dict per event with a real date.
|
|
97
61
|
|
|
98
62
|
Remarks, protocols and technicians stay out unless include_remarks is True (they are free text typed on the farm,
|
|
99
|
-
and technicians are people's names).
|
|
100
|
-
|
|
101
|
-
|
|
63
|
+
and technicians are people's names). Deduplication runs on the full row before dropping untrusted columns so
|
|
64
|
+
event counts do not depend on `include_remarks`."""
|
|
65
|
+
raw_rows = _io.read_dc_export(path)
|
|
66
|
+
header = set(raw_rows[0]) if raw_rows else set()
|
|
102
67
|
missing = [name for name in EVENT_COLUMNS if name not in header]
|
|
103
68
|
if missing:
|
|
104
69
|
raise ValueError(f"{path}: not an EVENTS export (missing {', '.join(missing)})")
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
70
|
+
all_cols = list(EVENT_COLUMNS) + list(OPTIONAL_EVENT_COLUMNS) + list(UNTRUSTED_EVENT_COLUMNS)
|
|
71
|
+
keep = list(EVENT_COLUMNS) + list(OPTIONAL_EVENT_COLUMNS) + (
|
|
72
|
+
list(UNTRUSTED_EVENT_COLUMNS) if include_remarks else []
|
|
73
|
+
)
|
|
74
|
+
seen, unique = set(), []
|
|
75
|
+
for raw in raw_rows:
|
|
76
|
+
cid = raw.get("ID") or ""
|
|
109
77
|
when = day(raw.get("DATE"))
|
|
110
|
-
if not
|
|
78
|
+
if not cid or cid.lower().startswith("total") or when is None:
|
|
79
|
+
continue
|
|
80
|
+
full_key = tuple(
|
|
81
|
+
when.isoformat() if k == "DATE" else (raw.get(k) or "").upper() if k == "EVENT" else (raw.get(k) or "")
|
|
82
|
+
for k in all_cols
|
|
83
|
+
)
|
|
84
|
+
if full_key in seen:
|
|
111
85
|
continue
|
|
112
|
-
|
|
86
|
+
seen.add(full_key)
|
|
87
|
+
event = {name: (raw.get(name) or "") for name in keep if name in raw}
|
|
113
88
|
event["DATE"] = when
|
|
114
89
|
event["EVENT"] = event["EVENT"].upper()
|
|
115
|
-
|
|
116
|
-
# The same event exported twice (overlapping windows) counts once.
|
|
117
|
-
seen, unique = set(), []
|
|
118
|
-
for e in events:
|
|
119
|
-
key = tuple(str(e.get(k)) for k in keep)
|
|
120
|
-
if key not in seen:
|
|
121
|
-
seen.add(key)
|
|
122
|
-
unique.append(e)
|
|
90
|
+
unique.append(event)
|
|
123
91
|
return unique
|
|
124
92
|
|
|
125
93
|
|
|
@@ -132,7 +100,7 @@ DAIRYCOMP_FIGURE = re.compile(
|
|
|
132
100
|
r"305|\bME\b|MATURE|AGE[- ]?ADJ|\bAA|AA\b|PROJ|PREDICT|RELV|RELATIVE|\bREL\b|INDEX|VALUE|PTA|MERIT|GENOMIC")
|
|
133
101
|
|
|
134
102
|
|
|
135
|
-
@dataclass
|
|
103
|
+
@dataclass(slots=True)
|
|
136
104
|
class Item:
|
|
137
105
|
name: str
|
|
138
106
|
description: str
|
|
@@ -152,29 +120,21 @@ class Item:
|
|
|
152
120
|
def read_items(path: str | Path) -> list[Item]:
|
|
153
121
|
"""DairyComp's item list as ALTER\\2 > Tools > Export > CSV writes it (Name, Index, Loc/Op1, Len/Op2, Type,
|
|
154
122
|
Description)."""
|
|
155
|
-
rows = [row for row in rows_of(path) if any(row)]
|
|
156
|
-
header = [name.upper() for name in rows[0]]
|
|
157
|
-
need = {"NAME": None, "LOC/OP1": None, "LEN/OP2": None, "TYPE": None, "DESCRIPTION": None}
|
|
158
|
-
for key in need:
|
|
159
|
-
if key not in header:
|
|
160
|
-
raise ValueError(f"{path}: not an ALTER item export (no {key} column)")
|
|
161
|
-
need[key] = header.index(key)
|
|
162
123
|
return [
|
|
163
124
|
Item(
|
|
164
|
-
name=
|
|
165
|
-
description=
|
|
166
|
-
type_code=
|
|
167
|
-
op1=
|
|
168
|
-
op2=
|
|
125
|
+
name=r["dc_item"],
|
|
126
|
+
description=r.get("description") or "",
|
|
127
|
+
type_code=r.get("type_code") or "",
|
|
128
|
+
op1=r.get("op1") or "",
|
|
129
|
+
op2=r.get("op2") or "",
|
|
169
130
|
)
|
|
170
|
-
for
|
|
171
|
-
if row and row[need["NAME"]]
|
|
131
|
+
for r in _io.read_item_list(path)
|
|
172
132
|
]
|
|
173
133
|
|
|
174
134
|
|
|
175
135
|
# --- EZfeed ----------------------------------------------------------------------------------------------------------
|
|
176
136
|
|
|
177
|
-
@dataclass
|
|
137
|
+
@dataclass(slots=True)
|
|
178
138
|
class IngredientDay:
|
|
179
139
|
pen: str
|
|
180
140
|
ingredient: str
|
|
@@ -231,44 +191,27 @@ def read_intakes(paths) -> IntakeReport:
|
|
|
231
191
|
def read_intake(path: str | Path) -> IntakeReport:
|
|
232
192
|
"""EZfeed's ingredient usage export. Two header rows (DMTgt, DMAct, $Tgt, $Act... over IU(lbs/hd), IU($/hd)...),
|
|
233
193
|
then a row per pen, a row per ingredient under it, and a row per day under each ingredient."""
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if head is None or head == 0:
|
|
194
|
+
rep = _io.read_ezfeed(path, flexible=True)
|
|
195
|
+
if rep is None or rep["kind"] != "intake_by_pen":
|
|
237
196
|
raise ValueError(f"{path}: not EZfeed's ingredient usage report (no 'Pen, Ingredient, Date' header row)")
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
pen = ingredient = None
|
|
251
|
-
for row in rows[head + 1:]:
|
|
252
|
-
if not any(row):
|
|
253
|
-
continue
|
|
254
|
-
cell = lambda i: row[i] if i < len(row) else ""
|
|
255
|
-
if cell(0):
|
|
256
|
-
pen, ingredient = cell(0), None
|
|
257
|
-
continue
|
|
258
|
-
if cell(1):
|
|
259
|
-
ingredient = cell(1)
|
|
260
|
-
continue
|
|
261
|
-
when = day(cell(2))
|
|
262
|
-
if pen is None or ingredient is None or when is None:
|
|
263
|
-
continue
|
|
264
|
-
report.days.append(IngredientDay(pen, ingredient, when, number(cell(dm_t)), number(cell(dm_a)),
|
|
265
|
-
number(cell(c_t)), number(cell(c_a))))
|
|
197
|
+
report = IntakeReport(days=[
|
|
198
|
+
IngredientDay(
|
|
199
|
+
pen=r["pen"],
|
|
200
|
+
ingredient=r["ingredient"],
|
|
201
|
+
date=r["date"],
|
|
202
|
+
dm_target_lb=r["target_dm_lb_per_head"],
|
|
203
|
+
dm_actual_lb=r["actual_dm_lb_per_head"],
|
|
204
|
+
cost_target_hd=r["target_cost_per_head"],
|
|
205
|
+
cost_actual_hd=r["actual_cost_per_head"],
|
|
206
|
+
)
|
|
207
|
+
for r in rep["rows"]
|
|
208
|
+
])
|
|
266
209
|
if not report.days:
|
|
267
210
|
raise ValueError(f"{path}: no daily rows found under the pens and ingredients")
|
|
268
211
|
return report
|
|
269
212
|
|
|
270
213
|
|
|
271
|
-
@dataclass
|
|
214
|
+
@dataclass(slots=True)
|
|
272
215
|
class RationLine:
|
|
273
216
|
ration: str
|
|
274
217
|
ingredient: str
|
|
@@ -282,49 +225,39 @@ class RationLine:
|
|
|
282
225
|
def read_rations(path: str | Path) -> list[RationLine]:
|
|
283
226
|
"""EZfeed's ration (recipe) export: a row per ration with its totals, then its ingredients
|
|
284
227
|
(AF lb, DM lb, $ a head a day, DM %, $ a ton as fed)."""
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
if head is None:
|
|
228
|
+
rep = _io.read_ezfeed(path, flexible=True)
|
|
229
|
+
if rep is None or rep["kind"] != "rations":
|
|
288
230
|
raise ValueError(f"{path}: not EZfeed's ration report (no 'Ration, Ingredient' header row)")
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
231
|
+
return [
|
|
232
|
+
RationLine(
|
|
233
|
+
ration=r["ration"],
|
|
234
|
+
ingredient=r["ingredient"],
|
|
235
|
+
as_fed_lb=r["as_fed_lb_per_head"],
|
|
236
|
+
dm_lb=r["dm_lb_per_head"],
|
|
237
|
+
cost_hd=r["cost_per_head"],
|
|
238
|
+
dm_pct=r["dm_pct"],
|
|
239
|
+
price_ton_as_fed=r["as_fed_cost_per_ton"],
|
|
240
|
+
)
|
|
241
|
+
for r in rep["rows"]
|
|
242
|
+
]
|
|
301
243
|
|
|
302
244
|
|
|
303
245
|
# --- Figures worked out here, from raw records -----------------------------------------------------------------------
|
|
304
246
|
|
|
305
247
|
def ecm_lb(milk_lb: float, fat_pct: float, protein_pct: float) -> float:
|
|
306
248
|
"""Energy-corrected milk, lb (Tyrrell and Reid, 1965, as DHIA uses it)."""
|
|
307
|
-
return
|
|
249
|
+
return _stats.ecm_lb(milk_lb, fat_pct, protein_pct)
|
|
308
250
|
|
|
309
251
|
|
|
310
|
-
|
|
311
|
-
values = [v for v in values if v is not None]
|
|
312
|
-
return math.fsum(values) / len(values) if values else None # the same answer on every Python
|
|
252
|
+
mean = _stats.mean
|
|
313
253
|
|
|
314
254
|
|
|
315
255
|
def percentiles(values, qs=(0.1, 0.5, 0.9)) -> tuple[float, ...] | None:
|
|
316
256
|
"""Linear-interpolated percentiles (the spread a pen card shows: low tenth, middle cow, high tenth)."""
|
|
317
|
-
|
|
318
|
-
if not
|
|
257
|
+
vals = _stats.clean(values)
|
|
258
|
+
if not vals:
|
|
319
259
|
return None
|
|
320
|
-
|
|
321
|
-
def at(q: float) -> float:
|
|
322
|
-
position = (len(values) - 1) * q
|
|
323
|
-
low = int(position)
|
|
324
|
-
high = min(low + 1, len(values) - 1)
|
|
325
|
-
return values[low] + (values[high] - values[low]) * (position - low)
|
|
326
|
-
|
|
327
|
-
return tuple(at(q) for q in qs)
|
|
260
|
+
return tuple(_stats.quantile(vals, q) for q in qs)
|
|
328
261
|
|
|
329
262
|
|
|
330
263
|
def quartiles(values) -> tuple[float, float, float] | None:
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""Dairy Data Tools: read a farm's DairyComp and EZfeed exports and work out what a nutritionist or vet asks.
|
|
2
|
+
|
|
3
|
+
Python 3.10+ standard library only (`dependencies = []`). Read-only: nothing is written except where a command is told
|
|
4
|
+
to, and nothing is sent over the network. Ported from the author's earlier R version, with parity verified against R,
|
|
5
|
+
plus record-only extensions and a zero-network handoff to Dairy Ration Lab (`lab.dairydatascience.com`).
|
|
6
|
+
|
|
7
|
+
The one source is `tools/dairytools` in the repository; `tools/sync_scripts.py` copies it into each skill's `scripts/`
|
|
8
|
+
folder, because in Claude's chat only a skill's own folder reaches the code sandbox.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from . import commands, ecosystem, epi, explorer, feeding, herd, io, models, repro, stats, udder, weekly
|
|
14
|
+
from .ecosystem import ECOSYSTEM, ration_lab_handoff
|
|
15
|
+
from .epi import (
|
|
16
|
+
audit_records,
|
|
17
|
+
calving_outcomes,
|
|
18
|
+
calving_period,
|
|
19
|
+
compare_groups,
|
|
20
|
+
dry_band,
|
|
21
|
+
dry_period_length,
|
|
22
|
+
dry_periods,
|
|
23
|
+
event_months,
|
|
24
|
+
fresh_disease_effects,
|
|
25
|
+
herd_survival,
|
|
26
|
+
lactation_data,
|
|
27
|
+
left_herd,
|
|
28
|
+
left_reasons,
|
|
29
|
+
mantel_haenszel_rr,
|
|
30
|
+
risk_ratio,
|
|
31
|
+
)
|
|
32
|
+
from .errors import DairyToolsError, FolderNotFoundError, MissingDataError, NotFoundError
|
|
33
|
+
from .herd import Herd, load
|
|
34
|
+
from .models import Cow, Event, Lactation, to_pandas, to_polars
|
|
35
|
+
from .repro import (
|
|
36
|
+
age_first_calving,
|
|
37
|
+
calving_interval,
|
|
38
|
+
conception_by,
|
|
39
|
+
first_service,
|
|
40
|
+
heifer_repro,
|
|
41
|
+
inter_service_intervals,
|
|
42
|
+
pregnancy_loss,
|
|
43
|
+
pregnancy_rate,
|
|
44
|
+
pregnant_by,
|
|
45
|
+
time_to_pregnancy,
|
|
46
|
+
)
|
|
47
|
+
from .udder import mastitis_incidence, scc_dynamics, scc_screen
|
|
48
|
+
|
|
49
|
+
__version__ = "0.3.2"
|
|
50
|
+
|
|
51
|
+
__all__ = [
|
|
52
|
+
"__version__",
|
|
53
|
+
"Cow",
|
|
54
|
+
"DairyToolsError",
|
|
55
|
+
"ECOSYSTEM",
|
|
56
|
+
"Event",
|
|
57
|
+
"FolderNotFoundError",
|
|
58
|
+
"Herd",
|
|
59
|
+
"Lactation",
|
|
60
|
+
"MissingDataError",
|
|
61
|
+
"NotFoundError",
|
|
62
|
+
"age_first_calving",
|
|
63
|
+
"audit_records",
|
|
64
|
+
"calving_interval",
|
|
65
|
+
"calving_outcomes",
|
|
66
|
+
"calving_period",
|
|
67
|
+
"commands",
|
|
68
|
+
"compare_groups",
|
|
69
|
+
"conception_by",
|
|
70
|
+
"dry_band",
|
|
71
|
+
"dry_period_length",
|
|
72
|
+
"dry_periods",
|
|
73
|
+
"ecosystem",
|
|
74
|
+
"epi",
|
|
75
|
+
"event_months",
|
|
76
|
+
"explorer",
|
|
77
|
+
"feeding",
|
|
78
|
+
"first_service",
|
|
79
|
+
"fresh_disease_effects",
|
|
80
|
+
"heifer_repro",
|
|
81
|
+
"herd",
|
|
82
|
+
"herd_survival",
|
|
83
|
+
"inter_service_intervals",
|
|
84
|
+
"io",
|
|
85
|
+
"lactation_data",
|
|
86
|
+
"left_herd",
|
|
87
|
+
"left_reasons",
|
|
88
|
+
"load",
|
|
89
|
+
"mantel_haenszel_rr",
|
|
90
|
+
"mastitis_incidence",
|
|
91
|
+
"models",
|
|
92
|
+
"pregnancy_loss",
|
|
93
|
+
"pregnancy_rate",
|
|
94
|
+
"pregnant_by",
|
|
95
|
+
"ration_lab_handoff",
|
|
96
|
+
"repro",
|
|
97
|
+
"risk_ratio",
|
|
98
|
+
"scc_dynamics",
|
|
99
|
+
"scc_screen",
|
|
100
|
+
"stats",
|
|
101
|
+
"time_to_pregnancy",
|
|
102
|
+
"to_pandas",
|
|
103
|
+
"to_polars",
|
|
104
|
+
"udder",
|
|
105
|
+
"weekly",
|
|
106
|
+
]
|