dairy-data-tools 0.2.1__tar.gz → 0.2.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.
Files changed (32) hide show
  1. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/CITATION.cff +1 -1
  2. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/NOTICE +3 -0
  3. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/PKG-INFO +24 -1
  4. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/README.md +23 -0
  5. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/plugins/dairy-data-tools/NOTICE +3 -0
  6. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/plugins/dairy-data-tools/README.md +23 -0
  7. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/pyproject.toml +1 -1
  8. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/tools/dairytools/cards.py +157 -126
  9. dairy_data_tools-0.2.2/tools/dairytools/data/NOTICE-nasem.md +11 -0
  10. dairy_data_tools-0.2.2/tools/dairytools/data/nasem_feeds.csv +285 -0
  11. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/tools/dairytools/io.py +3 -0
  12. dairy_data_tools-0.2.2/tools/dairytools/nutrients.py +141 -0
  13. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/tools/dairytools/weeklycard.py +2 -1
  14. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/.gitignore +0 -0
  15. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/LICENSE +0 -0
  16. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/LICENSE-skills.md +0 -0
  17. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/plugins/dairy-data-tools/LICENSE +0 -0
  18. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/plugins/dairy-data-tools/LICENSE-skills.md +0 -0
  19. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/plugins/dairy-data-tools/sample-herd/README.md +0 -0
  20. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/tools/dairyread.py +0 -0
  21. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/tools/dairytools/__init__.py +0 -0
  22. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/tools/dairytools/cli.py +0 -0
  23. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/tools/dairytools/commands.py +0 -0
  24. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/tools/dairytools/cowcard.py +0 -0
  25. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/tools/dairytools/explorer.py +0 -0
  26. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/tools/dairytools/feeding.py +0 -0
  27. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/tools/dairytools/herd.py +0 -0
  28. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/tools/dairytools/reference.py +0 -0
  29. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/tools/dairytools/stats.py +0 -0
  30. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/tools/dairytools/weekly.py +0 -0
  31. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/tools/pen_milk.py +0 -0
  32. {dairy_data_tools-0.2.1 → dairy_data_tools-0.2.2}/tools/ration_change.py +0 -0
@@ -11,7 +11,7 @@ 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.1
14
+ version: 0.2.2
15
15
  doi: 10.5281/zenodo.23493936
16
16
  date-released: 2026-10-20
17
17
  license: Apache-2.0
@@ -10,6 +10,9 @@ Figures and their sources:
10
10
  - Predicted dry matter intake: National Academies of Sciences, Engineering, and Medicine (2021), Nutrient
11
11
  Requirements of Dairy Cattle, 8th revised edition, equation 2-1.
12
12
  - 21-day pregnancy rate: counted the way DairyComp 305's BREDSUM report counts it.
13
+ - What a ration holds, where the farm has no analyses of its own: the NASEM (2021) feed library, from the nasem_dairy
14
+ package (Fieguth, Innes and Cant). Those values are NASEM's and keep NASEM's terms (academic use with acknowledgment;
15
+ commercial use needs NASEM's release), not this project's licence: see dairytools/data/NOTICE-nasem.md.
13
16
 
14
17
  DairyComp 305 and EZfeed are products of Valley Ag Software. This project is not affiliated with or endorsed
15
18
  by Valley Ag Software. It reads only export files that the programs write for their users.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: dairy-data-tools
3
- Version: 0.2.1
3
+ Version: 0.2.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
@@ -67,6 +67,29 @@ You get the figures, where each came from and what it's out of, and a card like
67
67
  No DairyComp export yet? Ask *"What do I type in DairyComp to export what you need?"*. It writes the SHOW commands from
68
68
  the farm's own item list.
69
69
 
70
+ ## What you get
71
+
72
+ Each answer comes back as a card. These are from the sample herd.
73
+
74
+ <table>
75
+ <tr>
76
+ <td width="50%" valign="top"><b>A cow</b><br>Her milk this lactation, her place in the pen, what's happened to her.<br><br>
77
+ <img src="https://raw.githubusercontent.com/padge01/dairy-data-tools/main/docs/images/card-cow.png" alt="Cow 3004's card" width="100%"></td>
78
+ <td width="50%" valign="top"><b>Pen feed</b><br>Each pen's intake, efficiency, cost per cwt and ration side by side.<br><br>
79
+ <img src="https://raw.githubusercontent.com/padge01/dairy-data-tools/main/docs/images/card-pen-feed.png" alt="The pen feed card" width="100%"></td>
80
+ </tr>
81
+ <tr>
82
+ <td valign="top"><b>Visit review</b><br>Fresh cows, components, udder health, reproduction, who left, and what to check next.<br><br>
83
+ <img src="https://raw.githubusercontent.com/padge01/dairy-data-tools/main/docs/images/card-visit.png" alt="The visit review" width="100%"></td>
84
+ <td valign="top"><b>On a slide</b><br>Add <code>--slide</code>: bigger, fewer items, sized for a talk or a meeting.<br><br>
85
+ <img src="https://raw.githubusercontent.com/padge01/dairy-data-tools/main/docs/images/card-slide.png" alt="Pen 21's card as a slide" width="100%"></td>
86
+ </tr>
87
+ </table>
88
+
89
+ Herds that test get ECM from their tests. Herds that only weigh milk get each cow's daily weight, and the card says so.
90
+ Save the exports more than once and the cards join them: each day gives a pen's milk by day, each month gives a cow's
91
+ tests.
92
+
70
93
  ## Other apps
71
94
 
72
95
  | Where | How |
@@ -48,6 +48,29 @@ You get the figures, where each came from and what it's out of, and a card like
48
48
  No DairyComp export yet? Ask *"What do I type in DairyComp to export what you need?"*. It writes the SHOW commands from
49
49
  the farm's own item list.
50
50
 
51
+ ## What you get
52
+
53
+ Each answer comes back as a card. These are from the sample herd.
54
+
55
+ <table>
56
+ <tr>
57
+ <td width="50%" valign="top"><b>A cow</b><br>Her milk this lactation, her place in the pen, what's happened to her.<br><br>
58
+ <img src="https://raw.githubusercontent.com/padge01/dairy-data-tools/main/docs/images/card-cow.png" alt="Cow 3004's card" width="100%"></td>
59
+ <td width="50%" valign="top"><b>Pen feed</b><br>Each pen's intake, efficiency, cost per cwt and ration side by side.<br><br>
60
+ <img src="https://raw.githubusercontent.com/padge01/dairy-data-tools/main/docs/images/card-pen-feed.png" alt="The pen feed card" width="100%"></td>
61
+ </tr>
62
+ <tr>
63
+ <td valign="top"><b>Visit review</b><br>Fresh cows, components, udder health, reproduction, who left, and what to check next.<br><br>
64
+ <img src="https://raw.githubusercontent.com/padge01/dairy-data-tools/main/docs/images/card-visit.png" alt="The visit review" width="100%"></td>
65
+ <td valign="top"><b>On a slide</b><br>Add <code>--slide</code>: bigger, fewer items, sized for a talk or a meeting.<br><br>
66
+ <img src="https://raw.githubusercontent.com/padge01/dairy-data-tools/main/docs/images/card-slide.png" alt="Pen 21's card as a slide" width="100%"></td>
67
+ </tr>
68
+ </table>
69
+
70
+ Herds that test get ECM from their tests. Herds that only weigh milk get each cow's daily weight, and the card says so.
71
+ Save the exports more than once and the cards join them: each day gives a pen's milk by day, each month gives a cow's
72
+ tests.
73
+
51
74
  ## Other apps
52
75
 
53
76
  | Where | How |
@@ -10,6 +10,9 @@ Figures and their sources:
10
10
  - Predicted dry matter intake: National Academies of Sciences, Engineering, and Medicine (2021), Nutrient
11
11
  Requirements of Dairy Cattle, 8th revised edition, equation 2-1.
12
12
  - 21-day pregnancy rate: counted the way DairyComp 305's BREDSUM report counts it.
13
+ - What a ration holds, where the farm has no analyses of its own: the NASEM (2021) feed library, from the nasem_dairy
14
+ package (Fieguth, Innes and Cant). Those values are NASEM's and keep NASEM's terms (academic use with acknowledgment;
15
+ commercial use needs NASEM's release), not this project's licence: see dairytools/data/NOTICE-nasem.md.
13
16
 
14
17
  DairyComp 305 and EZfeed are products of Valley Ag Software. This project is not affiliated with or endorsed
15
18
  by Valley Ag Software. It reads only export files that the programs write for their users.
@@ -48,6 +48,29 @@ You get the figures, where each came from and what it's out of, and a card like
48
48
  No DairyComp export yet? Ask *"What do I type in DairyComp to export what you need?"*. It writes the SHOW commands from
49
49
  the farm's own item list.
50
50
 
51
+ ## What you get
52
+
53
+ Each answer comes back as a card. These are from the sample herd.
54
+
55
+ <table>
56
+ <tr>
57
+ <td width="50%" valign="top"><b>A cow</b><br>Her milk this lactation, her place in the pen, what's happened to her.<br><br>
58
+ <img src="https://raw.githubusercontent.com/padge01/dairy-data-tools/main/docs/images/card-cow.png" alt="Cow 3004's card" width="100%"></td>
59
+ <td width="50%" valign="top"><b>Pen feed</b><br>Each pen's intake, efficiency, cost per cwt and ration side by side.<br><br>
60
+ <img src="https://raw.githubusercontent.com/padge01/dairy-data-tools/main/docs/images/card-pen-feed.png" alt="The pen feed card" width="100%"></td>
61
+ </tr>
62
+ <tr>
63
+ <td valign="top"><b>Visit review</b><br>Fresh cows, components, udder health, reproduction, who left, and what to check next.<br><br>
64
+ <img src="https://raw.githubusercontent.com/padge01/dairy-data-tools/main/docs/images/card-visit.png" alt="The visit review" width="100%"></td>
65
+ <td valign="top"><b>On a slide</b><br>Add <code>--slide</code>: bigger, fewer items, sized for a talk or a meeting.<br><br>
66
+ <img src="https://raw.githubusercontent.com/padge01/dairy-data-tools/main/docs/images/card-slide.png" alt="Pen 21's card as a slide" width="100%"></td>
67
+ </tr>
68
+ </table>
69
+
70
+ Herds that test get ECM from their tests. Herds that only weigh milk get each cow's daily weight, and the card says so.
71
+ Save the exports more than once and the cards join them: each day gives a pen's milk by day, each month gives a cow's
72
+ tests.
73
+
51
74
  ## Other apps
52
75
 
53
76
  | Where | How |
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dairy-data-tools"
3
- version = "0.2.1"
3
+ version = "0.2.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"
@@ -13,7 +13,7 @@ import re
13
13
  from collections import defaultdict
14
14
  from datetime import date, timedelta
15
15
 
16
- from . import explorer, feeding
16
+ from . import explorer, feeding, nutrients
17
17
  from .herd import Herd
18
18
  from .stats import ecm_lb, mean, quantile
19
19
 
@@ -21,10 +21,11 @@ CSS = """
21
21
  :root{--canvas:#fafaf9;--surface:#fff;--raised:#f0f2ef;--text:#0a0a0a;--text2:#626762;--text3:#6b726c;--border:#dedfdc;--subtle:#efefec;
22
22
  --line:#bfc3be;--bar:#cfd3ce;--ink:#0a0a0a;--l1:#c9a93a;--l2:#e08a2c;--l3:#9a6a43;--mark:#2b302c;
23
23
  --forage:#6f9a52;--grain:#c9a93a;--protein:#5a80aa;--fat:#e08a2c;--byproduct:#a47b55;--mineral:#8f948f;--other:#b5b9b4;--feed:#b8962a;--feedwash:rgba(201,169,58,.20);
24
+ --n-ndf:#3987e5;--n-starch:#d95926;--n-cp:#199e70;--n-fat:#c98500;--n-other:#cfd3ce;
24
25
  --sans:'Inter Variable','Inter','Segoe UI',system-ui,sans-serif}
25
26
  @media (prefers-color-scheme:dark){:root{--canvas:#0d110f;--surface:#151a17;--raised:#1d241f;--text:#f1f4f2;--text2:#aab3ad;
26
27
  --text3:#7d8a82;--border:#323b35;--subtle:#232b26;--line:#4a564e;--bar:#3a463f;--ink:#f1f4f2;--l1:#e6cf7a;--l2:#f0a24a;
27
- --l3:#c08a5c;--mark:#c9d1cb;--forage:#8cb56c;--grain:#e6cf7a;--protein:#86a9cf;--fat:#f0a24a;--byproduct:#c49a74;--mineral:#8f9a93;--other:#5d6660;--feed:#e6cf7a;--feedwash:rgba(230,207,122,.16)}}
28
+ --l3:#c08a5c;--mark:#c9d1cb;--forage:#8cb56c;--grain:#e6cf7a;--protein:#86a9cf;--fat:#f0a24a;--byproduct:#c49a74;--mineral:#8f9a93;--other:#5d6660;--feed:#e6cf7a;--feedwash:rgba(230,207,122,.16);--n-ndf:#2a78d6;--n-starch:#eb6834;--n-cp:#1baf7a;--n-fat:#eda100;--n-other:#3a463f}}
28
29
  *{box-sizing:border-box}body{margin:0;background:var(--canvas);color:var(--text);font-family:var(--sans)}
29
30
  .card{max-width:1180px;margin:24px auto;background:var(--surface);border:1px solid var(--border);border-radius:22px;
30
31
  padding:22px 30px 18px}
@@ -173,83 +174,119 @@ def _runs(points):
173
174
  return out
174
175
 
175
176
 
176
- def day_plot(title, start: date, end: date, change: date | None = None, band=(), lines=(), fed=(), width=760,
177
- height=270) -> str:
178
- """Milk and dry matter fed by day on one pound scale from 0: `band` [(day, low, mid, high)] the
179
- middle cow as a line with her middle 80% shaded; `lines` [(label, style, [(day, lb)])] such as a pen's ECM;
180
- `fed` [(day, lb DM)] as a wash from the floor. Every line is named in words where it ends."""
181
- pad_l, pad_r, top, bottom = 40, 126, 30, 26
182
- ph = height - top - bottom
177
+ def ordinal_word(n: int) -> str:
178
+ return f"{n}{'th' if 10 <= n % 100 <= 20 else {1: 'st', 2: 'nd', 3: 'rd'}.get(n % 10, 'th')}"
179
+
180
+
181
+ def pen_panels(start: date, end: date, change: date | None = None, band=(), lines=(), fed=(), shares=None,
182
+ milk_words="Milk, lb a cow", width=760) -> str:
183
+ """Two panels on one time axis: milk above on its own close scale (`band` [(day, low, mid, high)] or `lines`
184
+ [(label, style, [(day, lb)])]); below, the dry matter fed a cow by day, as a stack of what's in it when `shares`
185
+ {day: {layer: share}} is known, else one area. The last ration change is marked across both."""
186
+ from .nutrients import LAYERS
187
+ pad_l, pad_r, gap = 40, 150, 40
188
+ top_h = 150 if (band or any(len([v for _, v in s if v is not None]) > 1 for _, _, s in lines)) else 0
189
+ low_h = 190 if fed else 0
190
+ if not (top_h or low_h):
191
+ return ""
192
+ height = 24 + (top_h + gap if top_h else 0) + low_h + 26
183
193
  span = max((end - start).days, 1)
184
194
  x = lambda d: pad_l + (d - start).days / span * (width - pad_l - pad_r)
185
- band = [b for b in band if start <= b[0] <= end]
186
- fed = [f for f in fed if start <= f[0] <= end and f[1] is not None]
187
- lines = [(lab, sty, [(d, v) for d, v in s if start <= d <= end]) for lab, sty, s in lines]
188
- vals = [v for b in band for v in b[1:] if v is not None] + [v for _, _, s in lines for _, v in s if v is not None] \
189
- + [v for _, v in fed]
190
- if not vals:
191
- return ""
192
- step = 25 if max(vals) <= 110 else 50
193
- ymax = math.ceil(max(vals) * 1.06 / step) * step
194
- y = lambda v: top + ph - v / ymax * ph
195
- out = [f'<svg viewBox="0 0 {width} {height}" width="100%" role="img" aria-label="{esc(title)}, {start} to {end}">',
196
- f'<text x="{pad_l - 34}" y="14" class="lab" font-size="13">{esc(title)}</text>']
197
- v = 0
198
- while v <= ymax:
199
- out.append(f'<line x1="{pad_l}" x2="{width - pad_r}" y1="{y(v):.1f}" y2="{y(v):.1f}" stroke="var(--subtle)"/>'
200
- f'<text x="{pad_l - 6}" y="{y(v) + 4:.1f}" font-size="11" text-anchor="end">{v}</text>')
201
- v += step
202
- ends = []
203
- for run in _runs(fed):
204
- pts = " ".join(f"{x(d):.1f},{y(v):.1f}" for d, v in run)
205
- out.append(f'<polygon points="{x(run[0][0]):.1f},{y(0):.1f} {pts} {x(run[-1][0]):.1f},{y(0):.1f}" '
206
- f'fill="var(--feedwash)"/><polyline points="{pts}" fill="none" stroke="var(--feed)" stroke-width="1.6"/>')
207
- if fed:
208
- mid = fed[len(fed) // 3]
209
- out.append(f'<text x="{x(mid[0]) + 4:.1f}" y="{(y(mid[1]) + y(0)) / 2 + 4:.1f}" font-size="12.5" class="lab">'
210
- f'Dry matter fed per cow</text>')
211
- ends.append([y(fed[-1][1]) + 4, x(fed[-1][0]) + 6, f'<tspan font-weight="650">{fed[-1][1]:.1f}</tspan> fed'])
212
- for run in _runs(band):
213
- upper = " ".join(f"{x(d):.1f},{y(hi):.1f}" for d, lo, m, hi in run)
214
- lower = " ".join(f"{x(d):.1f},{y(lo):.1f}" for d, lo, m, hi in reversed(run))
215
- out.append(f'<polygon points="{upper} {lower}" fill="var(--bar)" opacity=".75"/>')
216
- out.append('<polyline points="' + " ".join(f"{x(d):.1f},{y(m):.1f}" for d, lo, m, hi in run)
217
- + '" fill="none" stroke="var(--ink)" stroke-width="2.2"/>')
218
- if band:
219
- first = band[len(band) // 3]
220
- out.append(f'<text x="{x(first[0]) + 4:.1f}" y="{y(first[3]) - 7:.1f}" font-size="12.5" class="lab">'
221
- f'Milk: the middle cow (shading: the middle 80%)</text>')
222
- last = band[-1]
223
- ends.append([y(last[2]) + 4, x(last[0]) + 6, f'<tspan font-weight="650">{last[2]:.0f}</tspan> milk'])
224
- for label, style, s in lines:
225
- s = [(d, v) for d, v in s if v is not None]
226
- if len(s) < 2:
227
- continue
228
- pts = " ".join(f"{x(d):.1f},{y(v):.1f}" for d, v in s)
229
- dash = ' stroke-dasharray="5 4"' if style == "dashed" else ""
230
- w = "2.4" if style == "bold" else "1.6" if style == "dashed" else "1"
231
- colour = "var(--line)" if style == "thin" else "var(--ink)" if style == "bold" else "var(--text2)"
232
- out.append(f'<polyline points="{pts}" fill="none" stroke="{colour}" stroke-width="{w}"{dash}/>')
233
- if style != "thin":
234
- d, v = s[-1]
235
- ends.append([y(v) + 4, x(d) + 6, f'<tspan font-weight="650">{v:.1f}</tspan> {esc(label)}'])
236
- ends.sort() # end labels never overlap: each at least 15 px below the one above
237
- for i in range(1, len(ends)):
238
- ends[i][0] = max(ends[i][0], ends[i - 1][0] + 15)
239
- for ly, lx, text in ends:
240
- out.append(f'<text x="{lx:.1f}" y="{ly:.1f}" font-size="12.5" class="lab">{text}</text>')
195
+ out = [f'<svg viewBox="0 0 {width} {height}" width="100%" role="img" aria-label="milk and intake by day">']
196
+
197
+ def ends_text(ends):
198
+ ends.sort()
199
+ for i in range(1, len(ends)):
200
+ ends[i][0] = max(ends[i][0], ends[i - 1][0] + 15)
201
+ return "".join(f'<text x="{lx:.1f}" y="{ly:.1f}" font-size="12.5" class="lab">{t}</text>' for ly, lx, t in ends)
202
+
203
+ y0 = 24
204
+ if top_h:
205
+ vals = [v for b in band for v in (b[1], b[3])] + [v for _, _, s in lines for _, v in s if v is not None]
206
+ lo, hi = min(vals), max(vals)
207
+ padv = (hi - lo) * .12 or 1
208
+ lo, hi = lo - padv, hi + padv
209
+ y = lambda v: y0 + top_h - (v - lo) / (hi - lo) * top_h
210
+ out.append(f'<text x="{pad_l - 34}" y="{y0 - 8}" class="lab" font-size="13">{esc(milk_words)}</text>')
211
+ for k in range(4):
212
+ v = lo + (hi - lo) * (k + .5) / 4
213
+ out.append(f'<line x1="{pad_l}" x2="{width - pad_r}" y1="{y(v):.1f}" y2="{y(v):.1f}" stroke="var(--subtle)"/>'
214
+ f'<text x="{pad_l - 6}" y="{y(v) + 4:.1f}" font-size="11" text-anchor="end">{v:.0f}</text>')
215
+ ends = []
216
+ for run in _runs(band):
217
+ up = " ".join(f"{x(d):.1f},{y(h):.1f}" for d, l, m, h in run)
218
+ dn = " ".join(f"{x(d):.1f},{y(l):.1f}" for d, l, m, h in reversed(run))
219
+ out.append(f'<polygon points="{up} {dn}" fill="var(--bar)" opacity=".75"/><polyline points="'
220
+ + " ".join(f"{x(d):.1f},{y(m):.1f}" for d, l, m, h in run)
221
+ + '" fill="none" stroke="var(--ink)" stroke-width="2.2"/>')
222
+ if band:
223
+ ends.append([y(band[-1][2]) + 4, x(band[-1][0]) + 6, f'<tspan font-weight="650">{band[-1][2]:.0f}</tspan> lb'])
224
+ for label, style, s in lines:
225
+ s = [(d, v) for d, v in s if v is not None and start <= d <= end]
226
+ if len(s) < 2:
227
+ continue
228
+ w, colour = ("2.4", "var(--ink)") if style == "bold" else ("1", "var(--line)")
229
+ out.append(f'<polyline points="{" ".join(f"{x(d):.1f},{y(v):.1f}" for d, v in s)}" fill="none" '
230
+ f'stroke="{colour}" stroke-width="{w}"/>')
231
+ if style == "bold":
232
+ ends.append([y(s[-1][1]) + 4, x(s[-1][0]) + 6, f'<tspan font-weight="650">{s[-1][1]:.1f}</tspan> lb'])
233
+ out.append(ends_text(ends))
234
+ y0 += top_h + gap
235
+ if low_h:
236
+ fed = [(d, v) for d, v in fed if start <= d <= end and v is not None]
237
+ # three-day average, so the stack reads as a level rather than noise
238
+ smooth = [(d, mean([v for _, v in fed[max(0, i - 2):i + 1]])) for i, (d, _) in enumerate(fed)]
239
+ ymax = max(v for _, v in smooth) * 1.1
240
+ step = 10 if ymax <= 60 else 20
241
+ y = lambda v: y0 + low_h - v / ymax * low_h
242
+ out.append(f'<text x="{pad_l - 34}" y="{y0 - 8}" class="lab" font-size="13">Intake, lb of dry matter a cow'
243
+ + (", and what's in it" if shares else "") + "</text>")
244
+ v = 0
245
+ while v <= ymax:
246
+ out.append(f'<line x1="{pad_l}" x2="{width - pad_r}" y1="{y(v):.1f}" y2="{y(v):.1f}" stroke="var(--subtle)"/>'
247
+ f'<text x="{pad_l - 6}" y="{y(v) + 4:.1f}" font-size="11" text-anchor="end">{v}</text>')
248
+ v += step
249
+ if shares:
250
+ last_share = None
251
+ stack = []
252
+ for d, total in smooth:
253
+ last_share = shares.get(d, last_share)
254
+ stack.append((d, total, last_share))
255
+ stack = [(d, tot, sh) for d, tot, sh in stack if sh]
256
+ base = {d: 0.0 for d, _, _ in stack}
257
+ ends = []
258
+ for key, label in LAYERS:
259
+ upper = [(d, base[d] + tot * sh.get(key, 0)) for d, tot, sh in stack]
260
+ pts_up = " ".join(f"{x(d):.1f},{y(v):.1f}" for d, v in upper)
261
+ pts_dn = " ".join(f"{x(d):.1f},{y(base[d]):.1f}" for d, _, _ in reversed(stack))
262
+ out.append(f'<polygon points="{pts_up} {pts_dn}" fill="var(--n-{key})"/>')
263
+ d_last, tot_last, sh_last = stack[-1]
264
+ mid = base[d_last] + tot_last * sh_last.get(key, 0) / 2
265
+ ends.append([y(mid) + 4, x(d_last) + 6, f'{esc(label)} <tspan font-weight="650">'
266
+ f'{tot_last * sh_last.get(key, 0):.1f}</tspan>'])
267
+ for d, tot, sh in stack:
268
+ base[d] += tot * sh.get(key, 0)
269
+ out.append(ends_text(ends))
270
+ else:
271
+ pts = " ".join(f"{x(d):.1f},{y(v):.1f}" for d, v in smooth)
272
+ out.append(f'<polygon points="{x(smooth[0][0]):.1f},{y(0):.1f} {pts} {x(smooth[-1][0]):.1f},{y(0):.1f}" '
273
+ f'fill="var(--feedwash)"/><polyline points="{pts}" fill="none" stroke="var(--feed)" stroke-width="1.6"/>'
274
+ f'<text x="{x(smooth[-1][0]) + 6:.1f}" y="{y(smooth[-1][1]) + 4:.1f}" font-size="12.5" class="lab">'
275
+ f'<tspan font-weight="650">{smooth[-1][1]:.1f}</tspan> fed</text>')
276
+ y_bottom = y(0)
277
+ else:
278
+ y_bottom = y0 - gap
241
279
  if change and start <= change <= end:
242
280
  cx = x(change)
243
- out.append(f'<line x1="{cx:.1f}" x2="{cx:.1f}" y1="{top - 6}" y2="{y(0):.1f}" stroke="var(--ink)" '
244
- f'stroke-dasharray="3 3"/><text x="{cx + 5:.1f}" y="{top - 8}" font-size="12.5" class="lab">'
281
+ out.append(f'<line x1="{cx:.1f}" x2="{cx:.1f}" y1="14" y2="{y_bottom:.1f}" stroke="var(--ink)" '
282
+ f'stroke-dasharray="3 3"/><text x="{cx + 5:.1f}" y="12" font-size="12.5" class="lab">'
245
283
  f'Ration change, {_fmt_date(change)}</text>')
246
284
  d = start
247
285
  while d <= end:
248
286
  if d.day in (1, 15):
249
287
  out.append(f'<text x="{x(d):.1f}" y="{height - 6}" font-size="11.5" text-anchor="middle">{_fmt_date(d)}</text>')
250
288
  d += timedelta(days=1)
251
- out.append("</svg>")
252
- return "".join(out)
289
+ return "".join(out) + "</svg>"
253
290
 
254
291
 
255
292
  def health_rows(health, cows: int) -> str:
@@ -459,86 +496,80 @@ def pen_card_html(herd: Herd, pen, pen_milk: dict | None = None, days: int = 75,
459
496
  intake_series = sorted((r["date"], r["dm_lb_per_head"] * (r["head_count"] or 0) / max(len(cows), 1)
460
497
  if r.get("head_count") else r["dm_lb_per_head"])
461
498
  for r in pen_days if r.get("dc_pen") == pen and start <= r["date"] <= end)
499
+ changes = _recipe_changes(herd, feed["ezfeed_pen"]) if feed else []
500
+ change = changes[-1][0] if changes else None
501
+ # The pen's place among the milking pens, by ECM (or milk where the herd doesn't test).
502
+ by_pen = defaultdict(list)
503
+ for c in herd.in_herd():
504
+ if herd.status(c) == "milking" and (c.get("test_milk") or 0) > 0:
505
+ e = ecm_lb(c["test_milk"], c.get("test_fat_pct"), c.get("test_protein_pct"))
506
+ by_pen[c["pen"]].append(e if e is not None else c["test_milk"])
507
+ means = sorted(((mean(v), k) for k, v in by_pen.items() if len(v) >= 5), reverse=True)
508
+ place = next((i for i, (_, k) in enumerate(means, 1) if k == pen), None)
509
+ rank = ("Highest" if place == 1 else ordinal_word(place)) + f" of {len(means)} pens" if place and len(means) > 1 else ""
510
+ # Called for: EZfeed's target, on the same per-cow footing as the intake.
511
+ called = None
512
+ if feed and feed.get("dmi_lb_per_cow"):
513
+ week = [r for r in herd.feed.get("feed_delivery", []) if r["pen"] == feed["ezfeed_pen"] and not r.get("premix")
514
+ and end - timedelta(days=6) <= r["date"] <= end]
515
+ tgt = sum(r.get("target_dm_lb_per_head") or 0 for r in week)
516
+ act = sum(r.get("actual_dm_lb_per_head") or 0 for r in week)
517
+ if tgt and act:
518
+ called = feed["dmi_lb_per_cow"] * tgt / act
462
519
  tiles = [
463
520
  (f"Milk per cow, {herd.milk_words}", f"{t['milk_mean_lb']:.1f} lb" if t["milk_mean_lb"] else "n/a",
464
521
  f"ECM {t['ecm_mean_lb']:.1f} lb" if t["ecm_mean_lb"] else "",
465
522
  violin(milk_vals, f"milk, {herd.milk_words}", " lb"),
466
- f"Middle 80%: {quantile(milk_vals, .1):.0f}–{quantile(milk_vals, .9):.0f} lb · {t['tested']} of {t['of']} cows"
467
- if milk_vals else "No tests"),
523
+ " · ".join(x for x in (rank, f"middle 80%: {quantile(milk_vals, .1):.0f}–{quantile(milk_vals, .9):.0f} lb"
524
+ if milk_vals else "no milk recorded") if x)),
468
525
  ("Days in milk", f"{quantile(dim_vals, .5):.0f}" if dim_vals else "n/a", "median",
469
526
  violin(dim_vals, "days in milk"),
470
527
  f"Middle 80%: {quantile(dim_vals, .1):.0f}–{quantile(dim_vals, .9):.0f} days" if dim_vals else ""),
471
528
  ("Lactation", f"{median_lact:.0f}" if median_lact else "n/a", "median", lact_bar(lact),
472
529
  " · ".join(f"{l} {n}" for l, n in lact)),
473
530
  ("Intake, last 7 days", f"{feed['dmi_lb_per_cow']:.1f} lb" if feed and feed.get("dmi_lb_per_cow") else "n/a",
474
- "DM per cow", spark(intake_series[-30:]), "Daily, the last 30 days" if intake_series else "No EZfeed records"),
531
+ "DM per cow", spark(intake_series[-30:]),
532
+ (f"Called for {called:.1f} lb · daily, last 30 days" if called else "Daily, the last 30 days")
533
+ if intake_series else "No EZfeed records"),
475
534
  ]
476
535
  tile_html = "".join(f'<div class="tile"><div class="k">{esc(k)}</div><div class="v">{esc(v)}<small>{esc(s)}</small>'
477
536
  f'</div>{chart}<div class="n">{esc(n)}</div></div>' for k, v, s, chart, n in tiles)
478
- # Charts: ECM per cow by day (this fall, and the same days last fall), intake per cow by day.
479
- changes = _recipe_changes(herd, feed["ezfeed_pen"]) if feed else []
480
- change = changes[-1][0] if changes else None
481
- rows = []
482
- if pen_milk:
483
- def ecm_series(year_shift):
484
- out = []
485
- d = start
486
- while d <= end:
487
- src = _shift_years(d, year_shift)
488
- v = pen_milk.get((pen, src))
489
- e = ecm_lb(v["milk_lb"], v["fat_pct"], v["protein_pct"]) if v and v.get("fat_pct") else None
490
- out.append((d, e))
491
- d += timedelta(days=1)
492
- return out
493
- this, last = ecm_series(0), ecm_series(-1)
494
- rows.append(("ECM, lb per cow", "lb", [("this fall", "thin", this), ("this fall", "bold", _week_avg(this)),
495
- ("last fall", "dashed", _week_avg(last))]))
496
- # One plot, one pound scale: milk (each day's middle cow, or the pen's ECM) and the dry matter fed a cow.
537
+ # Milk above: each day's middle cow and middle 80% (daily weights), or the pen's ECM by day; intake below as a stack.
497
538
  band = sorted((d, v["low"], v["mid"], v["high"]) for (p, d), v in herd.pen_milk_days.items()
498
539
  if p == pen and start <= d <= end)
499
540
  band = band if len(band) >= 2 else []
500
- lines = rows[0][2] if rows else []
501
- title = ("ECM and dry matter fed, lb per cow" if lines and not band else "Milk and dry matter fed, lb per cow"
502
- if band or lines else "Dry matter fed, lb per cow")
541
+ lines = []
542
+ if pen_milk and not band:
543
+ ecm = []
544
+ d = start
545
+ while d <= end:
546
+ v = pen_milk.get((pen, d))
547
+ ecm.append((d, ecm_lb(v["milk_lb"], v["fat_pct"], v["protein_pct"]) if v and v.get("fat_pct") else None))
548
+ d += timedelta(days=1)
549
+ lines = [("daily", "thin", ecm), ("7-day", "bold", _week_avg(ecm))]
550
+ shares, how = ({}, {})
551
+ if feed:
552
+ analyses = {}
553
+ for f in herd.files:
554
+ if f["kind"] == "analyses":
555
+ analyses.update(nutrients.read_analyses(f["path"]))
556
+ shares, how = nutrients.pen_layers_by_day(herd, feed["ezfeed_pen"], analyses)
503
557
  # A slide draws the chart narrower, so its words come out bigger.
504
- chart = day_plot(title, start, end, change, band=band, lines=[] if band else lines, fed=intake_series,
505
- width=560 if slide else 760)
506
- # Side: the current ration as bars, and the season beside the last change.
558
+ chart = pen_panels(start, end, change, band=band, lines=lines, fed=intake_series, shares=shares,
559
+ milk_words=("ECM, lb a cow" if lines else "Milk, lb a cow: the middle cow (shading: the middle 80%)"),
560
+ width=560 if slide else 760)
561
+ what_in = nutrients.source_words(how) if shares else ""
562
+ if chart and what_in:
563
+ chart += f"<div class='sub'>{esc(what_in)}</div>"
564
+ # Side: the current ration as bars.
507
565
  side = []
508
- ecm_since = ""
509
566
  if feed: # the pen's current ration; the chart marks when it last changed
510
567
  recipe = _recipe(herd, feed["ezfeed_pen"], end - timedelta(days=6), end)
511
568
  if recipe:
512
569
  side.append(f"<h2>Ration, last 7 days</h2><div class='sub'>lb of dry matter per cow, called for</div>"
513
570
  f"<div class='rbars'>{ration_bars(recipe)}</div>")
514
- if pen_milk and change:
515
- def wk(year_shift, a, b):
516
- vals = []
517
- dd = a
518
- while dd <= b:
519
- v = pen_milk.get((pen, _shift_years(dd, year_shift)))
520
- if v and v.get("fat_pct"):
521
- vals.append(ecm_lb(v["milk_lb"], v["fat_pct"], v["protein_pct"]))
522
- dd += timedelta(days=1)
523
- return mean(vals)
524
- before = (change - timedelta(days=7), change - timedelta(days=1))
525
- after = (end - timedelta(days=6), end)
526
- now = wk(0, *after) - wk(0, *before) if wk(0, *after) and wk(0, *before) else None
527
- then = wk(-1, *after) - wk(-1, *before) if wk(-1, *after) and wk(-1, *before) else None
528
- if now is not None and then is not None:
529
- note = f"The week before against the week to {_fmt_date(end)}, per cow"
530
- if slide: # the slide's point, as big figures under the chart
531
- ecm_since = (f"<h2>ECM since {_fmt_date(change)}</h2><div class='figs'>"
532
- f"<div><div class='k'>This fall</div><div class='v'>{now:+.1f} lb</div></div>"
533
- f"<div><div class='k'>Last fall, no change</div><div class='v'>{then:+.1f} lb</div></div>"
534
- f"<div><div class='k'>Left for the ration</div><div class='v'>{now - then:+.1f} lb</div>"
535
- f"</div></div><div class='sub'>{note}</div>")
536
- else:
537
- side.append(f"<h2>ECM since {_fmt_date(change)}</h2><div class='chips'>"
538
- f"{chip('This fall', f'{now:+.1f} lb')}{chip('Last fall, no change', f'{then:+.1f} lb')}"
539
- f"</div><div class='sub'>{note}</div>")
540
- # Feed and health go under the charts, so both columns end together; a slide has only the ECM figures there.
541
- below = [ecm_since] if ecm_since else []
571
+ # Feed and health go under the charts, so both columns end together; a slide leaves them out.
572
+ below = []
542
573
  if pc["health"] and not slide:
543
574
  below.append(f"<h2>Health, last {pc['days']} days</h2><div class='sub'>Cows in the pen now with each "
544
575
  f"event</div>{health_rows(pc['health'], len(cows))}")
@@ -0,0 +1,11 @@
1
+ # nasem_feeds.csv
2
+
3
+ Feed composition (% of dry matter: NDF, starch, crude protein, fatty acids, water-soluble carbohydrates, ash; dry
4
+ matter as % as fed) for the 284 feeds of the feed library of the National Academies of Sciences, Engineering, and
5
+ Medicine (2021), *Nutrient Requirements of Dairy Cattle*, 8th revised edition, taken from the library distributed with
6
+ the nasem_dairy package (Fieguth, Innes and Cant, University of Guelph).
7
+
8
+ These values are NASEM's, not this project's, and are not covered by this project's Apache-2.0 licence. NASEM's terms:
9
+ academic use is encouraged with appropriate acknowledgment; commercial use requires a copyright release from NASEM.
10
+ Dairy Data Tools uses them as book values, non-commercially, to show what a ration holds where the farm has no analyses
11
+ of its own, and says so on every card that uses them.
@@ -0,0 +1,285 @@
1
+ name,category,dm,ndf,starch,cp,fa,wsc,ash
2
+ "Zinc, organic generic",Vitamin/Mineral,98.00,0.00,0.00,0.00,0.00,0.00,80.00
3
+ Calf grower 14CP (Fed to calves only),Energy Source,88.00,18.00,0.00,16.00,2.00,,5.00
4
+ Calf grower 16CP (Fed to calves only),Energy Source,87.70,24.79,15.10,18.80,5.80,4.20,8.03
5
+ Calf starter 18CP high starch (Fed to calves only),Energy Source,88.00,17.37,37.92,20.60,3.00,7.68,8.01
6
+ Calf starter 18CP low starch (Fed to calves only),Energy Source,87.50,29.50,20.70,20.70,3.80,3.50,9.12
7
+ Calf starter 22CP high starch (Fed to calves only),Energy Source,89.00,13.65,32.89,24.95,2.20,9.22,8.79
8
+ Calf starter 22CP med starch (Fed to calves only),Energy Source,87.80,16.33,25.50,24.70,2.30,12.00,7.00
9
+ Casein,Calf Liquid Feed,91.00,0.00,0.00,92.70,0.00,0.00,4.00
10
+ Milk replacer 20 CP 20 fat,Calf Liquid Feed,12.50,0.00,0.00,20.80,20.00,52.40,6.00
11
+ Milk replacer 26 CP 17 fat,Calf Liquid Feed,13.00,0.00,0.00,27.10,17.00,49.20,6.00
12
+ Milk replacer 28 CP 17.5 fat,Calf Liquid Feed,15.00,0.00,0.00,29.20,18.00,45.60,7.00
13
+ "Skim milk, fresh",Calf Liquid Feed,10.00,0.00,0.00,35.50,0.40,42.00,6.90
14
+ "Skim milk, powder",Calf Liquid Feed,94.00,0.00,0.00,37.40,0.80,56.00,6.90
15
+ Whey protein concentrate,Calf Liquid Feed,93.00,0.00,0.00,37.10,,,5.95
16
+ "Whey, delactosed",Calf Liquid Feed,93.00,0.00,0.00,17.90,,,16.50
17
+ "Whey, fresh",Calf Liquid Feed,7.00,0.00,0.00,14.20,,,8.70
18
+ "Whey, permeate",Calf Liquid Feed,98.00,0.00,0.00,3.70,,,9.00
19
+ Whole milk,Calf Liquid Feed,12.50,0.00,0.00,25.40,28.90,,6.30
20
+ Alfalfa meal,Plant Protein,90.75,42.85,1.83,19.51,1.61,8.26,11.66
21
+ Almond hulls,By-Product/Other,88.20,33.01,0.93,5.25,1.26,36.42,7.62
22
+ Ammonium chloride,Vitamin/Mineral,100.00,0.00,0.00,163.60,0.00,0.00,100.00
23
+ Ammonium phosphate (dibasic),Vitamin/Mineral,100.00,0.00,0.00,115.90,0.00,0.00,36.00
24
+ Ammonium phosphate (monobasic),Vitamin/Mineral,100.00,0.00,0.00,70.90,0.00,0.00,36.00
25
+ Ammonium sulfate,Vitamin/Mineral,100.00,,,134.10,,,33.00
26
+ "Apple pomace or byproduct, wet",By-Product/Other,18.23,45.73,3.52,6.42,1.88,25.53,2.92
27
+ Bakery byproduct,By-Product/Other,90.13,12.66,51.67,12.83,7.68,19.00,4.37
28
+ "Bakery byproduct, bread waste",By-Product/Other,67.44,6.34,53.46,14.90,4.76,11.42,3.57
29
+ "Bakery byproduct, cereal",By-Product/Other,91.14,7.20,47.63,9.20,1.95,28.07,3.54
30
+ "Bakery byproduct, cookies",By-Product/Other,89.27,14.44,36.21,12.94,9.04,18.16,4.59
31
+ "Barley grain, dry, ground",Energy Source,88.74,18.63,56.67,11.81,1.31,4.91,2.82
32
+ "Barley grain, steam rolled",Energy Source,88.74,18.63,56.67,11.81,1.31,4.91,2.82
33
+ Barley hay,Grain Crop Forage,89.40,54.51,7.29,10.75,1.41,14.83,8.64
34
+ Barley malt sprouts,By-product/Other,81.16,40.52,8.56,23.88,1.46,15.90,5.87
35
+ "Barley silage, headed",Grain Crop Forage,36.96,44.76,23.87,10.88,2.06,7.00,5.92
36
+ "Barley silage, mid-maturity",Grain Crop Forage,36.12,52.88,12.30,11.36,1.70,5.93,7.89
37
+ "Barley silage, vegetative",Grain Crop Forage,32.96,56.61,2.99,14.22,2.07,6.88,10.69
38
+ "Beet pulp, dry",By-Product/Other,92.30,46.85,0.64,9.92,0.63,5.70,5.24
39
+ "Beet pulp, dry, molasses added",By-Product/Other,90.62,39.70,1.15,8.91,0.63,13.78,7.48
40
+ "Beet pulp, wet",By-Product/Other,22.72,44.10,0.90,9.12,0.64,2.98,7.34
41
+ Bermudagrass hay,Grass/Legume Forage,93.37,65.41,4.89,10.99,1.25,7.71,8.04
42
+ "Bermudagrass silage, mature",Grass/Legume Forage,45.29,70.85,3.37,10.27,1.35,3.97,6.20
43
+ "Bermudagrass silage, mid-mtr",Grass/Legume Forage,38.41,64.11,2.36,14.59,1.44,5.00,9.13
44
+ "Blood meal, high dRUP",Animal Protein,90.86,0.00,0.00,95.06,1.31,0.00,3.25
45
+ "Blood meal, low dRUP",Animal Protein,90.86,0.00,0.00,95.06,1.31,0.00,3.25
46
+ Bone meal,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,79.00
47
+ "Brewers grains, dry",By-Product/Other,93.12,51.77,6.45,25.33,8.31,3.78,4.58
48
+ "Brewers grains, wet",By-Product/Other,22.46,49.29,5.17,28.09,7.61,2.01,4.56
49
+ "Brewers yeast, dry",By-Product/Other,92.76,1.63,4.08,50.72,2.34,4.05,8.62
50
+ "Brewers yeast, wet",By-Product/Other,13.36,11.46,4.40,43.31,2.34,14.00,6.35
51
+ Calcium carbonate,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
52
+ Calcium chloride,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
53
+ Calcium chloride (2H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
54
+ Calcium hydroxide,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
55
+ Calcium iodate,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
56
+ Calcium oxide,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
57
+ Calcium phosphate (di),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
58
+ Calcium phosphate (mono),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
59
+ Calcium soaps,Fatty Acid Supplement,95.30,0.00,0.00,0.00,84.50,0.00,15.50
60
+ Calcium sulfate (2H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
61
+ Candy (not chocolate) byproduct,By-Product/Other,90.08,2.29,23.46,2.37,0.25,60.00,1.04
62
+ "Candy byproduct, high protein",By-Product/Other,88.88,29.72,16.05,14.63,11.11,15.00,5.56
63
+ Canola meal,Plant Protein,89.13,28.96,1.57,41.49,2.51,11.01,7.88
64
+ "Canola seed, ground",Plant Protein,94.96,28.73,2.42,23.36,39.46,6.00,4.50
65
+ Chocolate byproduct,By-Product/Other,94.28,13.22,11.17,10.00,20.68,39.58,2.57
66
+ "Citrus pulp, dry",By-Product/Other,88.20,24.07,1.27,7.18,1.72,23.04,7.07
67
+ "Citrus pulp, wet",By-Product/Other,18.32,25.91,0.92,8.66,1.72,11.50,6.83
68
+ Cobalt carbonate,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
69
+ Cobalt carbonate (6H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
70
+ Cobalt chloride (6H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
71
+ Cobalt organic generic,Vitamin/Mineral,98.00,0.00,0.00,0.00,0.00,0.00,80.00
72
+ Cobalt sulfate (7H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
73
+ "Cool season grass hay, mature",Grass/Legume Forage,89.85,66.67,2.02,9.23,0.95,10.80,6.71
74
+ "Cool season grass hay, mid-mtr",Grass/Legume Forage,88.33,58.01,2.22,13.28,1.58,15.23,8.57
75
+ Cool season grass silage,Grass/Legume Forage,38.84,62.07,1.94,13.42,1.83,7.29,8.08
76
+ Copper chloride (2H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
77
+ "Copper organic, generic",Vitamin/Mineral,98.00,0.00,0.00,0.00,0.00,0.00,80.00
78
+ Copper oxide,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
79
+ Copper sulfate (5H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
80
+ "Corn and cob meal, dry",Energy Source,86.35,19.02,62.12,8.41,3.26,4.45,1.86
81
+ Corn cobs,By-Product/Other,89.83,83.79,1.13,2.97,0.35,1.07,2.75
82
+ Corn germ,Plant Protein,90.16,27.01,27.59,15.42,16.89,3.00,5.87
83
+ Corn germ meal,Plant Protein,90.24,44.75,19.36,26.14,2.11,3.89,3.66
84
+ "Corn gluten feed, dry",By-Product/Other,89.16,35.68,15.51,23.19,3.38,5.83,7.50
85
+ "Corn gluten feed, wet",By-Product/Other,45.62,36.87,15.26,23.11,3.09,4.02,7.17
86
+ Corn gluten meal,Plant Protein,90.53,6.83,16.40,68.52,1.44,1.63,2.78
87
+ "Corn grain dry, coarse grind",Energy Source,86.91,9.76,70.37,8.51,3.84,2.88,1.50
88
+ "Corn grain dry, fine grind",Energy Source,86.91,9.76,70.37,8.51,3.84,2.88,1.50
89
+ "Corn grain dry, medium grind",Energy Source,86.91,9.76,70.37,8.51,3.84,2.88,1.50
90
+ "Corn grain HM, coarse grind",Energy Source,72.27,9.58,70.93,8.51,3.57,2.98,1.57
91
+ "Corn grain HM, fine grind",Energy Source,72.27,9.58,70.93,8.51,3.57,2.98,1.57
92
+ Corn grain screenings,Energy Source,86.94,11.72,65.59,8.56,3.18,2.81,1.76
93
+ "Corn grain, steam-flaked",Energy Source,85.74,8.64,71.74,8.00,3.14,1.80,1.29
94
+ Corn hominy feed,Energy Source,89.09,16.90,55.65,10.06,5.38,4.82,2.61
95
+ "Corn silage, immature",Grain Crop Forage,31.27,42.59,30.18,7.91,2.32,2.88,4.04
96
+ "Corn silage, mature",Grain Crop Forage,39.60,39.30,35.54,7.47,2.36,3.05,3.66
97
+ "Corn silage, typical",Grain Crop Forage,35.36,40.93,32.87,7.71,2.35,2.97,3.84
98
+ "Corn stalks, ensiled, high DM",Grain Crop Forage,84.97,72.00,3.67,5.61,0.48,5.91,9.01
99
+ "Corn stalks, ensiled, low DM",Grain Crop Forage,41.24,66.23,3.55,7.00,0.72,5.23,10.55
100
+ "Corn, ear w husk, stlk, hi fbr",Energy Source,57.96,24.89,56.72,7.95,2.89,1.83,2.11
101
+ "Corn, ear, huks, stlk, low fbr",Energy Source,64.83,18.11,64.65,7.83,3.11,1.88,1.73
102
+ Cotton gin trash,By-Product/Other,90.25,59.35,1.12,11.98,3.14,2.22,14.55
103
+ Cottonseed hulls,By-Product/Other,91.00,80.92,1.23,6.97,3.14,2.15,3.46
104
+ Cottonseed meal,Plant Protein,89.92,28.05,1.09,46.69,3.06,8.48,7.62
105
+ "Cottonseed, whole",Plant Protein,91.36,50.58,0.76,23.32,18.26,4.00,4.21
106
+ "DDGS, high fat",By-Product/Other,89.06,32.11,4.51,30.20,11.39,4.56,5.39
107
+ "DDGS, high protein",By-Product/Other,91.07,37.60,6.20,38.98,6.56,5.42,4.04
108
+ "DDGS, low fat",By-Product/Other,89.95,30.85,6.11,30.97,7.90,7.96,5.34
109
+ DGS modified,By-Product/Other,49.21,27.10,4.67,30.28,8.35,9.67,5.58
110
+ DGS wet,By-Product/Other,33.22,31.68,6.35,31.45,8.31,7.32,4.50
111
+ Distillers solubles,By-Product/Other,31.20,4.83,4.00,22.58,9.99,28.74,11.10
112
+ Dolomite limestone (magnesium),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
113
+ EDDI,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
114
+ "Fat, canola oil",Fat Supplement,99.00,0.00,0.00,0.00,88.00,0.00,0.00
115
+ "Fat, corn oil",Fat Supplement,99.00,0.00,0.00,0.00,88.00,0.00,0.00
116
+ "Fat, cottonseed oil",Fat Supplement,99.00,0.00,0.00,0.00,88.00,0.00,0.00
117
+ "Fat, flaxseed oil",Fat Supplement,99.00,0.00,0.00,0.00,88.00,0.00,0.00
118
+ "Fat, lard",Fat Supplement,99.00,0.00,0.00,0.00,88.00,0.00,0.00
119
+ "Fat, safflower oil",Fat Supplement,99.00,0.00,0.00,0.00,88.00,0.00,0.00
120
+ "Fat, soybean oil",Fat Supplement,99.00,0.00,0.00,0.00,88.00,0.00,0.00
121
+ "Fat, sunflower oil",Fat Supplement,99.00,0.00,0.00,0.00,88.00,0.00,0.00
122
+ "Fat, tallow",Fat Supplement,99.80,0.00,0.00,0.00,88.00,0.00,0.00
123
+ Feather meal,Animal Protein,92.87,0.00,0.00,90.55,7.85,0.00,2.31
124
+ Ferrous carbonate,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
125
+ Ferrous sulfate (7H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
126
+ Ferrous sulfate (H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
127
+ Fish meal,Animal Protein,92.03,0.00,0.00,69.19,6.44,0.00,21.12
128
+ Flaxseed,Plant Protein,92.69,30.44,2.39,22.79,33.41,3.93,4.03
129
+ Flaxseed meal,Plant Protein,89.65,30.43,2.06,38.48,3.08,5.89,6.77
130
+ "Fruit and vegetable byprod, wet",By-Product/Other,19.77,28.68,10.06,13.62,6.13,31.22,8.37
131
+ Glycerol,Energy Source,80.00,0.00,0.00,0.84,5.24,1.40,6.69
132
+ "Grain screenings, source unknwn",By-Product/Other,89.15,34.08,21.80,16.18,2.91,5.00,6.02
133
+ Grain sorghum hay,Grain Crop Forage,92.58,48.08,22.21,8.81,1.36,7.26,7.01
134
+ "Grain sorghum silage, mature",Grain Crop Forage,31.32,45.74,23.19,8.22,1.93,11.05,5.95
135
+ "Grain sorghum silage, midmtr",Grain Crop Forage,29.75,53.12,14.28,8.89,1.56,4.87,8.06
136
+ "Grass legume mixt, grass slg",Grass/Legume Forage,39.61,57.73,2.61,14.34,1.98,8.00,8.12
137
+ "Grass lg mixt, grass hay, mid",Grass/Legume Forage,89.24,54.69,1.53,15.61,1.93,12.62,9.41
138
+ "Grass lg mixt, grass hay, mtr",Grass/Legume Forage,87.40,61.99,2.54,10.85,1.29,10.91,7.49
139
+ "Grass lg mixt, leg. hay, mtr",Grass/Legume Forage,85.29,51.17,2.55,17.38,1.23,5.00,9.01
140
+ "Grass lg mixt, leg., hay, immtr",Grass/Legume Forage,88.56,43.94,1.89,20.35,1.78,9.00,10.02
141
+ "Grass lg mixt, legume slg",Grass/Legume Forage,40.98,45.93,2.10,20.04,1.99,6.58,10.27
142
+ "Grass lg mixt, mix hay",Grass/Legume Forage,86.44,58.24,2.75,12.12,1.37,10.08,9.24
143
+ "Grass lg mixt, mix silage",Grass/Legume Forage,40.02,51.23,2.12,17.68,2.03,8.08,9.52
144
+ Iron oxide,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
145
+ "Iron, organic generic",Vitamin/Mineral,95.00,0.00,0.00,0.00,0.00,0.00,80.00
146
+ "Legume hay, immature",Grass/Legume Forage,89.28,37.68,2.28,21.54,1.54,9.75,11.05
147
+ "Legume hay, mature",Grass/Legume Forage,87.65,46.65,2.27,18.11,1.21,9.77,9.97
148
+ "Legume hay, mid-maturity",Grass/Legume Forage,88.14,41.11,1.51,20.75,1.50,8.97,10.76
149
+ "Legume silage, immature",Grass/Legume Forage,41.61,38.75,1.91,22.06,1.98,7.32,11.12
150
+ "Legume silage, mid-maturity",Grass/Legume Forage,42.88,43.20,1.97,20.47,2.32,6.27,10.60
151
+ Limestone,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
152
+ Magnesium carbonate,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
153
+ Magnesium chloride (6H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
154
+ Magnesium hydroxide,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
155
+ Magnesium oxide,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
156
+ Magnesium sulfate (7H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
157
+ Manganese carbonate,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
158
+ Manganese chloride,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
159
+ Manganese chloride (4H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
160
+ Manganese organic generic,Vitamin/Mineral,98.00,0.00,0.00,0.00,0.00,0.00,80.00
161
+ Manganese oxide,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
162
+ Manganese sulfate (5H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
163
+ Manganese sulfate (H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
164
+ "Meat and bone meal, porcine",Animal Protein,96.06,0.00,0.00,56.63,7.45,0.00,26.18
165
+ Millet hay,Grass/Legume Forage,87.46,61.86,2.90,10.74,1.09,8.41,11.15
166
+ Millet silage,Grass/Legume Forage,29.32,59.67,3.50,13.02,1.47,6.21,11.74
167
+ Molasses,Energy Source,65.39,0.57,0.85,9.27,0.00,60.00,15.96
168
+ Oat grain,Energy Source,89.27,28.56,44.72,12.17,4.80,2.95,3.21
169
+ Oat hay mid-maturity,Grain Crop Forage,89.50,58.97,4.08,8.49,1.45,17.75,7.39
170
+ Oat hulls,By-Product/Other,91.39,73.62,10.57,5.01,1.82,0.95,5.76
171
+ "Oat silage, immature",Grass/Legume Forage,33.66,45.76,1.75,18.51,2.24,4.35,13.37
172
+ "Oat silage, mid-maturity",Grain Crop Forage,35.85,57.38,3.18,12.92,1.77,6.72,10.36
173
+ Oystershell,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
174
+ "Pasture, grass",Pasture,19.30,41.80,2.10,25.10,2.32,14.60,9.60
175
+ "Pasture, grass-legume mixture",Pasture,19.30,41.80,2.10,25.10,2.32,14.60,9.60
176
+ "Pasture, legume",Pasture,13.90,32.40,3.10,26.10,2.00,8.70,9.62
177
+ Pea hay,Grass/Legume Forage,89.48,43.37,8.56,15.90,1.69,9.01,9.08
178
+ Pea silage,Grass/Legume Forage,31.65,52.46,3.36,17.04,1.68,4.48,11.38
179
+ Peanut hay,Grass/Legume Forage,91.26,45.80,3.98,12.01,1.30,10.28,10.43
180
+ Peanut hulls,By-Product/Other,93.99,69.55,1.33,8.89,3.21,3.48,4.59
181
+ "Peanut meal, expellers",Plant Protein,93.96,22.90,6.39,42.62,7.31,5.00,6.48
182
+ Peanut skins,By-Product/Other,92.38,47.43,3.22,16.20,18.61,11.90,3.16
183
+ Peanuts,Plant Protein,94.13,24.01,2.76,25.55,41.24,5.00,3.01
184
+ Peas,Plant Protein,88.89,12.15,43.01,24.28,1.14,8.34,3.62
185
+ "Phosphate, Curacao",Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
186
+ "Phosphate, defluorinated",Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
187
+ "Phosphate, monosodium (H2O)",Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
188
+ Phosphoric acid,Vitamin/Mineral,75.00,0.00,0.00,0.00,0.00,0.00,100.00
189
+ Pineapple cannery waste,By-Product/Other,23.41,62.35,3.45,7.02,0.94,8.22,6.07
190
+ Potassium bicarbonate,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
191
+ Potassium carbonate,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
192
+ Potassium chloride,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
193
+ Potassium iodide,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
194
+ Potassium sulfate,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
195
+ Potato byproduct,By-Product/Other,22.98,14.43,57.49,9.99,1.78,7.10,5.60
196
+ Poultry byproduct meal,Animal Protein,95.52,0.00,0.00,65.62,11.78,0.00,14.25
197
+ Rice bran,By-Product/Other,92.38,23.05,22.18,14.81,12.00,7.95,10.02
198
+ "Rice bran, defatted",By-Product/Other,89.49,25.92,21.48,18.54,2.16,9.70,12.33
199
+ Rice hulls,By-Product/Other,90.95,75.13,7.59,3.69,0.27,1.00,17.43
200
+ "Rice silage, headed",Grain Crop Forage,41.07,41.89,32.15,7.12,1.62,2.00,12.52
201
+ "Rice silage, vegetative",Grain Crop Forage,42.93,61.49,7.60,8.27,1.47,1.77,16.17
202
+ "Rice, grain",Energy Source,87.87,6.39,75.84,8.11,1.24,1.44,1.82
203
+ Rumen Protected Arg,Additive,98.00,0.00,0.00,75.00,0.00,0.00,0.00
204
+ Rumen Protected His,Additive,98.00,0.00,0.00,75.00,0.00,0.00,0.00
205
+ Rumen Protected Ile,Additive,98.00,0.00,0.00,75.00,0.00,0.00,0.00
206
+ Rumen Protected Leu,Additive,98.00,0.00,0.00,75.00,0.00,0.00,0.00
207
+ Rumen Protected Lys,Additive,98.00,0.00,0.00,75.00,0.00,0.00,0.00
208
+ Rumen Protected Met,Additive,98.00,0.00,0.00,75.00,0.00,0.00,0.00
209
+ Rumen Protected Phe,Additive,98.00,0.00,0.00,75.00,0.00,0.00,0.00
210
+ Rumen Protected Thr,Additive,98.00,0.00,0.00,75.00,0.00,0.00,0.00
211
+ Rumen Protected Trp,Additive,98.00,0.00,0.00,75.00,0.00,0.00,0.00
212
+ Rumen Protected Val,Additive,98.00,0.00,0.00,75.00,0.00,0.00,0.00
213
+ "Rye annual fresh, immature",Grain Crop Forage,15.75,42.91,4.94,27.50,3.07,5.84,10.94
214
+ "Rye annual fresh, mid-maturity",Grain Crop Forage,19.46,49.14,4.94,20.48,2.44,7.70,9.75
215
+ "Rye annual hay, immature",Grain Crop Forage,90.04,47.04,1.99,22.89,2.53,12.78,11.06
216
+ "Rye annual hay, mature",Grain Crop Forage,92.70,66.83,2.01,7.62,1.00,12.73,6.29
217
+ "Rye annual hay, mid-maturity",Grain Crop Forage,90.33,57.27,2.21,11.98,1.47,14.03,9.35
218
+ "Rye annual silage, immature",Grain Crop Forage,34.71,50.47,1.66,16.41,1.95,14.00,11.05
219
+ "Rye annual silage, mature",Grain Crop Forage,67.19,66.21,1.45,8.28,1.25,12.33,8.72
220
+ "Rye annual silage, mid-maturity",Grain Crop Forage,34.88,58.03,1.48,14.43,1.68,8.76,10.27
221
+ Rye grain,Energy Source,85.96,16.03,57.62,11.80,1.45,8.00,2.58
222
+ Safflower meal,Plant Protein,93.98,55.40,1.21,26.21,3.88,5.10,4.92
223
+ "Selenate, sodium (10 H2O)",Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
224
+ "Selenite, sodium",Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
225
+ "Selenium yeast, generic",Vitamin/Mineral,99.00,0.00,0.00,0.00,0.00,0.00,50.00
226
+ Sodium bicarbonate,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
227
+ Sodium carbonate (H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
228
+ Sodium chloride (salt),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
229
+ Sodium sesquicarbonate (2H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
230
+ Sodium sulfate,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
231
+ Sodium tripolyphosphate,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
232
+ "Sorghum forage silage, immature",Grain Crop Forage,29.18,56.70,8.05,11.74,1.74,4.26,10.66
233
+ "Sorghum forage silage, mature",Grain Crop Forage,28.72,61.57,2.73,11.30,1.44,5.27,9.90
234
+ "Sorghum grain, dry, ground",Energy Source,88.89,6.13,72.59,12.48,2.92,2.23,2.50
235
+ "Sorghum grain, steam flaked",Energy Source,88.89,6.13,72.59,12.48,2.92,2.23,2.50
236
+ Sorghum hay,Grain Crop Forage,91.36,63.04,3.24,10.18,1.24,10.28,8.46
237
+ Sorghum soybean silage,Grain Crop Forage,32.33,54.40,9.95,11.66,1.81,4.21,9.17
238
+ Sorghum-sudangrass hay,Grain Crop Forage,90.47,61.02,3.75,9.81,1.10,10.36,10.04
239
+ Sorghum-sudangrass silage,Grain Crop Forage,31.71,59.47,2.79,12.25,1.63,5.63,10.90
240
+ Soybean hay,Grass/Legume Forage,91.58,40.28,5.73,20.08,1.91,7.78,9.04
241
+ Soybean hulls,By-Product/Other,90.37,66.75,0.98,11.88,1.61,2.75,5.18
242
+ "Soybean meal, expellers",Plant Protein,91.17,19.59,1.80,47.60,6.12,11.82,6.73
243
+ "Soybean meal, extruded",Plant Protein,93.36,18.35,1.49,40.43,15.08,9.31,5.66
244
+ "Soybean meal, solvent 48CP",Plant Protein,89.27,11.06,1.88,52.64,1.08,12.95,7.24
245
+ Soybean silage,Grass/Legume Forage,37.48,45.27,4.46,17.99,2.86,4.32,10.08
246
+ "Soybeans, whole raw",Plant Protein,89.11,11.88,4.17,39.98,16.99,9.00,5.31
247
+ "Soybeans, whole roasted",Plant Protein,94.04,18.36,1.54,40.02,15.35,9.79,5.56
248
+ Spelt grain,Energy Source,87.44,39.33,41.27,12.90,1.66,5.00,4.82
249
+ "Sudangrass hay, mature",Grass/Legume Forage,93.06,65.80,1.51,8.08,0.98,9.95,9.55
250
+ "Sudangrass hay, mid-maturity",Grass/Legume Forage,83.08,54.60,1.97,14.73,1.04,10.00,15.03
251
+ "Sudangrass silage, mature",Grass/Legume Forage,31.47,66.62,2.15,9.54,1.53,4.01,10.60
252
+ "Sudangrass silage, mid-maturity",Grass/Legume Forage,31.52,60.68,1.83,13.37,1.61,5.22,12.26
253
+ Sugar,Sugar/Sugar Alcohol,99.00,0.00,0.00,0.00,0.00,100.00,0.00
254
+ Sugarcane bagasse hay,Grain Crop Forage,93.19,76.91,0.81,3.89,0.71,5.35,6.08
255
+ Sugarcane bagasse silage,Grain Crop Forage,34.61,71.98,1.01,4.99,0.91,9.62,6.22
256
+ Sunflower meal,Plant Protein,90.24,40.20,1.11,37.01,1.02,9.22,7.35
257
+ Sunflower seed,Plant Protein,92.72,35.20,0.61,20.07,37.20,4.00,3.47
258
+ Sunflower silage,Grass/Legume Forage,21.60,45.30,1.52,13.27,3.06,4.00,12.57
259
+ Sweet corn cannery waste,By-Product/Other,22.45,56.33,10.19,9.80,3.81,4.78,5.13
260
+ Tapioca (Cassava),Energy Source,87.71,8.11,78.88,2.50,0.48,2.27,3.22
261
+ Tomato pomace,By-Product/Other,24.70,60.00,1.19,19.30,12.30,13.00,5.50
262
+ Triticale grain,Energy Source,88.37,14.12,61.22,12.05,1.55,8.01,2.08
263
+ Triticale hay,Grain Crop Forage,91.02,59.96,3.06,10.33,1.46,14.02,8.48
264
+ Triticale plus pea silage,Grain Crop Forage,34.25,55.72,2.77,15.98,2.13,5.99,10.29
265
+ "Triticale silage, mature",Grain Crop Forage,30.14,58.59,1.70,14.16,2.48,10.06,10.06
266
+ "Triticale silage, mid-maturity",Grain Crop Forage,33.28,52.20,1.49,17.78,2.38,7.55,12.45
267
+ Urea,Additive,99.00,0.00,0.00,281.00,0.00,0.00,0.00
268
+ Vit A premix,Vitamin/Mineral,100.00,60.00,0.00,10.00,0.00,0.00,5.00
269
+ Vit D premix,Vitamin/Mineral,100.00,,,,,,0.00
270
+ Vit E premix,Vitamin/Mineral,100.00,,,,,,0.00
271
+ "VitTM Premix, generic",Vitamin/Mineral,92.00,26.00,15.00,16.00,2.00,10.00,18.00
272
+ Wheat bran,By-Product/Other,90.09,40.09,20.80,17.40,4.02,8.02,5.49
273
+ Wheat grain,Energy Source,85.69,12.46,63.01,13.48,1.78,5.92,2.06
274
+ "Wheat hay, headed",Grain Crop Forage,90.59,52.85,12.16,9.88,1.01,9.60,8.12
275
+ "Wheat hay, vegetative",Grain Crop Forage,90.46,57.99,3.39,10.50,0.89,17.26,8.20
276
+ Wheat middlings,By-Product/Other,88.28,38.67,22.92,19.10,3.85,7.90,5.88
277
+ "Wheat silage, HEADED",Grain Crop Forage,34.80,51.11,12.99,10.73,1.53,6.51,10.53
278
+ "Wheat silage, VEGETATIVE",Grain Crop Forage,35.55,56.58,2.50,13.35,1.42,9.19,9.91
279
+ Wheat straw,Grain Crop Forage,89.45,76.90,1.81,4.50,0.55,4.19,8.00
280
+ "Whey, dry",Animal Protein,92.62,0.65,1.43,17.83,5.27,56.10,9.66
281
+ "Whey, wet",Animal Protein,22.87,2.17,1.43,7.42,0.97,50.60,13.53
282
+ Zinc carbonate,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
283
+ Zinc chloride,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
284
+ Zinc oxide,Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
285
+ Zinc sulfate (H2O),Vitamin/Mineral,100.00,0.00,0.00,0.00,0.00,0.00,100.00
@@ -352,6 +352,9 @@ def identify(path) -> dict:
352
352
  kind = "cows"
353
353
  elif {"DATE", "PEN", "MILK_LB"} <= {h.lower().upper() for h in header} or header[:3] == ["DATE", "PEN", "MILK_LB"]:
354
354
  kind = "pen_milk"
355
+ elif set(header) & {"FEED", "INGREDIENT", "FEED NAME"} and set(header) & {"NDF", "ANDF"} and \
356
+ set(header) & {"CP", "PROTEIN"}:
357
+ kind = "analyses" # the farm's own feed analyses
355
358
  else:
356
359
  kind = "unknown"
357
360
  return {"path": str(p), "kind": kind, "detail": " ".join(h for h in header if h)}
@@ -0,0 +1,141 @@
1
+ """What a ration holds: each feed's composition from the farm's own analyses where it has them, NASEM (2021) book values
2
+ otherwise, matched by the feed's name; and each pen's dry matter fed by day split into aNDF, starch, CP, fat and the
3
+ rest. Every match is reported, so a card can say where its numbers came from."""
4
+
5
+ from __future__ import annotations
6
+
7
+ import csv
8
+ import re
9
+ from collections import defaultdict
10
+ from pathlib import Path
11
+
12
+ from . import io
13
+
14
+ LIBRARY = Path(__file__).with_name("data") / "nasem_feeds.csv"
15
+ LAYERS = (("ndf", "aNDF"), ("starch", "Starch"), ("cp", "CP"), ("fat", "Fat"), ("other", "Sugar, ash, other"))
16
+
17
+ # A farm's name for a feed -> NASEM's. The first match wins, so the more particular names come first.
18
+ MATCH = (
19
+ (r"corn\s*silage", "Corn silage, typical"),
20
+ (r"earlage|snaplage|high\s*moist|\bhmc\b|\bhm\s*corn", "Corn grain HM, coarse grind"),
21
+ (r"steam(ed)?[\s-]*flak", "Corn grain, steam-flaked"),
22
+ (r"(alfalfa|lucerne|legume).*(silage|haylage)|haylage", "Legume silage, mid-maturity"),
23
+ (r"alfalfa|lucerne|legume", "Legume hay, mid-maturity"),
24
+ (r"wheat.*silage|small grain.*silage|triticale.*silage|oat.*silage", "Wheat silage, HEADED"),
25
+ (r"wheat\s*hay|oat\s*hay|small grain\s*hay", "Wheat hay, headed"),
26
+ (r"straw", "Wheat straw"),
27
+ (r"grass\s*hay|\bhay\b", "Cool season grass hay, mid-mtr"),
28
+ (r"canola\s*oil", "Fat, canola oil"),
29
+ (r"canola", "Canola meal"),
30
+ (r"soy.*hull", "Soybean hulls"),
31
+ (r"soy", "Soybean meal, solvent 48CP"),
32
+ (r"\bddgs?\b|distillers?\s*(dried\s*)?grain|dried distillers", "DDGS, low fat"),
33
+ (r"cottonseed\s*meal", "Cottonseed meal"),
34
+ (r"cottonseed\s*hull", "Cottonseed hulls"),
35
+ (r"cottonseed|\bcotton\b", "Cottonseed, whole"),
36
+ (r"almond", "Almond hulls"),
37
+ (r"beet\s*pulp", "Beet pulp, dry"),
38
+ (r"citrus", "Citrus pulp, dry"),
39
+ (r"molasses", "Molasses"),
40
+ (r"whey", "Whey, wet"),
41
+ (r"bypass|calcium soap|megalac|energy booster|\bfat\b", "Calcium soaps"),
42
+ (r"barley", "Barley grain, steam rolled"),
43
+ (r"corn|maize", "Corn grain dry, coarse grind"),
44
+ )
45
+ # Minerals, premixes and additives: no NDF, starch, protein or fat to speak of; all of it counts as "the rest".
46
+ MINERAL = re.compile(r"mineral|premix|vitamin|\bsalt\b|buffer|bicarb|limestone|rumensin|monensin|yeast|additive|"
47
+ r"binder|magnesium|mag ox|selenium|\bmix\b", re.I)
48
+
49
+
50
+ def library() -> dict[str, dict]:
51
+ with open(LIBRARY, encoding="utf-8") as f:
52
+ return {r["name"]: {k: (float(v) if k not in ("name", "category") and v else v) for k, v in r.items()}
53
+ for r in csv.DictReader(f)}
54
+
55
+
56
+ def read_analyses(path) -> dict[str, dict]:
57
+ """The farm's own feed analyses: a CSV with a feed name and, as % of DM, NDF, starch, CP and fat (any of these
58
+ headers: feed/ingredient/name, ndf/andf, starch, cp/protein, fat/fa/ee, sugar/wsc, ash)."""
59
+ rows = list(csv.DictReader(io.read_lines(path)))
60
+ if not rows:
61
+ return {}
62
+ keys = {k: k.strip().lower() for k in rows[0]}
63
+ pick = lambda *names: next((k for k, low in keys.items() if low in names), None)
64
+ name = pick("feed", "ingredient", "name", "feed name")
65
+ cols = {"ndf": pick("ndf", "andf", "andfom"), "starch": pick("starch", "st"), "cp": pick("cp", "protein", "crude protein"),
66
+ "fat": pick("fat", "fa", "ee", "fatty acids"), "wsc": pick("sugar", "wsc", "esc"), "ash": pick("ash")}
67
+ out = {}
68
+ for r in rows:
69
+ if name and (r.get(name) or "").strip():
70
+ out[r[name].strip().lower()] = {k: io.number(r.get(c)) if c else None for k, c in cols.items()}
71
+ return out
72
+
73
+
74
+ def is_analyses(header: list[str]) -> bool:
75
+ low = {h.strip().lower() for h in header}
76
+ return bool(low & {"feed", "ingredient", "feed name"}) and bool(low & {"ndf", "andf"}) and bool(low & {"cp", "protein"})
77
+
78
+
79
+ def composition(feed: str, analyses: dict, lib: dict) -> tuple[dict, str, str]:
80
+ """(% of DM by layer, where it came from: "farm" | "book" | "mineral" | "none", the book feed's name or "")."""
81
+ own = analyses.get(feed.strip().lower())
82
+ if own and own.get("ndf") is not None:
83
+ c = {"ndf": own["ndf"] or 0, "starch": own.get("starch") or 0, "cp": own.get("cp") or 0, "fat": own.get("fat") or 0}
84
+ return _with_rest(c), "farm", ""
85
+ if MINERAL.search(feed):
86
+ return {"ndf": 0, "starch": 0, "cp": 0, "fat": 0, "other": 100}, "mineral", ""
87
+ for pattern, book in MATCH:
88
+ if re.search(pattern, feed, re.I) and book in lib:
89
+ b = lib[book]
90
+ return _with_rest({"ndf": b["ndf"] or 0, "starch": b["starch"] or 0, "cp": b["cp"] or 0,
91
+ "fat": b["fa"] or 0}), "book", book
92
+ return {"ndf": 0, "starch": 0, "cp": 0, "fat": 0, "other": 100}, "none", ""
93
+
94
+
95
+ def _with_rest(c: dict) -> dict:
96
+ named = sum(c.values())
97
+ if named > 100: # analyses that overlap: scale the named parts to the whole
98
+ c = {k: v * 100 / named for k, v in c.items()}
99
+ named = 100
100
+ return {**c, "other": 100 - named}
101
+
102
+
103
+ def pen_layers_by_day(herd, ezfeed_pen: str, analyses: dict | None = None) -> tuple[dict, dict]:
104
+ """Each day's share of the pen's delivered dry matter in each layer, {day: {layer: share}}, from EZfeed's feeds by
105
+ day (premix lines once; Pushout and water left out), and how each feed was valued: {feed: (source, book name)}."""
106
+ from .feeding import NOT_FEED
107
+ lib = library()
108
+ analyses = analyses or {}
109
+ by_day = defaultdict(lambda: defaultdict(float))
110
+ totals = defaultdict(float)
111
+ how = {}
112
+ for r in herd.feed.get("feed_delivery", []):
113
+ if r["pen"] != ezfeed_pen or r.get("premix") or NOT_FEED.match(r["ingredient"] or ""):
114
+ continue
115
+ dm = r.get("actual_dm_lb_per_head") or 0
116
+ if dm <= 0:
117
+ continue
118
+ comp, source, book = composition(r["ingredient"], analyses, lib)
119
+ how[r["ingredient"]] = (source, book)
120
+ for layer, _ in LAYERS:
121
+ by_day[r["date"]][layer] += dm * comp[layer] / 100
122
+ totals[r["date"]] += dm
123
+ shares = {d: {layer: v / totals[d] for layer, v in layers.items()} for d, layers in by_day.items() if totals[d] > 0}
124
+ return shares, how
125
+
126
+
127
+ def source_words(how: dict) -> str:
128
+ """One line for a card: how many feeds were valued from what."""
129
+ count = defaultdict(list)
130
+ for feed, (source, _) in how.items():
131
+ count[source].append(feed)
132
+ parts = []
133
+ if count["farm"]:
134
+ parts.append(f"the farm's analyses for {len(count['farm'])} feed{'s' if len(count['farm']) != 1 else ''}")
135
+ if count["book"]:
136
+ parts.append(f"NASEM (2021) book values for {len(count['book'])}")
137
+ if count["mineral"]:
138
+ parts.append(f"{len(count['mineral'])} mineral or premix counted as the rest")
139
+ if count["none"]:
140
+ parts.append(f"not matched, counted as the rest: {', '.join(sorted(count['none']))}")
141
+ return "What's in it: " + "; ".join(parts) + "." if parts else ""
@@ -89,7 +89,8 @@ def pen_feed_html(herd: Herd, milk_price: float | None = None, days: int = 7, sl
89
89
  """Each pen's feed against its milk, each pen's ration as bars, loading. slide: for a projector, bigger and
90
90
  with fewer items (each pen's three figures and its ration)."""
91
91
  pf = feeding.pen_feed(herd, days=days, milk_price=milk_price)
92
- pens = [p for p in pf["pens"] if p.get("dmi_lb_per_cow") is not None] # every pen fed, tested or not
92
+ # Milking pens: their cows tested or weighed (dry and heifer pens have no milk to set against the feed)
93
+ pens = [p for p in pf["pens"] if p.get("tested") and p.get("dmi_lb_per_cow") is not None]
93
94
  span = ""
94
95
  if pens:
95
96
  a, _, b = pens[0]["days"].partition(" to ")