cow_builder.state module#

module:

state

module author:

Gabe van den Hoeven

synopsis:

This module contains the State dataclass representing a state of a cow. This class is used by the DigitalCow class.

How To Use This Module#

(See the individual classes, methods, and attributes for details.)

As a dataclass, the State class is purely used as a collection of variables. An instance, once created, cannot be altered except by using the mutate method, which returns a new altered instance of the class. If two State instances with the same instance values are compared, they will be considered equal.

Values in this HowTo are examples, see documentation of each class or function for details on the default values.

1. Import the State class:#

First import the State class from the state module:

from cow_builder.state import State

2. Create a State instance:#

new_state = State('Open', 300, 1, 200, 20)

3. Return variables from the State instance:#

days_in_milk = new_state.days_in_milk

class cow_builder.state.State(state: str, days_in_milk: int, lactation_number: int, days_pregnant: int, milk_output: float)#

Bases: object

A class representing the state of a dairy cow.

Attributes:
var state:

The life state of the dairy cow.

type state:

str

var days_in_milk:

The number of days since the cow’s last calving, or it’s birth if it has not calved yet.

type days_in_milk:

int

var lactation_number:

The number of lactation cycles the cow has completed.

type lactation_number:

int

var days_pregnant:

The number of days that the cow is pregnant.

type days_pregnant:

int

var milk_output:

The amount of milk the cow produces in this state.

type milk_output:

float

Methods:

__post_init__()

mutate(**kwargs)


__post_init__()#

Checks for illegal variable types and value-combinations.

Raises:
  • TypeError – If the type of any variable is wrong.

  • ValueError – If days_pregnant is not 0 and the state is not ‘Pregnant’ or days_pregnant is 0 and the state is ‘Pregnant’.

days_in_milk: int#
days_pregnant: int#
lactation_number: int#
milk_output: float#
mutate(**kwargs)#

Takes an argument of the State class and returns a new instance with the changed value. This function can be used to change values in a State object by having the returned instance overwrite the original instance.

Parameters:

kwargs – The keyword and value pairs of the new state that need to be changed.

Returns:

The new state with the changed values.

Return type:

State

state: str#