Ejemplo n.º 1
0
    def test_export_tabular_xlsx(self):

        pj = json.loads(open("files/test.boris").read())

        obs_id = "observation #1"
        parameters = {"selected subjects": ["subject1", "subject2"],
                      "selected behaviors": ["p", "s"]}
        file_name = "test_export_events_tabular.xlsx"
        output_format  = "xlsx"

        r, msg = export_observation.export_events(parameters,
                                                  obs_id,
                                                  pj[OBSERVATIONS][obs_id],
                                                  pj[ETHOGRAM],
                                                  "output/" + file_name,
                                                  output_format)

        ref_all_cells = []
        wb = load_workbook(filename=f'files/{file_name}', read_only=True)
        for ws_name in wb.sheetnames:
            ref_all_cells.extend([cell.value for row in wb[ws_name].rows for cell in row])

        test_all_cells = []
        wb = load_workbook(filename=f'output/{file_name}', read_only=True)
        for ws_name in wb.sheetnames:
            test_all_cells.extend([cell.value for row in wb[ws_name].rows for cell in row])

        assert ref_all_cells == test_all_cells
Ejemplo n.º 2
0
    def test_export_tabular_xlsx(self):

        pj = json.loads(open("files/test.boris").read())

        obs_id = "observation #1"
        parameters = {
            "selected subjects": ["subject1", "subject2"],
            "selected behaviors": ["p", "s"]
        }
        file_name = "test_export_events_tabular.xlsx"
        output_format = "xlsx"

        r, msg = export_observation.export_events(parameters, obs_id,
                                                  pj[OBSERVATIONS][obs_id],
                                                  pj[ETHOGRAM],
                                                  "output/" + file_name,
                                                  output_format)

        ref_all_cells = []
        wb = load_workbook(filename=f'files/{file_name}', read_only=True)
        for ws_name in wb.sheetnames:
            ref_all_cells.extend(
                [cell.value for row in wb[ws_name].rows for cell in row])

        test_all_cells = []
        wb = load_workbook(filename=f'output/{file_name}', read_only=True)
        for ws_name in wb.sheetnames:
            test_all_cells.extend(
                [cell.value for row in wb[ws_name].rows for cell in row])

        assert ref_all_cells == test_all_cells
Ejemplo n.º 3
0
    def test_export_tabular_csv(self):

        pj = json.loads(open("files/test.boris").read())
        obs_id = "observation #1"
        parameters = {"selected subjects": ["subject1", "subject2"],
                      "selected behaviors": ["p", "s"]}
        file_name = "test_export_events_tabular.csv"
        output_format  = "csv"

        r, msg = export_observation.export_events(parameters,
                                                  obs_id,
                                                  pj[OBSERVATIONS][obs_id],
                                                  pj[ETHOGRAM],
                                                  "output/" + file_name, output_format)

        assert open("files/test_export_events_tabular.csv").read() == open("output/test_export_events_tabular.csv").read()
Ejemplo n.º 4
0
    def test_export_tabular_csv(self):

        pj = json.loads(open("files/test.boris").read())
        obs_id = "observation #1"
        parameters = {SELECTED_SUBJECTS: ["subject1", "subject2"],
                      SELECTED_BEHAVIORS: ["p", "s"]}
        file_name = "test_export_events_tabular.csv"
        output_format  = "csv"

        r, msg = export_observation.export_events(parameters,
                                                  obs_id,
                                                  pj[OBSERVATIONS][obs_id],
                                                  pj[ETHOGRAM],
                                                  "output/" + file_name, output_format)

        assert open("files/test_export_events_tabular.csv").read() == open("output/test_export_events_tabular.csv").read()
Ejemplo n.º 5
0
    def test_export_tabular_html(self):

        pj = json.loads(open("files/test.boris").read())
        obs_id = "observation #1"
        parameters = {
            "selected subjects": ["subject1", "subject2"],
            "selected behaviors": ["p", "s"]
        }
        file_name = "test_export_events_tabular.html"
        output_format = "html"

        r, msg = export_observation.export_events(parameters, obs_id,
                                                  pj[OBSERVATIONS][obs_id],
                                                  pj[ETHOGRAM],
                                                  "output/" + file_name,
                                                  output_format)

        assert open("files/test_export_events_tabular.html").read() == open(
            "output/test_export_events_tabular.html").read()
Ejemplo n.º 6
0
            for k in utilities.sorted_keys(pj[ETHOGRAM])
        ]
        subjects = [
            pj[SUBJECTS][k]["name"]
            for k in utilities.sorted_keys(pj[SUBJECTS])
        ] + [NO_FOCAL_SUBJECT]

        output_format = "tsv"
        if len(args.command) > 1:
            output_format = args.command[1]

        for observation_id in observations_id_list:
            ok, msg = export_observation.export_events(
                {
                    "selected subjects": subjects,
                    "selected behaviors": behaviors
                }, observation_id, pj[OBSERVATIONS][observation_id],
                pj[ETHOGRAM],
                utilities.safeFileName(observation_id + "." + output_format),
                output_format)
            if not ok:
                print(msg)

        sys.exit()

    if "irr" in args.command:
        if len(observations_id_list) != 2:
            print("select 2 observations")
            sys.exit()

        behaviors = [
            pj[ETHOGRAM][k]["code"]