88
99
1010class BaseCollector :
11- def __init__ (self , name :str , obj : Any , attributes : str | List [str ]= None , callable : Callable = None ):
11+ def __init__ (self , name :str , obj : Any , attributes : str | List [str ]= None , fn : Callable = None ):
1212 """
1313
1414 Args
@@ -31,7 +31,7 @@ def __init__(self, name:str, obj: Any, attributes: str|List[str]=None, callable:
3131 self .name = name
3232 self .obj = obj
3333 self .attributes = attributes
34- self .callable = callable
34+ self .callable = fn
3535 self .data_over_time = {}
3636
3737 def collect (self , time ):
@@ -67,8 +67,8 @@ def to_dataframe(self):
6767
6868
6969class AgentSetCollector (BaseCollector ):
70- def __init__ (self , name , obj , attributes = None , callable = None ):
71- super ().__init__ (name , obj , attributes = attributes , callable = callable )
70+ def __init__ (self , name , obj , attributes = None , fn = None ):
71+ super ().__init__ (name , obj , attributes = attributes , fn = fn )
7272 self .attributes .append ("unique_id" )
7373
7474 def collect (self , time ):
@@ -165,24 +165,24 @@ def collect_all(self):
165165 collector .collect (time )
166166
167167
168- def collect (name :str , obj :Any , attributes : str | List [str ]= None , callable : Callable = None ):
168+ def collect (name :str , obj :Any , attributes : str | List [str ]= None , fn : Callable = None ):
169169 """
170170
171171 Args
172172 name : name of the collector
173173 obj : object form which to collect information
174174 attributes : attributes to collect, option. If not provided, attributes defaults to name
175- callable : callable to apply to collected data.
175+ fn : callable to apply to collected data.
176176
177177 FIXME:: what about callable to object directly? or simply not allow for it and solve this
178178 FIXME:: through measures?
179179
180180 """
181181
182182 if isinstance (obj , AgentSet ):
183- return AgentSetCollector (name , obj , attributes , callable )
183+ return AgentSetCollector (name , obj , attributes , fn )
184184 else :
185- return BaseCollector (name , obj , attributes , callable )
185+ return BaseCollector (name , obj , attributes , fn )
186186
187187
188188
@@ -193,13 +193,13 @@ class Measure:
193193 # FIXME:: doing so would turn measure into a descriptor
194194 # FIXME:: what about callable vs. attribute based Measures?
195195
196- def __init__ (self , model : Model , obj : Any , callable : Callable ):
196+ def __init__ (self , model , obj : Any , callable : Callable ):
197197 super ().__init__ ()
198198 self .obj = obj
199199 self .callable = callable
200- self .model = model
201200 self ._update_step = - 1
202201 self ._cached_value = None
202+ self .model = model
203203
204204 def get_value (self , force_update : bool = False ):
205205 """
@@ -213,3 +213,20 @@ def get_value(self, force_update: bool = False):
213213 self ._cached_value = self .callable (self .obj )
214214 return self ._cached_value
215215
216+
217+
218+ class MeasureDescriptor :
219+
220+ def some_test_method (self , obj , * args , ** kwargs ):
221+ print ("blaat" )
222+
223+ def __set_name__ (self , owner , name ):
224+ self .public_name = name
225+ self .private_name = "_" + name
226+ def __get__ (self , obj , owner ):
227+ return getattr (obj , self .private_name ).get_value ()
228+
229+ def __set__ (self , obj , value ):
230+ setattr (obj , self .private_name , value )
231+
232+
0 commit comments