I have a bunch of functions that return strings based upon score ranges. Then I have another function that sums everything up and assigns a numeric weight.
@property
def risk_status(self):
""" This function assigns numeric weight to risks. It returns an over all integer score. """
# Build a string of risks, ie "High Risk@At Risk@@Extreme Risk"
raw_string_of_risks = self.si_risk + '@' + self.aggbs_risk + '@' + self.cfimb_risk + '@' + self.cfiab_risk + '@' + self.cei_risk
# Build a list ["High Risk", "At Risk", "Extreme Risk"]
risks = raw_string_of_risks.split('@')
# Formula for over all risk status. ["High Risk", "At Risk", "Extreme Risk"] => 2+1+3 = 6
status = risks.count("At Risk")*1 + risks.count("High Risk")*2 + risks.count("Extreme Risk")*3
return status
I'm afraid with a gazillion records this property might slow things down. It will never get a string longer than 65 characters to parse, but will doing this over and over again really slow things down?
risks = [self.si_risk, self.aggbs_risk, ...]
– jcfollower Apr 4 '14 at 20:48