Python Program Design: Analyzing Screen Time Data with Lists
Khan AcademyApril 21, 20255 min5,225 views
3 connectionsΒ·5 entities in this videoβAnalyzing Screen Time Data
- π± The video demonstrates how to design a Python program to analyze personal screen time usage data.
- π‘ The goal is to understand usage patterns by calculating total active minutes and the number of distinct phone sessions.
Data Structure and Preparation
- π Screen time data is formatted as a list, where each element represents a minute and records the app used or an empty string for idle time.
- π It's good practice to store data in a separate file and import it into the program module to avoid clutter.
Counting Active Minutes
- β±οΈ A function is created to count total active minutes, excluding idle time (represented by empty strings).
- π« The
continuestatement is used to skip idle minutes during iteration. - π§ͺ Test cases with smaller datasets are used to verify the function's accuracy, including scenarios with all idle, some active, and all active minutes.
Excluding Specific Apps
- βοΈ The
count_minutesfunction is enhanced to accept a list of apps to exclude from the count. - β This allows for focusing on personal screen time by excluding work-related apps.
Counting Screen Time Sessions
- π€³ A function is developed to count distinct phone sessions, defined as periods of app usage separated by idle time.
- β‘οΈ A new session is counted when the current element is an app name and the previous element was an empty string.
- π Initializing a
previous_activityvariable to an empty string correctly handles sessions starting at the beginning of the data.
Calculating Average Session Length
- π The average session length is calculated by dividing total active minutes by the number of sessions.
- β οΈ A check for zero sessions is implemented to prevent a division-by-zero error, returning zero in such cases.
- π― The analysis can be expanded by excluding work apps from session calculations or comparing data across multiple days.
Knowledge graph5 entities Β· 3 connections
How they connect
An interactive map of every person, idea, and reference from this conversation. Hover to trace connections, click to explore.
Hover Β· drag to explore
5 entities
Chapters3 moments
Key Moments
Transcript22 segments
Full Transcript
Topics10 themes
Whatβs Discussed
PythonListsScreen Time AnalysisData StructuresProgrammingFunctionsIterationConditional LogicModule ImportData Analysis
Smart Objects5 Β· 3 links
ConceptΒ· 1
ProductΒ· 1
CompanyΒ· 1
MediasΒ· 2