## 3 Materials and Methods
### Data Pre-Processing and Generated Dataset  
Due to the number of records, as well as their nature, it was necessary to conduct several refinement processes in order to be able to effectively use these data. The first step was to condense the different events into cycles to profile the users. To accomplish this, several approaches were considered, including grouping by time window, grouping by event typology, and grouping by locked/unlocked cycles. As the focus of the study was oriented towards the uses applied to the mobile device, the decision was made to use the lock/unlock cycle classification approach, which was achieved with the algorithm in Algorithm 1. As described, the filtering of the locked/unlocked events of all users was performed first. After this, they were sorted temporally, from oldest to newest. Finally, a loop was performed that checked the input or output of lock/unlock events and stored this information in a lexicon to then assign the type of cycle to each record. ```
1:Let _cycles_ = {}
2:foruser = 0, 1, 2,..., N from usersdo
3:Assign user_events all the user events on smartphone that are locked/unlocked events
4:Let in_locked = False variable
5:Let in_unlocked = False variable
6:foruser_event = 0, 1, 2,..., M from user_eventsdo
7:ifuser_event is the first then
8:ifuser_event is an locked event then
9: Assign in_locked = True variable
10:Add a new register to _cycles_ dictionary, with kind lock and init with the timestamp of the event
11:else
12: Assign in_unlocked = True variable
13:Add a new register to _cycles_ dictionary, with kind unlock and init with the timestamp of the event
14:endif
15:else
16:ifin_lock and user_event is a unlocked event then
17: Access to the register of _cycles_ variable and add the end of the cycle with the last event timestamp
18: Access in_lock = False
19: Access in_unlock = True
20:Add a new register to _cycles_ dictionary, with kind unlock and init with the timestamp of the current event
21:else if in_unlock and user_event is a locked event then
22: Access to the register of _cycles_ variable and add the end of the cycle with the last event timestamp
23: Assign in_unlock = False
24: Access in_lock = True
25:Add a new register to _cycles_ dictionary, with kind unlock and init with the timestamp of the current event
26:endif
27:endif
28:endif
29:Use _cycles_ to assign the kind of cycle of every user event
30:endfor
```  
**Algorithm 1** Locked/Unlocked cycles generation  
The second step comprised combining the user event logs (classified into locked/unlocked cycles as explained above) with the physical activity logs. Here, we dealt mainly with the difference in the frequency of physical activity and user event collection. To solve this and perform an accurate matching process, an algorithm was designed and implemented that could assign to each event the physical activities closest in time and type; Algorithm 2 provides details of the algorithm. In this case, it was traversed event by event, using the time stamp. With this time stamp and a pre-determined time drift of seconds, a time window was established to locate physical activities. The activities that fell within the window were ordered temporally, and the one closest to the time stamp of the event (or the one with the least temporal drift) was searched.