Пример #1
0
 def getAAI(self, name):
     claimant = self.getClaimant(name)
     if claimant:
         return claimant.getAAI()
     else:
         print("Non existent name for claimant in getAAI")
         errors.add("Non existent name for claimant in getAAI")
         return None
Пример #2
0
def discountFactor(yrs,discountRate):
    #returns the discountFactor after yrs with discountRate
    if discountRate==-1:
        errors.add('Discount rate is -1')
        return None
    if yrs<0: return 1
    factor=1/(1+discountRate)
    return factor**yrs
Пример #3
0
    def __init__(self, attributes):

        if 'rows' in attributes:
            self.rows = attributes['rows']

        self.autoYrAttained = False
        if 'autoYrAttained' in attributes['game']:
            self.autoYrAttained = attributes['game']['autoYrAttained']

        self.projection = True
        if 'projection' in attributes['game']:
            self.projection = attributes['game']['projection']

        if 'trialDate' in attributes[
                'game']:  #if trial date supplied, accept; otherwise use today's date
            if type(attributes['game']['trialDate']) is str:
                attributes['game']['trialDate'] = parsedateString(
                    attributes['game']['trialDate'])
            self.trialDate = attributes['game']['trialDate']
        else:
            self.trialDate = datetime.now()

        if 'DOI' in attributes[
                'game']:  #if trial date supplied, accept; otherwise use today's date
            if type(attributes['game']['DOI']) is str:
                attributes['game']['DOI'] = parsedateString(
                    attributes['game']['DOI'])
            self.doi = attributes['game']['DOI']

        if 'discountRate' in attributes[
                'game']:  #if discountrate supplied, accept; otherwise use default
            self.discountRate = attributes['game']['discountRate']
        else:
            self.discountRate = defaultdiscountRate

        if 'Ogden' in attributes[
                'game']:  #if correct Ogden supplied, accept; otherwise use default
            if attributes['game']['Ogden'] in Ogden:
                self.ogden = attributes['game']['Ogden']
            else:
                self.ogden = defaultOgden
        else:
            self.ogden = defaultOgden

        self.dirty = True
        self.TablesAD = TablesAD(self.ogden)

        self.claimants = {}  #dictionary for storing the claimants by name
        self.dependents = {}  #dictionary for storing the dependents by name

        if 'claimants' in attributes['game']:
            [
                self.addClaimant(person(cs, parent=self))
                for cs in attributes['game']['claimants']
            ]
        else:
            print('No claimants added')
            errors.add("No claimants added")
Пример #4
0
def termCertain(yrs,discountRate):
    if discountRate==-1:
        errors.add('Discount rate is -1')
        return None
    factor=1/(1+discountRate)
    if factor==1:
        return 1+yrs
    else:
        return ((factor**yrs)/(math.log(factor)))-(1/math.log(factor))
Пример #5
0
 def getAgeFromPoint(self, point):
     #point is either a float (i.e. age) or a datetime
     #returns age
     age = None
     if isinstance(point, np.float64) or isinstance(
             point, np.int64) or type(point) is float or type(point) is int:
         #i.e. age
         age = point
     elif type(point) is datetime:
         age = (point - self.dob).days / 365.25
     elif type(point) is str:  #for entries like TRIAL, LIFE
         age = self.parseTextPoint(point)
     else:
         #Error, wrong type
         print('Wrong type passed to getAgeFromPoint')
         print(type(point))
         errors.add('Wrong type passed to getAgeFromPoint: ' + type(point))
     return age
Пример #6
0
 def parseTextPoint(self, point):
     #where point='TRIAL+1Y" etc
     #check it's not a string date first
     if is_date(point): return self.getAgeFromPoint(parsedate(point))
     #make upper case
     point = point.upper()
     #removes all spaces
     point = " ".join(point.split())
     #split into component parts
     parts = re.split("([^a-zA-Z0-9_\.])", point)
     #evaluate each part - each part is either 'TRIAL' or '5Y' or '+' or '-'
     #add or subtract
     age = 0
     flag = True  #add if true
     for part in parts:
         if part in wordPoints:
             if part == 'TRIAL':
                 if flag: age += self.getAge()
                 if not flag: age -= self.getAge()
             elif part == 'LIFE':
                 if flag: age += 125
                 if not flag: age -= 125
             elif part == 'RETIREMENT':
                 if hasattr(self, 'retirement'):
                     if flag: age += self.retirement
                     if not flag: age -= self.retirement
                 else:
                     print('Retirement (uninjured) age not given')
                     errors.add('Retirement (uninjured) age not given')
                     return None
             elif part == 'INJURY':
                 AAI = self.getAAI()
                 if (AAI):
                     if flag: age += self.getAAI()
                     if not flag: age -= self.getAAI()
                 else:
                     errors.add('Date of injury not specified')
                     return None
             else:
                 age = age  #do nothing
         elif part in plusMinus:
             if part == '+': flag = True
             if part == '-': flag = False
         else:
             #test value
             #strip any '<' or '>'
             part = part.strip('<')
             part = part.strip('>')
             st, en, factor, tinterval = returnFreq(part)
             if tinterval:
                 if flag: age += tinterval
                 if not flag: age -= tinterval
             else:
                 print('Invalid part of word point, parsewordPoint')
                 errors.add("Invalid part of word point, parsewordPoint")
                 return None
     #return value
     return age
Пример #7
0
def returnFreq(freq,fromAge=None, toAge=None):
    #where freq is a string '<3Y' meaning every 3 years starting at the first date
    #returns tuple of timedelta and whether < or >
    if len(freq)<1:
        errors.add("Nil length freq")
        return False, False, 1, None
    st=False
    en=False
    if freq[0]=='<': st=True
    if freq[-1]=='>': en=True
    if st and en: st=en=False #if both True turn them False
    f=freq.strip('<').strip('>') #remove arrows
    p=f[-1] #get main period Y,M,W,D
    if len(f)>1:
        if isfloat(f[:-1]):
            n=float(f[:-1])
        else:
            n=1
    else:
        n=1

    factor=1

    if p=='Y':
        tinterval=n #in years
        factor=1/n
    elif p=='M':
        tinterval=(n*1/12) #in years
        factor=12.0/n
    elif p=='W':
        tinterval=(n*1/52) #in years
        factor=52/n
    elif p=='D':
        tinterval=(n*1/365.25) #in years
        factor=365.25/n
    elif p=='A':
        tinterval=n
        if (not toAge==None and not fromAge==None):
            factor=1/((toAge-fromAge)*n)
        else:
            print("toAge and fromAge need to be specified for 'A' in returnFreq")
            errors.add("toAge and fromAge need to be specified for 'A' in returnFreq")
            factor=1/n
    else:
        #Error wrong period passed
        print('Wrong period passed to returnFreq')
        errors.add("Wrong period passed to returnFreq")
        return st, en, 1, None

    return st, en, factor, tinterval
Пример #8
0
    def __init__(self, attributes, parent):

        self.parent = parent  #reference to game object
        self.attributes = attributes
        self.dirty = True
        self.fatal = False
        self.dependenton = None

        if 'name' in attributes:
            self.name = attributes['name']

        if 'dob' in attributes and not 'age' in attributes:
            if type(attributes['dob']) is str:
                attributes['dob'] = parsedateString(attributes['dob'])
            self.dob = attributes['dob']
            self.age = (self.gettrialDate() - self.dob).days / 365.25
        if 'age' in attributes and not 'dob' in attributes:
            self.age = attributes['age']
            self.dob = self.gettrialDate() - timedelta(days=(self.age *
                                                             365.25))

        if not 'age' in attributes and not 'dob' in attributes:
            print("Missing age information for person")
            errors.add("Missing age information for person")
        if 'age' in attributes and 'dob' in attributes:
            print("Both age and dob supplied for person")
            errors.add("Both age and dob supplied for person")

        if 'sex' in attributes:
            self.sex = attributes['sex']
        else:
            print("Missing sex for person")
            errors.add("Missing sex for person")

        if 'retirement' in attributes:
            if type(attributes['retirement']) is int or type(
                    attributes['retirement']) is float:
                self.retirement = attributes['retirement']

        #Life expectancy inputs
        c = 0
        if 'deltaLE' in attributes:
            c += 1
            self.deltaLE = attributes['deltaLE']
        else:
            self.deltaLE = 0

        self.targetLE = None
        if 'targetLE' in attributes:
            c += 1
            self.targetLE = attributes['targetLE']

        if 'liveto' in attributes:
            c += 1
            self.targetLE = attributes['liveto'] - self.age

        if c > 1:
            print(
                "Specify only one of targetLE, deltaLE or liveto: targetLE will be used."
            )
            errors.add(
                "Specify only one of targetLE, deltaLE or liveto: targetLE will be used."
            )

        self.contAutomatic = False  #manual by default
        if 'contAutomatic' in attributes:
            self.contAutomatic = attributes['contAutomatic']

        self.cont = 1
        if 'cont' in attributes: self.cont = attributes['cont']

        self.contDetails = ContDetailsdefault
        if 'contDetails' in attributes:
            self.contDetails = attributes[
                'contDetails']  #should be {'employed','qualification','disabled'}

        if 'dependenton' in self.attributes:
            self.dependenton = self.attributes['dependenton'].strip()

        self.dataSet = dataSet(attributes['dataSet'], self, self.deltaLE)
        self.curve = curve(self)

        self.SAR = SAR(parent=self)

        self.setUp()
        self.refresh()
Пример #9
0
 def addClaimant(self, claimant):
     if not claimant.name in self.claimants:
         self.claimants[claimant.name] = claimant
     else:
         print("Name already exists")
         errors.add("Name already exists")