Пример #1
0
def il_exceptions(estimated_ocdid, ed):

    if 'appellate' in ed:
        return estimated_ocdid + '/court_of_appeals:{}'.format(get_district(ed))
    elif 'circuit' in ed and 'cook' not in ed:
        return estimated_ocdid + '/circuit_court:{}'.format(get_district(ed))
    else:
        return ''
Пример #2
0
def nh_exceptions(estimated_ocdid, ed, role):

    if role == 'executivecouncil':
        estimated_ocdid += '/executive_district:' + get_district(ed)
    elif role == 'legislatorlowerbody':
        estimated_ocdid += (u'/sldl:') + get_district(ed)
    elif role == 'legislatorupperbody':
        estimated_ocdid += (u'/sldu:') + get_district(ed)

    return estimated_ocdid
Пример #3
0
def ky_exceptions(estimated_ocdid, ed):

    if 'supreme' in ed:
        return estimated_ocdid + '/court_of_appeals:{}'.format(get_district(ed))
    elif 'circuit' in ed:
        return estimated_ocdid + '/circuit_court:{}'.format(get_district(ed))
    elif 'judicial district' in ed:
        return estimated_ocdid + '/district_court:{}'.format(get_district(ed))
    else:
        return ''
Пример #4
0
def assign_lower(state, ed, office, level, role, estimated_ocdid):
    nothing = False

    if level == 'administrativearea1':
        nothing = True

    elif level == 'administrativearea2':

        if 'county' in ed:
            if state == 'va' and 'city' in ed:
                estimated_ocdid = se.va_exceptions(estimated_ocdid, ed)
            elif 'county council district' in ed:
                temp_ed = ed.split('county council district')
                estimated_ocdid += '/county:{}/council_district:{}'.format(
                    no_spaces(temp_ed[0]), no_spaces(temp_ed[-1].strip())
                )
            elif 'school' in ed:
                nothing = True
            elif 'subcircuit' in ed:
                nothing = True
            elif 'finance' in ed or 'dorchester county judicial' in ed:
                nothing = True
            else:
                ed = ed.replace('county', '').strip().replace(' ', '_').replace('.', '')
                estimated_ocdid += '/county:{}'.format(ed)
        else:
            nothing = True

    elif level == 'regional':

        if state == 'ky':
            estimated_ocdid = se.ky_exceptions(estimated_ocdid, ed)
        elif state == 'il':
            estimated_ocdid = se.il_exceptions(estimated_ocdid, ed)
        elif 'county' in ed and 'district' not in ed:
            ed = ed.replace('county', '').strip().replace(' ', '_').replace('.', '')
            estimated_ocdid += '/county:{}'.format(ed)
        elif 'supreme' in ed:
            estimated_ocdid += 'supreme_court:{}'.format(get_district(ed))
            if not ocdid.is_ocdid(estimated_ocdid):
                nothing = True
        elif 'circuit' in ed:
            nothing = True
        else:
            nothing = True

    elif level == 'locality':
        if state == 'va':
            estimated_ocdid = se.va_exceptions(estimated_ocdid, ed)
        else:
            nothing = True

    elif level == 'special':
        nothing = True

    else:
        nothing = True

    if state == 'co' and 'school' in role:
        estimated_ocdid = se.co_exceptions(estimated_ocdid, ed, role)
        nothing = False

    if nothing:
        estimated_ocdid = ''

    return estimated_ocdid
Пример #5
0
def assign_ids(data):

    matched = []
    unmatched = []
    possible_errors = []

    match_count = 0

    for d in data:
        nothing = False

        d['Office Name'] = d['Office Name'].strip()
        d['Candidate Name'] = d['Candidate Name'].strip()

        state = d['State'].lower()
        ed = d['Electoral District'].lower().replace('\'', '~').replace('.', '')
        office = d['Office Name'].lower()
        level = d['level'].lower()
        role = d['role'].lower()

        estimated_ocdid = get_prefix(state)

        if level == 'country':
            if role == 'legislatorlowerbody' and not ed == state:
                estimated_ocdid += '/cd:' + get_district(ed)
            elif not ed == state:
                nothing = True

        elif level == 'administrativearea1':
            if ed == state:
                estimated_ocdid = estimated_ocdid
            elif state == 'dc':
                estimated_ocdid = se.dc_exceptions(estimated_ocdid, ed, role)
            elif state == 'ma' and 'councillor district' in ed:
                estimated_ocdid = ''
            elif state == 'nh':
                estimated_ocdid = se.nh_exceptions(estimated_ocdid, ed, role)
            elif state == 'vt':
                estimated_ocdid = se.vt_exceptions(estimated_ocdid, office, role)
            elif role == 'legislatorlowerbody':
                estimated_ocdid += (u'/sldl:') + get_district(ed)
            elif role == 'legislatorupperbody':
                estimated_ocdid += (u'/sldu:') + get_district(ed)
            else:
                nothing = True
        else:
            nothing = True

        if nothing:
            estimated_ocdid = assign_lower(state, ed, office,
                                           level, role, estimated_ocdid)
            if not estimated_ocdid == '':
                nothing = False

        if nothing:
            estimated_ocdid = ''

        if not ocdid.is_ocdid(estimated_ocdid) and not estimated_ocdid == '':
            invalid_id = {'state': state.upper(),
                          'possible_error': repr(estimated_ocdid)}
            possible_errors.append(invalid_id)
            estimated_ocdid = ''
        if not estimated_ocdid == '':
            match_count += 1

        # Exclude stuff for 141003 QA
        excludes = ['IN', 'KY', 'MD']
        if d['State'] in excludes:
            if d['level'].lower() == 'adminisitrativearea2':
                d['exclude'] = 'x'

        d['ocdid'] = estimated_ocdid
        d['ocdid_report'] = ''
        if not any(m['UID'] == d['UID'] for m in matched):
            matched.append(d)

    print 'Rows in flat file: {}'.format(len(matched))
    print 'Matched rows: {}'.format(match_count)
    print 'Unmatched rows: {}\n'.format(len(unmatched))
    print 'POSSIBLE ERRORS:{}'.format(len(possible_errors))

    return {'matched': matched,
            'invalid_id_report': possible_errors
            }
Пример #6
0
def co_exceptions(estimated_ocdid, ed, role):
    if 'school' in role:
        return estimated_ocdid + '/cd:{}'.format(get_district(ed))
    else:
        return ''