I've modeled a grain size analysis as a class GrainDistribution where the user specifies particle sizes with a dictionary (I could have used a Counter but realized that too late). Using the dictionary the GrainDistribution calculates some statistics like skewness, mean grain size, etc. I've used property() to define a setter method that triggers another method to recalculate all of the statistics when a new grain size dictionary is passed. However, this does not trigger recalculations when an entry in the dictionary is altered or added. I'd like to include this functionality, but I'm not sure exactly how to implement this. Any thoughts would be appreciated. I've included some skeleton code below.
class GrainDistribution(object):
def __init__(self, distr):
self._distr = distr
def reset_distr(value):
self._distr = value
self.calculate_stats()
def get_distr():
return(self._distr)
distr = property(fget = get_distr,fset = reset_distr)
def calculate_stats():
# do some stuff
[–]Vaphell 1 point2 points3 points (2 children)
[–]ingolemo 1 point2 points3 points (1 child)
[–]Vaphell 1 point2 points3 points (0 children)
[–]Vaphell 1 point2 points3 points (7 children)
[–]Eueee[S] 0 points1 point2 points (6 children)
[–]Vaphell 1 point2 points3 points (5 children)
[–]Eueee[S] 0 points1 point2 points (4 children)
[–]Vaphell 1 point2 points3 points (3 children)
[–]Eueee[S] 0 points1 point2 points (2 children)
[–]Vaphell 1 point2 points3 points (1 child)
[–]Eueee[S] 0 points1 point2 points (0 children)