Ejemplo n.º 1
0
    def setup():
        it.regions_x = [
            Region(Point(0, 0), Point(10, 0)),
            Region(Point(10, 0), Point(20, 0)),
            Region(Point(20, 0), Point(30, 0)),
            Region(Point(30, 0), Point(40, 0)),
        ]
        it.item_x = Item(1, 1, it.regions_x)
        it.fixations_x = [
            Fixation(Point(0, 0), 0, 100, 0, it.regions_x[0]),
            Fixation(Point(3, 0), 100, 200, 1, it.regions_x[0]),
            Fixation(Point(22, 0), 200, 300, 2, it.regions_x[2]),
            Fixation(Point(12, 0), 300, 400, 3, it.regions_x[1]),
        ]
        it.trial_x = Trial(1, 400, it.item_x, it.fixations_x)

        it.excluded_fix = [
            Fixation(Point(1, 0), 0, 50, 0, it.regions_x[0], excluded=True),
            Fixation(Point(2, 0), 50, 100, 1, it.regions_x[0], excluded=False),
            Fixation(Point(22, 0), 110, 150, 2, it.regions_x[2],
                     excluded=True),
            Fixation(Point(13, 0),
                     200,
                     250,
                     3,
                     it.regions_x[1],
                     excluded=False),
            Fixation(Point(1, 0), 300, 350, 4, it.regions_x[0], excluded=True),
        ]

        it.excluded_trial = Trial(1, 350, it.item_x, it.excluded_fix)

        it.regions_y = [
            Region(Point(0, 0), Point(10, 0)),
            Region(Point(10, 0), Point(0, 1)),
            Region(Point(0, 1), Point(10, 1)),
            Region(Point(10, 1), Point(20, 1)),
        ]
        it.item_y = Item(2, 1, it.regions_y)
        it.fixations_y = [
            Fixation(Point(12, 0), 0, 100, 0, it.regions_y[1]),
            Fixation(Point(12, 1), 100, 200, 1, it.regions_y[3]),
            Fixation(Point(15, 1), 200, 300, 2, it.regions_y[3]),
            Fixation(Point(8, 0), 300, 400, 3, it.regions_y[0]),
        ]
        it.trial_y = Trial(1, 400, it.item_y, it.fixations_y)

        it.fixations_x2 = [
            Fixation(Point(0, 0), 0, 150, 0, it.regions_x[0]),
            Fixation(Point(3, 0), 150, 200, 1, it.regions_x[0]),
            Fixation(Point(14, 0), 200, 350, 2, it.regions_x[1]),
            Fixation(Point(12, 0), 350, 400, 3, it.regions_x[1]),
            Fixation(Point(3, 0), 400, 550, 4, it.regions_x[0]),
            Fixation(Point(11, 0), 650, 700, 5, it.regions_x[1]),
            Fixation(Point(21, 0), 750, 800, 6, it.regions_x[2]),
            Fixation(Point(11, 0), 850, 900, 7, it.regions_x[1]),
        ]
        it.trial_x2 = Trial(1, 600, it.item_x, it.fixations_x2)
Ejemplo n.º 2
0
    def setup_all():
        # /aaaaaaaaaa/aaaaaaaaaa/aaaaaaaaaa/aaaaaaaaaa/
        it.regions_x = [
            Region(Point(0, 0), Point(10, 0)),
            Region(Point(10, 0), Point(20, 0)),
            Region(Point(20, 0), Point(30, 0)),
            Region(Point(30, 0), Point(40, 0)),
        ]
        it.item_x = Item(1, 1, it.regions_x)
        it.fixations_x = [
            Fixation(Point(0, 0), 0, 150, 0, it.regions_x[0]),
            Fixation(Point(3, 0), 150, 200, 1, it.regions_x[0]),
            Fixation(Point(22, 0), 200, 350, 2, it.regions_x[2]),
            Fixation(Point(24, 0), 350, 350, 3, it.regions_x[2], excluded=True),
            Fixation(Point(12, 0), 350, 400, 4, it.regions_x[1]),
            Fixation(Point(3, 0), 400, 550, 5, it.regions_x[0]),
            Fixation(Point(11, 0), 550, 600, 6, it.regions_x[1]),
        ]
        it.trial_x = Trial(1, 600, it.item_x, it.fixations_x)

        it.fixations_x2 = [
            Fixation(Point(0, 0), 0, 150, 0, it.regions_x[0]),
            Fixation(Point(3, 0), 150, 200, 1, it.regions_x[0]),
            Fixation(Point(22, 0), 200, 370, 2, it.regions_x[2]),
            Fixation(Point(24, 0), 370, 380, 3, it.regions_x[2], excluded=True),
            Fixation(Point(21, 0), 380, 400, 4, it.regions_x[2]),
            Fixation(Point(3, 0), 400, 550, 5, it.regions_x[0]),
        ]
        it.trial_x2 = Trial(1, 600, it.item_x, it.fixations_x2)

        # aaaaaaaaaa/aaaaaaaaa.../
        # aaaaaaaaaa/aaaaaaaaaa/
        it.regions_y = [
            Region(Point(0, 0), Point(10, 0)),
            Region(Point(10, 0), Point(0, 1)),
            Region(Point(0, 1), Point(10, 1)),
            Region(Point(10, 1), Point(20, 1)),
        ]
        it.item_y = Item(2, 1, it.regions_y)
        it.fixations_y = [
            Fixation(Point(12, 0), 0, 100, 0, it.regions_y[1]),
            Fixation(Point(12, 1), 100, 150, 1, it.regions_y[3]),
            Fixation(Point(15, 1), 150, 350, 2, it.regions_y[3]),
            Fixation(Point(8, 0), 350, 400, 3, it.regions_y[0]),
            Fixation(Point(15, 1), 400, 600, 4, it.regions_y[3]),
            Fixation(Point(17, 1), 600, 700, 5, it.regions_y[3]),
        ]
        it.trial_y = Trial(1, 400, it.item_y, it.fixations_y)
Ejemplo n.º 3
0
    def setup():
        # /aaaaaaaaaa/aaaaaaaaaa/aaaaaaaaaa/aaaaaaaaaa/
        it.regions_x = [
            Region(Point(0, 0), Point(10, 0)),
            Region(Point(10, 0), Point(20, 0)),
            Region(Point(20, 0), Point(30, 0)),
            Region(Point(30, 0), Point(40, 0)),
        ]
        it.item_x = Item(1, 1, it.regions_x)
        it.fixations_x = [
            Fixation(Point(0, 0), 0, 100, 0, it.regions_x[0]),
            Fixation(Point(3, 0), 120, 200, 1, it.regions_x[0]),
            Fixation(Point(22, 0), 230, 300, 2, it.regions_x[2]),
            Fixation(Point(12, 0), 340, 400, 3, it.regions_x[1]),
            Fixation(Point(15, 0), 400, 450, 4, it.regions_x[1],
                     excluded=True),
        ]
        it.trial_x = Trial(1, 400, it.item_x, it.fixations_x)

        it.no_regressions_fix = [
            Fixation(Point(0, 0), 0, 100, 0, it.regions_x[0]),
            Fixation(Point(3, 0), 110, 200, 1, it.regions_x[0]),
            Fixation(Point(22, 0), 220, 300, 2, it.regions_x[2]),
            Fixation(Point(31, 0), 330, 400, 3, it.regions_x[3]),
        ]

        it.no_regressions = Trial(1, 400, it.item_x, it.no_regressions_fix)

        # aaaaaaaaaa/aaaaaaaaa.../
        # aaaaaaaaaa/aaaaaaaaaa/
        it.regions_y = [
            Region(Point(0, 0), Point(10, 0)),
            Region(Point(10, 0), Point(0, 1)),
            Region(Point(0, 1), Point(10, 1)),
            Region(Point(10, 1), Point(20, 1)),
        ]
        it.item_y = Item(2, 1, it.regions_y)
        it.fixations_y = [
            Fixation(Point(12, 0), 0, 100, 0, it.regions_y[1]),
            Fixation(Point(12, 1), 110, 200, 1, it.regions_y[3]),
            Fixation(Point(15, 1), 220, 300, 2, it.regions_y[3]),
            Fixation(Point(8, 0), 330, 400, 3, it.regions_y[0]),
        ]
        it.trial_y = Trial(1, 400, it.item_y, it.fixations_y)
Ejemplo n.º 4
0
 def setup_rb():
     it.right_bounded_fixations = [
         Fixation(Point(0, 0), 0, 150, 0, it.regions_x[0]),
         Fixation(Point(3, 0), 150, 200, 1, it.regions_x[0]),
         Fixation(Point(14, 0), 200, 350, 2, it.regions_x[1]),
         Fixation(Point(12, 0), 350, 400, 3, it.regions_x[1]),
         Fixation(Point(3, 0), 400, 550, 4, it.regions_x[0]),
         Fixation(Point(11, 0), 550, 600, 5, it.regions_x[1]),
         Fixation(Point(21, 0), 650, 700, 6, it.regions_x[2]),
         Fixation(Point(11, 0), 750, 800, 7, it.regions_x[1]),
     ]
     it.trial_right_bound = Trial(1, 600, it.item_x, it.right_bounded_fixations)
Ejemplo n.º 5
0
def parse(
    filename: str,
    items: Dict[ItemNum, Dict[Condition, Item]],
    config: Configuration = Configuration(),
    da1_type: str = None,
) -> Experiment:
    """
    Parses DA1-like files into sideeye Experiment objects, given column positions.

    Args:
        filename (str): DA1 file.
        items (Dict[ItemNum, Dict[Condition, Item]]): List of items in the experiment.
        da1_type (str): Type of DA1 file - `timdrop`, `robodoc`, or `None` for any other type.
    """
    if config.terminal_output > 0:
        print("\nParsing DA1 file: %s" % filename)

    validate(filename, config.da1_fields.fixation_start, da1_type)

    def parse_fixations(line, item):
        """Parses a list of (x, y, start time, end time) numbers into a list of Fixations."""
        fixations = []
        for pos in range(0, len(line), 4):
            x_pos = line[pos]
            y_pos = line[pos + 1]
            start = line[pos + 2]
            end = line[pos + 3]
            if (end - start) > config.cutoffs.min and (
                    config.cutoffs.max < 0 or
                (end - start) < config.cutoffs.max):
                fixations += [
                    Fixation(
                        Point(x_pos, y_pos),
                        start,
                        end,
                        len(fixations),
                        item.find_region(x_pos, y_pos),
                    )
                ]
            else:
                fixations += [
                    Fixation(
                        Point(x_pos, y_pos),
                        start,
                        end,
                        len(fixations),
                        item.find_region(x_pos, y_pos),
                        excluded=True,
                    )
                ]

        return fixations

    with open(filename) as da1_file:
        trials: List[Trial] = []
        for da1_line in da1_file:
            split_line = da1_line.split()
            number = split_line[config.da1_fields.number]
            condition = split_line[config.da1_fields.condition]
            line: List[int] = [int(x) for x in split_line]
            if config.terminal_output == 2 or config.terminal_output >= 5:
                print("\tParsing trial: %s" % line[config.da1_fields.index])
            if items[number][condition]:
                fixations = parse_fixations(
                    line[config.da1_fields.fixation_start:],
                    items[number][condition])
                trials += [
                    Trial(
                        line[config.da1_fields.index],
                        line[config.da1_fields.time],
                        items[number][condition],
                        fixations,
                        config.cutoffs.include_fixation,
                        config.cutoffs.include_saccades,
                    )
                ]
            else:
                print(
                    "Item number",
                    number,
                    ", condition",
                    condition,
                    "does not exist. It was not added to the Experiment object.",
                )

        return Experiment("".join(os.path.split(filename)[1].split(".")[:-1]),
                          trials, filename)
Ejemplo n.º 6
0
def save_trial_measure(trial: Trial, measure: str, value: Any) -> Any:
    """Adds measure to trial.measures, returns dictionary."""
    trial.trial_measures[measure] = value
    return value
Ejemplo n.º 7
0
def get_trials(
    asc: str,
    items: Dict[Condition, Dict[ItemNum, Item]],
    config: ASCParsingConfig = Configuration().asc_parsing,
) -> List[Trial]:
    """
    Parses .ASC text into a list of Trial objects.

    Args:
        asc (string): Text of .ASC file.
        items (Dict[str, Dict[str, Item]]): List of items in experiments.
        config (ASCParsingConfig): Configuration for .ASC parsing.
    """
    characters: List[CharPosition] = []
    fixations: List[Fixation] = []
    fixation_start_time = 0
    trials: List[Trial] = []
    exclude = False
    blinks = 0
    start_time = 0
    condition: Optional[str] = None
    item: Optional[str] = None
    for line in asc.split("\n"):
        if line.split() and line.split()[0] in LINE_TYPES:
            start_time = get_start(line) or start_time
            condition = get_condition(line) or condition
            item = get_item(line) or item
            char = get_char(line)
            characters = characters + [char] if char else characters
            new_fixation, fixation_start_time = (
                get_fixation(
                    line,
                    characters,
                    items[item][condition],
                    len(fixations),
                    fixation_start_time,
                )
                if start_time
                and item
                and condition
                and item in items
                and condition in items[item]
                else (None, fixation_start_time)
            )
            fixations = (
                get_new_fixations(new_fixation, fixations, config)
                if new_fixation
                else fixations
            )
            if (
                config.max_saccade_dur
                and len(fixations) > 1
                and fixations[-1].start - fixations[-2].end > config.max_saccade_dur
            ):
                exclude = True
            blink_dur = get_blink_dur(line)
            if blink_dur:
                blinks += 1
                if config.blink_max_dur and blink_dur > config.blink_max_dur:
                    exclude = True
                if config.blink_max_count and blinks > config.blink_max_count:
                    exclude = True
            end_time = get_end(line)
            if end_time:
                if (
                    item
                    and condition
                    and item in items
                    and condition in items[item]
                    and not exclude
                ):
                    trials += [
                        Trial(
                            len(trials),
                            end_time - start_time,
                            items[item][condition],
                            fixations,
                        )
                    ]
                start_time = 0
                fixations = []
                fixation_start_time = 0
                characters = []
                exclude = False
                blinks = 0
                item = None
                condition = None
    return trials