Skip to content

Commit 0c054ca

Browse files
authored
Merge pull request #143 from BIDMCDigitalPsychiatry/sensorkit
integrating raw sensorkit features
2 parents 561bbf1 + 374f764 commit 0c054ca

File tree

5 files changed

+229
-0
lines changed

5 files changed

+229
-0
lines changed

cortex/raw/ambient_light.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
""" Module for raw feature ambient light """
2+
from ..feature_types import raw_feature
3+
4+
@raw_feature(
5+
name="com.apple.sensorkit.ambient_light",
6+
dependencies=["com.apple.sensorkit.ambient_light"]
7+
)
8+
def ambient_light(_limit=10000,
9+
cache=False,
10+
recursive=True,
11+
**kwargs):
12+
""" Get all ambient light data bounded by the time interval.
13+
14+
Args:
15+
_limit (int): The maximum number of sensor events to query for in a single request
16+
cache (bool): Indicates whether to save raw data locally in cache dir
17+
recursive (bool): if True, continue requesting data until all data is
18+
returned; else just one request
19+
20+
Returns:
21+
timestamp (int): The UTC timestamp for the accelerometer event.
22+
placement (int): An integer representation of the position of the light source relative to the phone.
23+
chromaticity (dict): A dictionary containing an x, y pair describing hue and colorfulness of the light source.
24+
lux (dict): A dictionary describing the luminous flux (perceived power of observed light per unit time)
25+
per unit area, in units of lux (lx).
26+
27+
Example:
28+
[{'timestamp': 1666528657228,
29+
'placement': 1,
30+
'chromaticity': {'x': 0.4228740930557251, 'y': 0.35222673416137695},
31+
'lux': {'value': 0,
32+
'unit': {'converter': {'coefficient': 1, 'constant': 0},
33+
'symbol': 'lx'}}},
34+
{'timestamp': 1666528656036,
35+
'placement': 1,
36+
'lux': {'value': 0,
37+
'unit': {'converter': {'coefficient': 1, 'constant': 0},
38+
'symbol': 'lx'}},
39+
'chromaticity': {'x': 0.38883176445961, 'y': 0.382804811000824}},
40+
{'timestamp': 1666528654423,
41+
'placement': 1,
42+
'chromaticity': {'x': 0.37757551670074463, 'y': 0.36116909980773926},
43+
'lux': {'value': 0,
44+
'unit': {'converter': {'coefficient': 1, 'constant': 0},
45+
'symbol': 'lx'}}}]
46+
"""
47+
return

cortex/raw/device_usage.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
""" Module for raw feature device_usage """
2+
from ..feature_types import raw_feature
3+
4+
@raw_feature(
5+
name="com.apple.sensorkit.device_usage",
6+
dependencies=["com.apple.sensorkit.device_usage"]
7+
)
8+
def device_usage(_limit=10000,
9+
cache=False,
10+
recursive=True,
11+
**kwargs):
12+
""" Get all device usage data bounded by the time interval.
13+
14+
Args:
15+
_limit (int): The maximum number of sensor events to query for in a single request
16+
cache (bool): Indicates whether to save raw data locally in cache dir
17+
recursive (bool): if True, continue requesting data until all data is
18+
returned; else just one request
19+
20+
Returns:
21+
timestamp (int): The UTC timestamp for the accelerometer event.
22+
totalScreenWakes (int): Total number of times the screen wakes up.
23+
totalUnlockDuration (int): Total amount of time the phone is unlocked (seconds).
24+
totalUnlocks (int): Total number of times the phone is unlocked.
25+
duration (int): Duration of which the report spans (seconds).
26+
27+
Example:
28+
[{'timestamp': 1666494900006,
29+
'totalScreenWakes': 7,
30+
'totalUnlockDuration': 298,
31+
'duration': 900,
32+
'totalUnlocks': 5},
33+
{'timestamp': 1666494900206,
34+
'totalUnlockDuration': 298,
35+
'duration': 900,
36+
'totalScreenWakes': 6,
37+
'totalUnlocks': 6},
38+
{'timestamp': 1666494000406,
39+
'totalScreenWakes': 0,
40+
'duration': 900,
41+
'totalUnlocks': 0,
42+
'totalUnlockDuration': 0}]
43+
"""
44+
return

cortex/raw/messages_usage.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
""" Module for raw feature messages usage """
2+
from ..feature_types import raw_feature
3+
4+
@raw_feature(
5+
name="com.apple.sensorkit.messages_usage",
6+
dependencies=["com.apple.sensorkit.messages_usage"]
7+
)
8+
def messages_usage(_limit=10000,
9+
cache=False,
10+
recursive=True,
11+
**kwargs):
12+
""" Get all messages usage data bounded by the time interval.
13+
14+
Args:
15+
_limit (int): The maximum number of sensor events to query for in a single request
16+
cache (bool): Indicates whether to save raw data locally in cache dir
17+
recursive (bool): if True, continue requesting data until all data is
18+
returned; else just one request
19+
20+
Returns:
21+
timestamp (int): The UTC timestamp for the accelerometer event.
22+
duration (int): The duration over which the report spans (seconds).
23+
totalUniqueContacts (int): Total number of unique contacts over the report span.
24+
totalIncomingMessages (int): Total number of incoming messages over the report span.
25+
totalOutgoingMessages (int): Total number of outgoing messages over the report span.
26+
27+
Example:
28+
[{'timestamp': 1666494000034,
29+
'duration': 1800,
30+
'totalUniqueContacts': 2,
31+
'totalIncomingMessages': 0,
32+
'totalOutgoingMessages': 5},
33+
{'timestamp': 1666494000234,
34+
'duration': 1800,
35+
'totalUniqueContacts': 1,
36+
'totalIncomingMessages': 0,
37+
'totalOutgoingMessages': 1},
38+
{'timestamp': 1666494000428,
39+
'duration': 1800,
40+
'totalUniqueContacts': 3,
41+
'totalIncomingMessages': 0,
42+
'totalOutgoingMessages': 8}]
43+
"""
44+
return

cortex/raw/phone_usage.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
""" Module for raw feature phone usage """
2+
from ..feature_types import raw_feature
3+
4+
@raw_feature(
5+
name="com.apple.sensorkit.phone_usage",
6+
dependencies=["com.apple.sensorkit.phone_usage"]
7+
)
8+
def phone_usage(_limit=10000,
9+
cache=False,
10+
recursive=True,
11+
**kwargs):
12+
""" Get all phone usage data bounded by the time interval.
13+
14+
Args:
15+
_limit (int): The maximum number of sensor events to query for in a single request
16+
cache (bool): Indicates whether to save raw data locally in cache dir
17+
recursive (bool): if True, continue requesting data until all data is
18+
returned; else just one request
19+
20+
Returns:
21+
timestamp (int): The UTC timestamp for the accelerometer event.
22+
duration (int): The duration over which the report spans (seconds)
23+
totalUniqueContacts (int): Total number of unique contacts over the report span.
24+
totalIncomingCalls (int): Total number of incoming calls over the report span.
25+
totalOutgoingCalls (int): Total number of outgoing calls over the report span.
26+
totalPhoneCallDuration (float): Total phone call duration (seconds).
27+
28+
Example:
29+
[{'timestamp': 1666411200036,
30+
'totalIncomingCalls': 0,
31+
'totalOutgoingCalls': 4,
32+
'duration': 86400,
33+
'totalPhoneCallDuration': 39.51534700393677,
34+
'totalUniqueContacts': 1},
35+
{'timestamp': 1666411200033,
36+
'totalPhoneCallDuration': 39.51534700393677,
37+
'totalIncomingCalls': 0,
38+
'duration': 86400,
39+
'totalOutgoingCalls': 4,
40+
'totalUniqueContacts': 1},
41+
{'timestamp': 1666411200031,
42+
'totalPhoneCallDuration': 39.51534700393677,
43+
'totalUniqueContacts': 1,
44+
'totalOutgoingCalls': 4,
45+
'totalIncomingCalls': 0,
46+
'duration': 86400}]
47+
"""
48+
return

cortex/raw/visits.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
""" Module for raw feature visits """
2+
from ..feature_types import raw_feature
3+
4+
@raw_feature(
5+
name="com.apple.sensorkit.visits",
6+
dependencies=["com.apple.sensorkit.visits"]
7+
)
8+
def visits(_limit=10000,
9+
cache=False,
10+
recursive=True,
11+
**kwargs):
12+
""" Get all visits data bounded by the time interval.
13+
14+
Args:
15+
_limit (int): The maximum number of sensor events to query for in a single request
16+
cache (bool): Indicates whether to save raw data locally in cache dir
17+
recursive (bool): if True, continue requesting data until all data is
18+
returned; else just one request
19+
20+
Returns:
21+
timestamp (int): The UTC timestamp for the accelerometer event.
22+
distanceFromHome (float): Distance of location from home (meters).
23+
locationCategory (int): The type of location visited.
24+
depatureDateInterval (dict): The timestamp since 00:00:00 UTC on 1 January 2001
25+
and error (seconds, seconds) of the departure time.
26+
arrivalDateInterval (dict): The UTC timestamp 00:00:00 UTC on 1 January 2001
27+
and error (seconds, seconds) of the arrival time.
28+
29+
Example:
30+
[{'timestamp': 1666451574083,
31+
'distanceFromHome': 2748.563657340416,
32+
'locationCategory': 0,
33+
'departureDateInterval': {'start': 688072500, 'duration': 900},
34+
'arrivalDateInterval': {'start': 688092500, 'duration': 900}},
35+
{'timestamp': 1666451584080,
36+
'distanceFromHome': 0,
37+
'arrivalDateInterval': {'start': 688084200, 'duration': 900},
38+
'locationCategory': 1,
39+
'departureDateInterval': {'start': 688124200, 'duration': 900}},
40+
{'timestamp': 1666451594080,
41+
'locationCategory': 0,
42+
'distanceFromHome': 2748.563657340416,
43+
'arrivalDateInterval': {'start': 688072500, 'duration': 900},
44+
'departureDateInterval': {'start': 688072500, 'duration': 900}}]
45+
"""
46+
return

0 commit comments

Comments
 (0)