
from ....util import key_as_str

def set_flag(arrest_records, **kw):
    arr_dates = set(['|'.join([str(x) for x in [row['astate'], row['arryr'], row['arrmo'], row['arrda']]]) 
                     if row['rapstate'].lower() != 'wvfbi' else 0 for row in arrest_records.itervalues()])
    
    for row in arrest_records.itervalues():
        if row['rapstate'].lower() == 'wvfbi' and row['afed'] != 1 and '|'.join([str(x) for x in [row['astate'], row['arryr'], row['arrmo'], row['arrda']]]) in arr_dates:
            arrest_records[row['id']]['wvfbi_overlap_flag'] = True
        else:
            arrest_records[row['id']]['wvfbi_overlap_flag'] = False
            
        