def process_data_for_mean(data, direction_type_key):
    dec_key, inc_key, meth_key = 'dec', 'inc', 'magic_method_codes'
    if 'dir_dec' in data[0].keys():
        dec_key, inc_key, meth_key = 'dir_dec', 'dir_inc', 'method_codes'
    n_lines, n_planes = 0, 0
    L, fdata = [], []
    E = [0, 0, 0]
    for rec in data:
        cart = dir2cart([float(rec[dec_key]), float(rec[inc_key])])[0]
        if direction_type_key in list(rec.keys()):
            if rec[direction_type_key] == 'p':
                n_planes += 1
                L.append(cart)
            else:
                n_lines += 1
                fdata.append([float(rec[dec_key]), float(rec[inc_key]), 1.])
                E[0] += cart[0]
                E[1] += cart[1]
                E[2] += cart[2]
        elif 'method_codes' in list(rec.keys()):
            if "DE-BFP" in rec[meth_key]:
                n_planes += 1
                L.append(cart)
            else:
                n_lines += 1
                fdata.append([rec[dec_key], rec[inc_key], 1.])
                E[0] += cart[0]
                E[1] += cart[1]
                E[2] += cart[2]
        elif meth_key in list(rec.keys()):
            if "DE-BFP" in rec[meth_key]:
                n_planes += 1
                L.append(cart)
            else:
                n_lines += 1
                fdata.append([rec[dec_key], rec[inc_key], 1.])
                E[0] += cart[0]
                E[1] += cart[1]
                E[2] += cart[2]
        else:
            n_lines += 1
            fdata.append([rec[dec_key], rec[inc_key], 1.])
            E[0] += cart[0]
            E[1] += cart[1]
            E[2] += cart[2]
    return fdata, n_lines, L, n_planes, E