{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os, sys\n", "from tabulate import tabulate\n", "nb_dir = os.path.split(os.getcwd())[0]\n", "if nb_dir not in sys.path:\n", " sys.path.append(nb_dir)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from features.screen import *\n", "import participants.query_db" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "df_screen_nokia = get_screen_data([\"nokia_0000003\"])" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " id _id timestamp device_id \\\n", "0 245456 155 1615456297079 12324354-e195-4e93-a2d5-268556e3ea5d \n", "1 245455 154 1615456297069 12324354-e195-4e93-a2d5-268556e3ea5d \n", "2 245454 153 1615456288219 12324354-e195-4e93-a2d5-268556e3ea5d \n", "3 245453 152 1615455357213 12324354-e195-4e93-a2d5-268556e3ea5d \n", "4 245452 151 1615455357190 12324354-e195-4e93-a2d5-268556e3ea5d \n", "... ... ... ... ... \n", "1911 33221 5 1583329949659 d5fb52e1-7df8-44b5-a805-8d04ca008061 \n", "1912 33171 4 1583327341863 d5fb52e1-7df8-44b5-a805-8d04ca008061 \n", "1913 33170 3 1583327340983 d5fb52e1-7df8-44b5-a805-8d04ca008061 \n", "1914 33169 2 1583327340739 d5fb52e1-7df8-44b5-a805-8d04ca008061 \n", "1915 33168 1 1583327340713 d5fb52e1-7df8-44b5-a805-8d04ca008061 \n", "\n", " screen_status participant_id username \n", "0 2 21 nokia_0000003 \n", "1 0 21 nokia_0000003 \n", "2 1 21 nokia_0000003 \n", "3 2 21 nokia_0000003 \n", "4 0 21 nokia_0000003 \n", "... ... ... ... \n", "1911 3 21 nokia_0000003 \n", "1912 3 21 nokia_0000003 \n", "1913 1 21 nokia_0000003 \n", "1914 2 21 nokia_0000003 \n", "1915 0 21 nokia_0000003 \n", "\n", "[1916 rows x 7 columns]\n" ] } ], "source": [ "print(df_screen_nokia)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "participants_inactive_usernames = participants.query_db.get_usernames()\n", "df_screen_inactive = get_screen_data(participants_inactive_usernames)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
off 70243
on 70012
locked 63080
unlocked36666
" ], "text/plain": [ "'\\n\\n\\n\\n\\n\\n\\n
off 70243
on 70012
locked 63080
unlocked36666
'" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_screen_inactive[\"screen_status\"] = df_screen_inactive[\"screen_status\"].astype(\"category\").cat.rename_categories(screen_status)\n", "screen_freq = df_screen_inactive.value_counts(\"screen_status\")\n", "tabulate(screen_freq.to_frame(), tablefmt='html')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{0: 'off', 1: 'on', 2: 'locked', 3: 'unlocked'}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "screen_status" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A typical sequence might be: off -> locked -> on -> unlocked (0 -> 2 -> 1 -> 3)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
screen_status
-1.0810
2.0779
-3.0238
1.044
-2.038
0.06
\n", "
" ], "text/plain": [ " screen_status\n", "-1.0 810\n", " 2.0 779\n", "-3.0 238\n", " 1.0 44\n", "-2.0 38\n", " 0.0 6" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "status_diff = df_screen_nokia.sort_values(\"timestamp\")[\"screen_status\"].diff()\n", "status_diff.value_counts().to_frame()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "But I have also seen off -> on -> unlocked (with 2 - locked missing) and off -> locked -> on -> off -> locked (*again*)." ] } ], "metadata": { "jupytext": { "formats": "ipynb,auto:percent" }, "kernelspec": { "display_name": "straw2analysis", "language": "python", "name": "straw2analysis" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.4" } }, "nbformat": 4, "nbformat_minor": 4 }