def grade(PmagRec, ACCEPT, type, data_model=2.5):
    """
    Finds the 'grade' (pass/fail; A/F) of a record (specimen,sample,site) given the acceptance criteria
    """
    GREATERTHAN = ['specimen_q', 'site_k', 'site_n', 'site_n_lines', 'site_int_n', 'measurement_step_min', 'specimen_int_ptrm_n', 'specimen_fvds', 'specimen_frac', 'specimen_f', 'specimen_n', 'specimen_int_n', 'sample_int_n', 'average_age_min', 'average_k', 'average_r', 'specimen_magn_moment',
                   'specimen_magn_volume', 'specimen_rsc', 'sample_n', 'sample_n_lines', 'sample_n_planes', 'sample_k', 'sample_r', 'site_magn_moment', 'site_magn_volume', 'site_magn_mass', 'site_r']  # these statistics must be exceede to pass, all others must be less than (except specimen_scat, which must be true)
    ISTRUE = ['specimen_scat']
    kill = []  # criteria that kill the record
    sigma_types = ['sample_int_sigma', 'sample_int_sigma_perc', 'site_int_sigma',
                   'site_int_sigma_perc', 'average_int_sigma', 'average_int_sigma_perc']
    sigmas = []
    accept = {}
    if type == 'specimen_int':
        USEKEYS = ['specimen_q', 'measurement_step_min', 'measurement_step_max', 'specimen_int_ptrm_n', 'specimen_fvds', 'specimen_frac', 'specimen_f', 'specimen_int_n', 'specimen_magn_moment',
                   'specimen_magn_volume', 'specimen_rsc', 'specimen_scat', 'specimen_drats', 'specimen_int_mad', 'specimen_int_dang', 'specimen_md', 'specimen_b_beta', 'specimen_w', 'specimen_gmax']
        if data_model == 3.0:
            USEKEYS = [map_magic.spec_magic2_2_magic3_map[k] for k in USEKEYS]
    elif type == 'specimen_dir':
        USEKEYS = ['measurement_step_min', 'measurement_step_max', 'specimen_mad',
                   'specimen_n', 'specimen_magn_moment', 'specimen_magn_volume']
        if data_model == 3.0:
            USEKEYS = [map_magic.spec_magic2_2_magic3_map[k] for k in USEKEYS]
    elif type == 'sample_int':
        USEKEYS = ['sample_int_n', 'sample_int_sigma', 'sample_int_sigma_perc']
        if data_model == 3.0:
            USEKEYS = [map_magic.samp_magic2_2_magic3_map[k] for k in USEKEYS]
    elif type == 'sample_dir':
        USEKEYS = ['sample_alpha95', 'sample_n', 'sample_n_lines',
                   'sample_n_planes', 'sample_k', 'sample_r']
        if data_model == 3.0:
            USEKEYS = [map_magic.samp_magic2_2_magic3_map[k] for k in USEKEYS]
    elif type == 'site_int':
        USEKEYS = ['site_int_sigma', 'site_int_sigma_perc', 'site_int_n']
        if data_model == 3.0:
            USEKEYS = [map_magic.site_magic2_2_magic3_map[k] for k in USEKEYS]
    elif type == 'site_dir':
        USEKEYS = ['site_alpha95', 'site_k', 'site_n',
                   'site_n_lines', 'site_n_planes', 'site_r']
        if data_model == 3.0:
            USEKEYS = [map_magic.site_magic2_2_magic3_map[k] for k in USEKEYS]

    for key in list(ACCEPT.keys()):
        if ACCEPT[key] != "" and key in USEKEYS:
            if key in ISTRUE and ACCEPT[key] == 'TRUE' or ACCEPT[key] == 'True':
                # this is because Excel always capitalizes True to TRUE and
                # python doesn't recognize that as a boolean.  never mind
                ACCEPT[key] = '1'
            elif ACCEPT[key] == 'FALSE' or ACCEPT[key] == 'False':
                ACCEPT[key] = '0'
            elif eval(ACCEPT[key]) == 0:
                ACCEPT[key] = ""
            accept[key] = ACCEPT[key]
    for key in sigma_types:
        if key in USEKEYS and key in list(accept.keys()) and key in list(PmagRec.keys()):
            sigmas.append(key)
    if len(sigmas) > 1:
        if PmagRec[sigmas[0]] == "" or PmagRec[sigmas[1]] == "":
            kill.append(sigmas[0])
            kill.append(sigmas[1])
        elif eval(PmagRec[sigmas[0]]) > eval(accept[sigmas[0]]) and eval(PmagRec[sigmas[1]]) > eval(accept[sigmas[1]]):
            kill.append(sigmas[0])
            kill.append(sigmas[1])
    elif len(sigmas) == 1 and sigmas[0] in list(accept.keys()):
        if PmagRec[sigmas[0]] > accept[sigmas[0]]:
            kill.append(sigmas[0])
    for key in list(accept.keys()):
        if accept[key] != "":
            if key not in list(PmagRec.keys()) or PmagRec[key] == '':
                kill.append(key)
            elif key not in sigma_types:
                if key in ISTRUE:  # boolean must be true
                    if PmagRec[key] != '1':
                        kill.append(key)
                if key in GREATERTHAN:
                    if eval(str(PmagRec[key])) < eval(str(accept[key])):
                        kill.append(key)
                else:
                    if eval(str(PmagRec[key])) > eval(str(accept[key])):
                        kill.append(key)
    return kill