def fuzzy_match_candidate(skedeline):
    state = skedeline.candidate_state
    name_to_check = "%s, %s" % (skedeline.candidate_last_name,
                                skedeline.candidate_first_name)
    office = skedeline.candidate_office
    state = skedeline.candidate_state

    cycle_date = skedeline.effective_date
    THIS_CYCLE = None
    if cycle_date:
        THIS_CYCLE = get_cycle_from_date(cycle_date)

    result = run_fec_query(name_to_check,
                           state=state,
                           office=office,
                           cycle=THIS_CYCLE,
                           fuzzy=True)
    if result:
        if result[0]['match']:
            print "Fuzzy matching matched %s, %s, %s to %s with id %s" % (
                name_to_check, state, office, result[0]['name'],
                result[0]['id'])

            return set_data_from_candidate_id(skedeline, result[0]['id'])

    print "Fuzzy matching couldn't match %s, %s, %s" % (name_to_check, state,
                                                        office)
    return False
Example #2
0
def refine_json(request, reconciliation_type):
    
    fuzzy=True
    if reconciliation_type == 'fec_ids':
        pass
    elif reconciliation_type == 'fec_ids_nofuzzy':
        fuzzy=False
    else:
        raise Exception ("Invalid reconciliation type: %s" % (reconciliation_type))
    
    queries = request.REQUEST.get('queries')
    if queries:
        q = json.loads(queries)
        thisjson={}
        if q is not None:
            for key, query in q.iteritems():
                
                state = query.get('state', None)
                office = query.get('office', None)
                cycle = query.get('cycle', None)
                result = run_fec_query(query['query'], state=state, office=office, cycle=cycle, fuzzy=fuzzy)
                thisjson[key] = {'result':result}
        return render_to_json(json.dumps(thisjson))

        
    else:
        message = "Couldn't decode the query JSON!"
        return render_to_json("{'Error':'%s'}" % message)
Example #3
0
def do_fec_query(query, fuzzy=True):
    #print "running query: %s" % (query['query'])
    properties = normalize_properties(query)
    #print "running query with properties=%s" % (properties)
    state = None
    office = None
    cycle = None
    if properties:
        for thisproperty in properties:
            for key in thisproperty:
                if key=='state':
                    state = thisproperty['state']
                elif key =='office':
                    office = thisproperty['office']
                elif key =='cycle':
                    cycle = thisproperty['cycle']
    match_key_hash = run_fec_query(query['query'], state=state, office=office, cycle=cycle, fuzzy=fuzzy)
    return match_key_hash
Example #4
0
def fuzzy_match_candidate(skedeline):
    state = skedeline.candidate_state
    name_to_check = "%s, %s" % (skedeline.candidate_last_name, skedeline.candidate_first_name)
    office = skedeline.candidate_office
    state = skedeline.candidate_state
    
    cycle_date = skedeline.effective_date
    THIS_CYCLE = None
    if cycle_date:
        THIS_CYCLE = get_cycle_from_date(cycle_date)
    
    result = run_fec_query(name_to_check, state=state, office=office, cycle=THIS_CYCLE, fuzzy=True)
    if result:
        if result[0]['match']:
            print "Fuzzy matching matched %s, %s, %s to %s with id %s" % (name_to_check, state, office, result[0]['name'], result[0]['id'])
        
            return set_data_from_candidate_id(skedeline, result[0]['id'])
    
    print "Fuzzy matching couldn't match %s, %s, %s" % (name_to_check, state, office)
    return False