Coverage for pybeepop/beepop/colonyresource.py: 62%
89 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-30 13:34 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-30 13:34 +0000
1"""BeePop+ Colony Resource Management Module.
3This module contains classes for managing colony food resources including pollen
4and nectar stores with associated pesticide contamination tracking.
6Classes:
7 ResourceItem: Individual resource unit with contamination tracking
8 ColonyResource: Colony-level resource stores with pesticide management
9"""
12class ResourceItem:
13 """Individual resource unit with associated pesticide contamination.
15 Represents a discrete quantity of colony resource (pollen or nectar) with
16 its associated pesticide load. Used for tracking contamination levels and
17 implementing resource-based mortality and sublethal effects.
19 Attributes:
20 resource_quantity (float): Amount of resource (grams)
21 pesticide_quantity (float): Associated pesticide load (grams)
22 """
24 def __init__(self, resource_quantity=0.0, pesticide_quantity=0.0):
25 self.resource_quantity = resource_quantity
26 self.pesticide_quantity = pesticide_quantity
29class ColonyResource:
30 """Colony-level resource management with pollen and nectar stores.
32 Manages colony food resources including pollen and nectar quantities with
33 associated pesticide contamination tracking. Provides resource consumption,
34 storage limits, and contamination concentration calculations for colony
35 survival and brood rearing dynamics.
37 Resources support larval development, adult maintenance, and colony growth.
38 Pesticide contamination affects bee mortality and reproductive success.
39 Resource depletion can trigger colony decline or collapse scenarios.
41 Attributes:
42 pollen_quantity (float): Current pollen stores in grams
43 nectar_quantity (float): Current nectar stores in grams
44 pollen_pesticide_quantity (float): Total pesticide load in pollen stores in grams
45 nectar_pesticide_quantity (float): Total pesticide load in nectar stores in grams
46 """
48 def __init__(self):
49 self.pollen_quantity = 0.0
50 self.nectar_quantity = 0.0
51 self.pollen_pesticide_quantity = 0.0
52 self.nectar_pesticide_quantity = 0.0
54 # Gets and Sets
55 def get_pollen_quantity(self):
56 return self.pollen_quantity
58 def get_nectar_quantity(self):
59 return self.nectar_quantity
61 def get_pollen_pesticide_quantity(self):
62 return self.pollen_pesticide_quantity
64 def get_nectar_pesticide_quantity(self):
65 return self.nectar_pesticide_quantity
67 def get_pollen_pesticide_concentration(self):
68 if self.pollen_quantity > 0:
69 return self.pollen_pesticide_quantity / self.pollen_quantity
70 return 0.0
72 def get_nectar_pesticide_concentration(self):
73 if self.nectar_quantity > 0:
74 return self.nectar_pesticide_quantity / self.nectar_quantity
75 return 0.0
77 def set_pollen_quantity(self, quan):
78 self.pollen_quantity = quan
80 def set_nectar_quantity(self, quan):
81 self.nectar_quantity = quan
83 def set_pollen_pesticide_quantity(self, quan):
84 self.pollen_pesticide_quantity = quan
86 def set_nectar_pesticide_quantity(self, quan):
87 self.nectar_pesticide_quantity = quan
89 # Methods
90 def initialize(self, init_pollen=0.0, init_nectar=0.0):
91 self.pollen_quantity = init_pollen
92 self.nectar_quantity = init_nectar
93 self.pollen_pesticide_quantity = 0.0
94 self.nectar_pesticide_quantity = 0.0
96 def add_pollen(self, pollen: ResourceItem):
97 self.pollen_quantity += pollen.resource_quantity
98 self.pollen_pesticide_quantity += pollen.pesticide_quantity
100 def add_nectar(self, nectar: ResourceItem):
101 self.nectar_quantity += nectar.resource_quantity
102 self.nectar_pesticide_quantity += nectar.pesticide_quantity
104 def remove_pollen(self, amount):
105 """Remove pollen - matches C++ RemovePollen(double Amount)"""
106 # Pollen cannot go below zero
107 if self.pollen_quantity >= amount:
108 self.pollen_quantity -= amount
109 self.pollen_pesticide_quantity -= (
110 amount * self.get_pollen_pesticide_concentration()
111 )
112 if self.pollen_pesticide_quantity < 0:
113 self.pollen_pesticide_quantity = 0
114 else:
115 self.pollen_quantity = 0.0
116 self.pollen_pesticide_quantity = 0.0
118 def remove_pollen_with_return(self, amount, pollen: ResourceItem):
119 """Remove pollen and return removed amount - matches C++ RemovePollen(double Amount, SResourceItem &Pollen)"""
120 if self.pollen_quantity >= amount:
121 # Pollen
122 pollen.resource_quantity = amount
123 self.pollen_quantity -= amount
124 if self.pollen_quantity < 0:
125 self.pollen_quantity = 0
127 # Pesticide
128 pollen.pesticide_quantity = (
129 self.get_pollen_pesticide_concentration() * pollen.resource_quantity
130 )
131 self.pollen_pesticide_quantity -= pollen.pesticide_quantity
132 if self.pollen_pesticide_quantity < 0:
133 self.pollen_pesticide_quantity = 0
134 else:
135 pollen.resource_quantity = self.pollen_quantity
136 pollen.pesticide_quantity = self.pollen_pesticide_quantity
137 self.pollen_quantity = 0.0
138 self.pollen_pesticide_quantity = 0.0
140 def remove_nectar(self, amount):
141 """Remove nectar - matches C++ RemoveNectar(double Amount)"""
142 # Nectar cannot go below zero
143 if self.nectar_quantity >= amount:
144 self.nectar_quantity -= amount
145 self.nectar_pesticide_quantity -= (
146 amount * self.get_nectar_pesticide_concentration()
147 )
148 if self.nectar_pesticide_quantity < 0:
149 self.nectar_pesticide_quantity = 0
150 else:
151 self.nectar_quantity = 0.0
152 self.nectar_pesticide_quantity = 0.0
154 def remove_nectar_with_return(self, amount, nectar: ResourceItem):
155 """Remove nectar and return removed amount - matches C++ RemoveNectar(double Amount, SResourceItem &Nectar)"""
156 if self.nectar_quantity >= amount:
157 # Nectar
158 nectar.resource_quantity = amount
159 self.nectar_quantity -= amount
160 if self.nectar_quantity < 0:
161 self.nectar_quantity = 0
163 # Pesticide
164 nectar.pesticide_quantity = (
165 self.get_nectar_pesticide_concentration() * nectar.resource_quantity
166 )
167 self.nectar_pesticide_quantity -= nectar.pesticide_quantity
168 if self.nectar_pesticide_quantity < 0:
169 self.nectar_pesticide_quantity = 0
170 else:
171 nectar.resource_quantity = self.nectar_quantity
172 nectar.pesticide_quantity = self.nectar_pesticide_quantity
173 self.nectar_quantity = 0.0
174 self.nectar_pesticide_quantity = 0.0