Tracking your Focus with Python*ADXiDIuF6b31bRhf

Original Source Here

Track & Visualize

The steps will be:

  • Set up the tracking script
  • Set up the visualization
  • Wrap the code in a Streamlit app

1. The tracking script

Let’s begin by writing the script to track your focus:

Let’s unpack what is happening here:

  1. First we write a function called trackFocus() which simply tracks an interval of time separated by a simple input from the user (like hitting return)
  2. Then we call the calculatefocustime() function which returns the total amount of time tracked on a given day
  3. Finally, we call the logFocus() function which logs the timestamps of the beginning and ending of a session

Now that we have our tracker, let’s write a simple visualization to look at our daily focused time.

2. Visualizing focus time

To visualize focus time we will need two functions, one for creating a dataframe to store our data properly, and another for the plot.

Script to plot focused time

The output:

Focused time from February to June of 2021

The code has two main parts:

  1. Creating the dataframe with the create_focus_df() function
  2. Plotting the focus using the plotly library in the plotfocus() function.

The cool thing about this is that it gives you an idea of how much time you spend actually concentrated on activities, and how that varies in time.

For me the insights are helpful, because they give me an overview of my consistency and my overall performance in terms of the time spent doing productive work.

3. Wrapping things up in a Streamlit app

Now, to finish things off, let’s make a simple dashboard app with Streamlit to be able to visualize our data anytime with just one simple command from the terminal.

Now, in the terminal we run:

streamlit run


Trending AI/ML Article Identified & Digested via Granola by Ramsey Elbasheer; a Machine-Driven RSS Bot

%d bloggers like this: