Skip to main content

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 continue statement 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_minutes function 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_activity variable 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