I'm currently making a code for analyzing app usage stats.The dataset looks as below.
date idx AppName EventType EventTime
2019-10-01 15835 clock ACTIVITIY_RESUMED 15:30:02
2019-10-01 15836 clock ACTIVITIY_PAUSED 15:30:15
2019-10-01 15837 gallery ACTIVITY_RESUMED 15:31:42
.
.
2019-10-02 16133 clock ACTIVITY_RESUMED 16:40:30
For each app usage, I coded as below and this works well. However, this gives overall used time which covers several days. I'd like to count used times by each day. Thanks in advance!
app_names = df.AppName.unique()
app_names = df.AppName.value_counts()
app_usage_time = {}
for app in app_names: #
app_resumed = False
app_period = 0
app_tmp_start = None
for i, (index, data) in enumerate(df.iterrows()):
if data.AppName == app:
if data.EventType == 'ACTIVITIY_RESUMED':
app_resumed = True
app_tmp_start = data.datetime.timestamp()
if (data.EventType == 'ACTIVITIY_PAUSED') and (app_tmp_start is not None):
app_resumed = False
app_period += data.datetime.timestamp() - app_tmp_start
app_tmp_start = None
app_usage_time[app] = app_period