Skip to content

autora.variable.time

DVTime

Bases: DV, VTime

A class representing time as a dependent variable.

Source code in temp_dir/core/src/autora/variable/time.py
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
class DVTime(DV, VTime):
    """
    A class representing time as a dependent variable.
    """

    _name = "time_DV"
    _UID = ""
    _variable_label = "Time"
    _units = "s"
    _priority = 0
    _value_range = (0, 604800)  # don't record more than a week
    _value = 0

    _is_covariate = True

    # Initializes reference time.
    # The reference time usually denotes the beginning of an experiment trial.
    def __init__(self, *args, **kwargs):
        """
        Initializes the time as dependent variable. The reference time usually denotes
        the beginning of an experiment trial.

        For arguments, see [autora.variable.Variable][autora.variable.Variable.__init__]
        """
        print(self._variable_label)
        super(DVTime, self).__init__(*args, **kwargs)
        print(self._variable_label)

    # Measure number of seconds relative to reference time
    def measure(self):
        """
        Measures the time in seconds relative to the reference time.
        """
        value = time.time() - self._t0
        self.set_value(value)

__init__(*args, **kwargs)

Initializes the time as dependent variable. The reference time usually denotes the beginning of an experiment trial.

For arguments, see [autora.variable.Variable][autora.variable.Variable.__init__]

Source code in temp_dir/core/src/autora/variable/time.py
86
87
88
89
90
91
92
93
94
95
def __init__(self, *args, **kwargs):
    """
    Initializes the time as dependent variable. The reference time usually denotes
    the beginning of an experiment trial.

    For arguments, see [autora.variable.Variable][autora.variable.Variable.__init__]
    """
    print(self._variable_label)
    super(DVTime, self).__init__(*args, **kwargs)
    print(self._variable_label)

measure()

Measures the time in seconds relative to the reference time.

Source code in temp_dir/core/src/autora/variable/time.py
 98
 99
100
101
102
103
def measure(self):
    """
    Measures the time in seconds relative to the reference time.
    """
    value = time.time() - self._t0
    self.set_value(value)

IVTime

Bases: IV, VTime

A class representing time as an independent variable.

Source code in temp_dir/core/src/autora/variable/time.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class IVTime(IV, VTime):
    """
    A class representing time as an independent variable.
    """

    _name = "time_IV"
    _UID = ""
    _variable_label = "Time"
    _units = "s"
    _priority = 0
    _value_range = (0, 3600)
    _value = 0

    # Initializes reference time.
    # The reference time usually denotes the beginning of an experiment trial.
    def __init__(self, *args, **kwargs):
        """
        Initializes the time as independent variable.

        For arguments, see [autora.variable.Variable][autora.variable.Variable.__init__]
        """
        super(IVTime, self).__init__(*args, **kwargs)

    # Waits until specified time has passed relative to reference time
    def manipulate(self):
        """
        Waits for the specified time to pass.
        """

        t_wait = self.get_value() - (time.time() - self._t0)
        if t_wait <= 0:
            return
        else:
            time.sleep(t_wait)

    def disconnect(self):
        """
        Disconnects the time.
        """
        pass

__init__(*args, **kwargs)

Initializes the time as independent variable.

For arguments, see [autora.variable.Variable][autora.variable.Variable.__init__]

Source code in temp_dir/core/src/autora/variable/time.py
42
43
44
45
46
47
48
def __init__(self, *args, **kwargs):
    """
    Initializes the time as independent variable.

    For arguments, see [autora.variable.Variable][autora.variable.Variable.__init__]
    """
    super(IVTime, self).__init__(*args, **kwargs)

disconnect()

Disconnects the time.

Source code in temp_dir/core/src/autora/variable/time.py
62
63
64
65
66
def disconnect(self):
    """
    Disconnects the time.
    """
    pass

manipulate()

Waits for the specified time to pass.

Source code in temp_dir/core/src/autora/variable/time.py
51
52
53
54
55
56
57
58
59
60
def manipulate(self):
    """
    Waits for the specified time to pass.
    """

    t_wait = self.get_value() - (time.time() - self._t0)
    if t_wait <= 0:
        return
    else:
        time.sleep(t_wait)

VTime

A class representing time as a general experimental variable.

Source code in temp_dir/core/src/autora/variable/time.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class VTime:
    """
    A class representing time as a general experimental variable.
    """

    _t0 = 0

    def __init__(self):
        """
        Initializes the time.
        """
        self._t0 = time.time()

    # Resets reference time.
    def reset(self):
        """
        Resets the time.
        """
        self._t0 = time.time()

__init__()

Initializes the time.

Source code in temp_dir/core/src/autora/variable/time.py
13
14
15
16
17
def __init__(self):
    """
    Initializes the time.
    """
    self._t0 = time.time()

reset()

Resets the time.

Source code in temp_dir/core/src/autora/variable/time.py
20
21
22
23
24
def reset(self):
    """
    Resets the time.
    """
    self._t0 = time.time()