- Notifications
You must be signed in to change notification settings - Fork0
R package for processing and analysing mobile (passive) sensing data from m-Path Sense. The main task of mpathsenser is to read m-Path Sense JSON files into a database and provide several convenience functions to aid in data processing.
License
koenniem/mpathsenser
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
You can install the latest version of mpathsenser from CRAN:
install.packages("mpathsenser")Alternatively, you can install the development version from my Gitlabrepo. First, make sure you haveRtools (Windows,Linux) or XCode installed. For XCode, register as anAppleDeveloper (don’t worry, it’s free) andthen runxcode-select --install in a terminal. Then, run the followingcode in R:
devtools::install_git("https://gitlab.kuleuven.be/ppw-okpiv/researchers/u0134047/mpathsenser")
Specify a path variable to wherever you put the JSON files. Make sure touse/ and not a backslash.
path<-"~/Mobile Sensing Study/Data"
If you haven’t done so, unzip all files.
unzip_data(path=path)#> No files found to unzip.
In m-Path Sense, data is written to JSON files as it comes in. In theJSON file format, every file starts with[ and ends with]. If theapp is killed, JSON files may not be properly closed and hence cannot beread by JSON parsers. So, we must first test if all files are in a validJSON format and fix those that are not.
# Test JSONs for problems. Output is a character vector containing bad files (if any).to_fix<- test_jsons(path=path)#> Warning: There were issues in some files# Fix JSON files if there are any.# Note that test_jsons() returns the full path names, so a path directory is not necessary.if (length(to_fix)>0) { fix_jsons(path=NULL,files=to_fix)}#> Fixed 12 files
To import data, first create a database.
db<- create_db(path=path,db_name="some_db.db")
Then, callimport() to start reading in the files.
import(path=path,db=db)#> All files were successfully written to the database.
If everything went correctly, there should be a message that all fileswere successfully written to the database. Otherwiseimport() return acharacter vector containing the files that failed to be imported. Notethat files only need to be imported once, and that new files can beadded to the database by callingimport() again using the samedatabase. Files that were processed previously will be skipped.
Once files are imported, you can establish a database connection withopen_db(). Don’t forget to save it to a variable!
db<- open_db(path=path,db_name="some_db.db")
To find out which participants are in the database (or rather theirparticipant numbers):
get_participants(db)#> participant_id study_id#> 1 2784 Study_Merijn#> 2 carp-data-2022-06-14-09-18-41-055229Z.json example
We can also check what device they are using (which can be found in theDevice table of the database).
device_info(db=db)#> # A tibble: 1 × 10#> participant_id device_id hardware device_name device_manufacturer device_model operating_system#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>#> 1 2784 SP1A.210812… qcom r8q samsung SM-G780G REL#> # ℹ 3 more variables: platform <chr>, operating_system_version <chr>, sdk <chr>
To find out how much data there is in this database, look at the numberof rows as an indication. Note that this operation may be slow for largedatabases, as every tables in the database needs to be queried.
get_nrows(db)#> Accelerometer AirQuality Activity AppUsage Battery Bluetooth Calendar#> 75680 0 2 386 0 1103 98#> Connectivity Device Error Geofence Gyroscope Heartbeat InstalledApps#> 40 12 1 0 26509 0 1236#> Keyboard Light Location Memory Mobility Noise Pedometer#> 0 538 37 84 0 0 4099#> PhoneLog Screen TextMessage Timezone Weather Wifi#> 0 358 0 0 35 84
Now let’s find out how to actually retrieve data from the database.There is a simple function for this, which is calledget_data(). Withthis function you can extract any kind of data you want. Make sure youalso run?get_data for an overview of how to use this (or any other)function. In most functions, you can also leave arguments empty toretrieve all data (e.g. not in a specific time window).
get_data(db=db,# the ACTIVE database connection, open with open_db AND save to a variablesensor="Pedometer",# A sensor name, see mpathsenser::sensors for the full listparticipant_id="2784",# A participant ID, see get_participantsstart_date="2022-06-14",# An optional start date, in the format YYYY-MM-DDend_date="2022-06-15"# An optional end date, in the format YYYY-MM-DD)#> # Source: SQL [?? x 5]#> # Database: sqlite 3.46.0 [C:\Users\u0134047\AppData\Local\Temp\RtmpiImu0Z\readme\some_db.db]#> measurement_id participant_id date time step_count#> <chr> <chr> <chr> <chr> <int>#> 1 ce16d410-ebc5-11ec-a276-bfb1e065589a 2784 2022-06-14 09:38:54 119131#> 2 ce659050-ebc5-11ec-a235-b1fd6433d9e2 2784 2022-06-14 09:38:54 119132#> 3 ceb64860-ebc5-11ec-8f07-93c1927f71b2 2784 2022-06-14 09:38:55 119133#> 4 cf133570-ebc5-11ec-bf61-85f33d53f14d 2784 2022-06-14 09:38:55 119134#> 5 cfb47e80-ebc5-11ec-b17b-85bcc3b36c13 2784 2022-06-14 09:38:56 119136#> # ℹ more rows
A more comprehensive guide is provided in theGet Startedvignette.
For an overview of all functions in this package, see thempathsenserReferenceSite.The database schema used in this package can be foundhere.
If you encounter a clear bug or need help getting a function to run,please file an issue with a minimal reproducible example onGitlab.
Please note that this project is released with aContributor Code ofConduct. By participating in this project you agreeto abide by its terms.
About
R package for processing and analysing mobile (passive) sensing data from m-Path Sense. The main task of mpathsenser is to read m-Path Sense JSON files into a database and provide several convenience functions to aid in data processing.
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.
