Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
acb0727
reordered reset daily stats
JoeWaddell Mar 3, 2026
958aab8
added stillborn_calf_info to herdstatistics attributs
JoeWaddell Mar 3, 2026
9a6bc47
removed unused avg_daily_cow_milking attribute
JoeWaddell Mar 3, 2026
291f974
removed avg_daily_cow_milking in unit test
JoeWaddell Mar 3, 2026
c0f9dc6
HerdStatistics docstring updates
JoeWaddell Mar 3, 2026
38420e1
reordered variable grouping in reset daily stats and attributes
JoeWaddell Mar 3, 2026
e537927
Merge 38420e1772ffc32b1f06a371d87989f41e78b06d into 9c8b2bd6c40619bba…
JoeWaddell Mar 3, 2026
86c47cf
updated changelog
JoeWaddell Mar 3, 2026
7737636
removed TODOs
JoeWaddell Mar 3, 2026
1ce6055
Apply Black Formatting
github-actions[bot] Mar 3, 2026
3385859
flake8 fix
JoeWaddell Mar 3, 2026
4f9fb64
Merge branch 'reset_daily_stats-reordering' of https://github.com/Rum…
JoeWaddell Mar 3, 2026
1aea417
Merge 4f9fb643c3abddd4eee663ba38774e8ee170ed0b into 9c8b2bd6c40619bba…
JoeWaddell Mar 3, 2026
19be0cb
Apply Black Formatting
github-actions[bot] Mar 3, 2026
5c334f9
Update badges on README
JoeWaddell Mar 3, 2026
255fe4a
updated typing
JoeWaddell Mar 4, 2026
c177cb1
Merge branch 'reset_daily_stats-reordering' of https://github.com/Rum…
JoeWaddell Mar 4, 2026
ee2bb99
Merge c177cb1a51373ceac09fe80a2a9aa3392c2eb230 into 9c8b2bd6c40619bba…
JoeWaddell Mar 4, 2026
a71c278
Apply Black Formatting
github-actions[bot] Mar 4, 2026
23222b4
Update badges on README
JoeWaddell Mar 4, 2026
e3e9c5a
fixed typing from review comment
JoeWaddell Mar 6, 2026
8a8799d
Merge branch 'dev' into reset_daily_stats-reordering
JoeWaddell Mar 6, 2026
ea07a31
Merge 8a8799d1a479b3ebd9bb4c82106d9fb4d7ce5dc6 into 15e42dfb63a8fbec3…
JoeWaddell Mar 6, 2026
e845877
Apply Black Formatting
github-actions[bot] Mar 6, 2026
b00f480
Update badges on README
JoeWaddell Mar 6, 2026
3be15ce
Merge branch 'dev' into reset_daily_stats-reordering
JoeWaddell Mar 6, 2026
dcfa75e
Merge 3be15ce6bc1f03119524f6e5e6e893869243d48b into 0dc1e4d3e4f728cd9…
JoeWaddell Mar 6, 2026
0183bbc
Apply Black Formatting
github-actions[bot] Mar 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Flake8](https://img.shields.io/badge/Flake8-passed-brightgreen)](https://github.com/RuminantFarmSystems/MASM/actions/workflows/combined_format_lint_test_mypy.yml)
[![Pytest](https://img.shields.io/badge/Pytest-passed-brightgreen)](https://github.com/RuminantFarmSystems/MASM/actions/workflows/combined_format_lint_test_mypy.yml)
[![Coverage](https://img.shields.io/badge/Coverage-99%25-brightgreen)](https://github.com/RuminantFarmSystems/MASM/actions/workflows/combined_format_lint_test_mypy.yml)
[![Mypy](https://img.shields.io/badge/Mypy-1424%20errors-red)](https://github.com/RuminantFarmSystems/MASM/actions/workflows/combined_format_lint_test_mypy.yml)
[![Mypy](https://img.shields.io/badge/Mypy-1423%20errors-red)](https://github.com/RuminantFarmSystems/MASM/actions/workflows/combined_format_lint_test_mypy.yml)


# RuFaS: Ruminant Farm Systems
Expand Down
87 changes: 46 additions & 41 deletions RUFAS/biophysical/animal/data_types/herd_statistics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass

from RUFAS.biophysical.animal import animal_constants
from RUFAS.biophysical.animal.data_types.animal_typed_dicts import SoldAnimalTypedDict
from RUFAS.biophysical.animal.data_types.animal_typed_dicts import SoldAnimalTypedDict, StillbornCalfTypedDict
from RUFAS.biophysical.animal.data_types.animal_types import AnimalType


Expand All @@ -19,18 +19,20 @@ class HerdStatistics:
Count statistics of culled animals, categorized by specified culling reasons, (unitless).
num_cow_for_parity : dict[str, int]
Count of cows for each parity class, (unitless).
avg_daily_cow_milking : float
Average number of milking cows per day, (unitless).
stillborn_calf_info : list[StillbornCalfTypedDict]
Details about stillborn calves including relevant attributes.
sold_calves_info : list[SoldAnimalTypedDict]
Details about sold calves including relevant attributes.
sold_heiferIIIs_info : list[SoldAnimalTypedDict]
Detailed information on sold animals categorized as "Heifer III".
sold_heiferIIs_info : list[SoldAnimalTypedDict]
Detailed information about sold animals categorized as "Heifer II".
sold_heiferIIIs_info : list[SoldAnimalTypedDict]
Detailed information on sold animals categorized as "Heifer III".
sold_cows_info : list[SoldAnimalTypedDict]
Comprehensive details of sold cows including relevant attributes.
sold_and_died_cows_info : list[SoldAnimalTypedDict]
Information concerning cows that were either sold or died.
total_enteric_methane : dict[AnimalType, dict[str, float]]
Total amount of enteric methane, grouped by animal types and methods (g/day).
herd_num : int
Total number of animals in the herd, (unitless).
calf_num : int
Expand Down Expand Up @@ -93,6 +95,8 @@ class HerdStatistics:
Total number of semen units used for cows, (unitless).
ed_period_h : int
Estrus detection (ED) period for heifers, (simulation days).
ed_period : int
Estrus detection (ED) period for cows, (simulation days).
open_cow_num : int
Total number of open (non-pregnant) cows, (unitless).
preg_cow_num : int
Expand All @@ -103,6 +107,8 @@ class HerdStatistics:
Number of cows actively milking in the herd, (unitless).
dry_cow_num : int
Number of dry cows (non-milking) in the herd, (unitless).
animals_deaths_by_stage : dict[AnimalType, int]
Count of animal deaths categorized by their stages.
dry_cow_percent : float
Percentage of dry cows in the herd, (unitless).
milking_cow_percent : float
Expand All @@ -111,16 +117,6 @@ class HerdStatistics:
Percentage of pregnant cows in the herd, (unitless).
non_preg_cow_percent : float
Percentage of non-pregnant cows in the herd, (unitless).
daily_milk_production : float
Average daily milk production, (kg).
herd_milk_fat_kg : float
Total quantity of milk fat in the herd's milk production, (kg).
herd_milk_fat_percent : float
Percentage of milk fat in the herd's milk production, (unitless).
herd_milk_protein_kg : float
Total quantity of milk protein in the herd's milk production, (kg).
herd_milk_protein_percent : float
Percentage of milk protein in the herd's milk production, (unitless).
avg_days_in_milk : float
Average number of days in milk, (simulation days).
avg_days_in_preg : float
Expand Down Expand Up @@ -150,25 +146,32 @@ class HerdStatistics:
Percentage statistics of culled animals, categorized by culling reasons, (unitless).
percent_cow_for_parity : dict[str, float]
Percentage of cows available for each parity class, calculated based on total counts, (unitless).
total_enteric_methane : dict[AnimalType, dict[str, float]]
Total amount of enteric methane, grouped by animal types and methods (g/day).
daily_milk_production : float
Average daily milk production, (kg).
herd_milk_fat_kg : float
Total quantity of milk fat in the herd's milk production, (kg).
herd_milk_fat_percent : float
Percentage of milk fat in the herd's milk production, (unitless).
herd_milk_protein_kg : float
Total quantity of milk protein in the herd's milk production, (kg).
herd_milk_protein_percent : float
Percentage of milk protein in the herd's milk production, (unitless).

"""

avg_calving_to_preg_time: dict[str, float]
cull_reason_stats: dict[str, int]

num_cow_for_parity: dict[str, int]
avg_daily_cow_milking = 0.0

stillborn_calf_info: list[StillbornCalfTypedDict]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it here. So I guess in the above docstring, it should be StillbornCalfTypedDict

sold_calves_info: list[SoldAnimalTypedDict]
sold_heiferIIIs_info: list[SoldAnimalTypedDict]
sold_heiferIIs_info: list[SoldAnimalTypedDict]
sold_heiferIIIs_info: list[SoldAnimalTypedDict]
sold_cows_info: list[SoldAnimalTypedDict]
sold_and_died_cows_info: list[SoldAnimalTypedDict]
total_enteric_methane: dict[AnimalType, dict[str, float]]

# TODO: Maybe break this list down into smaller lists GitHub Issue #1215
herd_num = 0
calf_num = 0
heiferI_num = 0
Expand All @@ -191,9 +194,9 @@ class HerdStatistics:
heiferIII_percent = 0.0
cow_percent = 0.0

CIDR_count = 0
preg_check_num_h = 0
preg_check_num = 0
CIDR_count = 0
GnRH_injection_num_h = 0
GnRH_injection_num = 0
PGF_injection_num_h = 0
Expand All @@ -212,16 +215,13 @@ class HerdStatistics:
milking_cow_num = 0
dry_cow_num = 0

animals_deaths_by_stage: dict[AnimalType, int]

dry_cow_percent = 0.0
milking_cow_percent = 0.0
preg_cow_percent = 0.0
non_preg_cow_percent = 0.0

daily_milk_production = 0.0
herd_milk_fat_kg = 0.0
herd_milk_fat_percent = 0.0
herd_milk_protein_kg = 0.0
herd_milk_protein_percent = 0.0
avg_days_in_milk = 0.0
avg_days_in_preg = 0.0
avg_cow_body_weight = 0.0
Expand All @@ -240,7 +240,11 @@ class HerdStatistics:
cull_reason_stats_percent: dict[str, float]
percent_cow_for_parity: dict[str, float]

animals_deaths_by_stage: dict[AnimalType, int]
daily_milk_production = 0.0
herd_milk_fat_kg = 0.0
herd_milk_fat_percent = 0.0
herd_milk_protein_kg = 0.0
herd_milk_protein_percent = 0.0

def __init__(self) -> None:
"""
Expand Down Expand Up @@ -326,14 +330,14 @@ def reset_daily_stats(self) -> None:
self.heiferIII_percent = 0.0
self.cow_percent = 0.0

# TODO: Check if all the following variables need to reset daily GitHub Issue #1215
self.CIDR_count = 0
self.preg_check_num_h = 0
self.preg_check_num = 0
self.GnRH_injection_num_h = 0
self.GnRH_injection_num = 0
self.PGF_injection_num_h = 0
self.PGF_injection_num = 0

self.ai_num_h = 0
self.ai_num = 0
self.semen_num_h = 0
Expand All @@ -347,16 +351,20 @@ def reset_daily_stats(self) -> None:
self.milking_cow_num = 0
self.dry_cow_num = 0

self.animals_deaths_by_stage: dict[AnimalType, int] = {
AnimalType.CALF: 0,
AnimalType.HEIFER_I: 0,
AnimalType.HEIFER_II: 0,
AnimalType.HEIFER_III: 0,
AnimalType.LAC_COW: 0,
AnimalType.DRY_COW: 0,
}

self.preg_cow_percent = 0.0
self.dry_cow_percent = 0.0
self.milking_cow_percent = 0.0
self.non_preg_cow_percent = 0.0

self.daily_milk_production = 0.0
self.herd_milk_fat_kg = 0.0
self.herd_milk_fat_percent = 0.0
self.herd_milk_protein_kg = 0.0
self.herd_milk_protein_percent = 0.0
self.avg_days_in_milk = 0.0
self.avg_days_in_preg = 0.0
self.avg_cow_body_weight = 0.0
Expand All @@ -368,14 +376,11 @@ def reset_daily_stats(self) -> None:
self.avg_cow_culling_age = 0.0
self.avg_mature_body_weight = 0.0

self.animals_deaths_by_stage: dict[AnimalType, int] = {
AnimalType.CALF: 0,
AnimalType.HEIFER_I: 0,
AnimalType.HEIFER_II: 0,
AnimalType.HEIFER_III: 0,
AnimalType.LAC_COW: 0,
AnimalType.DRY_COW: 0,
}
self.daily_milk_production = 0.0
self.herd_milk_fat_kg = 0.0
self.herd_milk_fat_percent = 0.0
self.herd_milk_protein_kg = 0.0
self.herd_milk_protein_percent = 0.0

def reset_parity(self) -> None:
"""Resets parity-based attributes."""
Expand Down
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ v1.0.0
- [2791](https://github.com/RuminantFarmSystems/MASM/pull/2791) - [minor change] [Animal] [NoInputChange] [NoOutputChange] Updates ration percentage values in example feed files to sum to exactly 100.
- [2804](https://github.com/RuminantFarmSystems/MASM/pull/2804) - [minor change] [Tests] [NoInputChange] [NoOutputChange] Clears all mypy errors in test_field.py.
- [2819](https://github.com/RuminantFarmSystems/MASM/pull/2819) - [minor change] [Tests] [NoInputChange] [NoOutputChange] Clears all mypy errors in test_input_manager.py.
- [2809](https://github.com/RuminantFarmSystems/MASM/pull/2809) - [minor change] [Animal] [NoInputChange] [NoOutputChange] Reorders grouping of attributes in some HerdStatistics methods, updates docstrings.

### v1.0.0

- [2081](https://github.com/RuminantFarmSystems/MASM/pull/2081) - [minor change] [Crop & Soil] Break down the `_setup_field()` function in `FieldManager`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def test_initialization(herd_statistics: HerdStatistics) -> None:
assert herd_statistics.sold_cows_info == []
assert herd_statistics.herd_num == 0
assert herd_statistics.calf_num == 0
assert herd_statistics.avg_daily_cow_milking == 0.0


def test_reset_daily_stats(herd_statistics: HerdStatistics) -> None:
Expand Down