示例#1
0
def data_process(participant_list=[], data_dir=[]):
    output_fields = ['task', 'trial', 'rotation_angle_deg', 'target_angle_deg']
    output_rows = []
    for i in range(0, len(data_dir)):
        output_fields.append(participant_list[i])
        pc = 0
        for j in range(0, len(data_dir[i])):
            for k in range(0, len(data_dir[i][j])):
                #                fields = []
                rows = []
                input_row = []
                with open(data_dir[i][j][k], "rb") as csvfile:
                    csv_reader = csv.reader(csvfile)
                    #                    fields = csv_reader.next()
                    #                    print ("\nField names are:" + ','.join(field for field in fields))
                    for row in csv_reader:
                        rows.append(row)
                for row in rows[1:]:
                    if i == 0:
                        if float(
                                exp.get_dist([0, 0], [
                                    float(row[15:16][0]),
                                    float(row[16:17][0])
                                ])) / float(
                                    exp.get_dist([0, 0], [
                                        float(row[11:12][0]),
                                        float(row[12:13][0])
                                    ])) >= float(1) / float(3):
                            input_row.append(row[1:2][0])
                            input_row.append(row[3:4][0])
                            input_row.append(row[5:6][0])
                            input_row.append(row[6:7][0])
                            cursor_deviation = degrees(
                                exp.cart2pol([
                                    float(row[15:16][0]),
                                    float(row[16:17][0])
                                ])[1]) - float(row[6:7][0])
                            input_row.append(cursor_deviation)
                            break
                    if i > 0:
                        if float(
                                exp.get_dist([0, 0], [
                                    float(row[15:16][0]),
                                    float(row[16:17][0])
                                ])) / float(
                                    exp.get_dist([0, 0], [
                                        float(row[11:12][0]),
                                        float(row[12:13][0])
                                    ])) >= float(1) / float(3):
                            cursor_deviation = degrees(
                                exp.cart2pol([
                                    float(row[15:16][0]),
                                    float(row[16:17][0])
                                ])[1]) - float(row[6:7][0])
                            output_rows[pc].append(cursor_deviation)
                            pc = pc + 1
                            break
                if i == 0:
                    output_rows.append(input_row)
    return [output_fields, output_rows]
示例#2
0
def data_process(participant_list=[], data_dir=[], cfg={}):

    output_fields = ['task', 'trial', 'rotation_angle_deg', 'target_angle_deg']
    output_rows = []
    for i in range(0, len(data_dir)):  # does this loop over participants?
        output_fields.append(participant_list[i])  # seems like it does
        pc = 0
        for j in range(0, len(data_dir[i])
                       ):  # does this loop over files in the data directory?
            for k in range(0, len(data_dir[i][j])):
                #                fields = []
                rows = []
                input_row = []
                with open(data_dir[i][j][k], "rb") as csvfile:
                    csv_reader = csv.reader(
                        csvfile
                    )  # why not read in the COMPLETE file as a pandas data frame?
                    #                    fields = csv_reader.next()
                    #                    print ("\nField names are:" + ','.join(field for field in fields))
                    for row in csv_reader:
                        rows.append(row)
                for row in rows[1:]:
                    if i == 0:
                        if float(
                                exp.get_dist([0, 0], [
                                    float(row[15:16][0]),
                                    float(row[16:17][0])
                                ])
                        ) / float(
                                exp.get_dist([0, 0], [
                                    float(row[11:12][0]),
                                    float(row[12:13][0])
                                ])
                        ) >= float(
                                1
                        ) / float(
                                3
                        ):  # why use column indices instead of column names? names are more robust to future situations where we add or re-order columns
                            input_row.append(row[1:2][0])  # task?
                            input_row.append(row[3:4][0])  # trial?
                            input_row.append(
                                row[5:6][0])  # rotation_angle_deg?
                            input_row.append(row[6:7][0])  # target_angle_deg?
                            cursor_deviation = degrees(
                                exp.cart2pol([
                                    float(row[15:16][0]),
                                    float(row[16:17][0])
                                ])[1]) - float(row[6:7][0])
                            input_row.append(cursor_deviation)
                            break
                    if i > 0:
                        if float(
                                exp.get_dist([0, 0], [
                                    float(row[15:16][0]),
                                    float(row[16:17][0])
                                ])) / float(
                                    exp.get_dist([0, 0], [
                                        float(row[11:12][0]),
                                        float(row[12:13][0])
                                    ])) >= float(1) / float(3):
                            cursor_deviation = degrees(
                                exp.cart2pol([
                                    float(row[15:16][0]),
                                    float(row[16:17][0])
                                ])[1]) - float(row[6:7][0])
                            output_rows[pc].append(cursor_deviation)
                            pc = pc + 1
                            break
                if i == 0:
                    output_rows.append(input_row)
    return [output_fields, output_rows
            ]  # why not return a data frame where this is integrated?