Introducing Lifevisor

Introducing Lifevisor

Time for a quick break from the focus of the usual blog posts, to announce a CLI tool and system I have been working on recently.

Github link: here

Background

At the start of 2024, I worked through a blog series from the Harvard Business Review called Use Strategic Thinking to Create the Life You Want, essentially it is about identifying how you spend the time you have in your life, breaking them down into categories, and having set goals and deadlines for certain categories, for example: You might have the goal to start your own business, etc. and then identify the time you spend towards that goal.

One practice given in the the blog series is performing a weekly review of your time, and identifying how it aligns with your goals, and you can then make changes incrementally to reach those goals.

For me, part of the process of that weekly review is using ActivityWatch on my Desktop and Phone, and every Sunday, going through the time spent and seeing what can be done to reach certain goals like:

  • Less time on social media, or
  • More time writing code

With my experience with Observability, I started coming up with the idea, that while a weekly review is great, what if we could get closer to the data and essentially have the ability to audit that time on-demand?

Around May 2022, an ActivityWatch community member @SqrtMinusTwo posted their Metabase dashboard: link, that was enough for me to try do it myself, but closer to real-time.

Lifevisor

Lifevisor is a system of three components:

  • Lifevisor backend or CLI
  • A Postgres database for uploading data from ActivityWatch
  • Metabase, a fast analytics engine for querying the activity data.

Technical Details:

There are currently 2 ways to deploy Lifevisor:

  1. Direct writes to a Postgres server that can also be reached by Metabase.
  2. Deploying the backend service beside a Postgres server, and writing to that via HTTP

Both deployments work in a similar way: running the CLI tool on a schedule and writing to a remote postgres database.

There are 2 stages:

  1. init - Where all the previous ActivityWatch data is loaded from the Sqlite database into our remote database
  2. sync - Where on a x second schedule, the last x entries are pulled from the local Sqlite database, and written to the remote database.

Both phases ensure that we capture all the data from our ActivityWatch instance.

Getting started:


Installation

  1. Clone the Repository:

    git clone https://github.com/azaurus1/lifevisor.git
    cd lifevisor
    
  2. Build the CLI Application:

    cd app
    go build -o lifevisor main.go
    

    This will generate the lifevisor binary in the current directory.

  3. Move the Binary to Your Path:
    For easier usage, move the lifevisor binary to a directory in your system’s PATH:

    mv lifevisor /usr/local/bin/
    

Initial Setup

Before syncing data, initialize the platform with the init command:

lifevisor init pg <activitywatch-db-path> <postgres-connection-string> <batch-size>
  • <activitywatch-db-path>: Path to your ActivityWatch SQLite database file, typically ~/.local/share/activitywatch/aw-server/peewee-sqlite.v2.db.
  • <postgres-connection-string>: Connection string for your PostgreSQL database (e.g., postgres://username:password@host:port/dbname).
  • <batch-size>: Number of records to process in each batch during synchronization.

Example:

lifevisor init pg ~/.local/share/activitywatch/aw-server/peewee-sqlite.v2.db postgres://postgres:[email protected]:30136/lifevisor 10000

Set Up the Cronjob

To keep your data up-to-date, configure a cronjob to run the sync command every 5 minutes:

  1. Open your crontab editor:

    crontab -e
    
  2. Add the following entry:

    */5 * * * * /usr/local/bin/lifevisor sync pg ~/.local/share/activitywatch/aw-server/peewee-sqlite.v2.db postgres://postgres:[email protected]:30136/lifevisor 300
    
  • sync Command: Updates the PostgreSQL database with the latest data from ActivityWatch.
  • <activitywatch-db-path>: Same as above.
  • <postgres-connection-string>: Same as above.
  • 300: Sync records within the last 300 seconds (5 minutes).

Note: Replace /usr/local/bin/lifevisor with the actual path to your lifevisor binary if it differs.


Verify Setup

  1. Run the sync command manually to ensure it works:

    lifevisor sync pg ~/.local/share/activitywatch/aw-server/peewee-sqlite.v2.db postgres://postgres:[email protected]:30136/lifevisor 300
    
  2. Check your PostgreSQL database to confirm that screentime data is being updated.

  3. Verify that the cronjob is running as expected by checking your system logs:

    grep CRON /var/log/syslog
    

Use Cases:

Some potential use cases for Lifevisor are:

  • Personal Development: tracking how much time you have spent on learning new skills or side projects
  • Work-life balance: Auditing the split between professional and personal activities
  • Productivity Enhancements: Identify time-wasting activities and make adjustments in real-time
  • Quantified Self: Seamlessly track, analyse and optimise your daily activities by integrating real-time data into empowering data-driven personal growth.

Future Plans:

Lifevisor Roadmap

  • gRPC Backend and CLI:
    • Implement a gRPC-based backend to improve performance and scalability.
    • Enhance the CLI to communicate efficiently with the new backend.
  • Multi-Database Support:
    • Extend compatibility beyond PostgreSQL to include other SQL databases like MySQL and SQLite.
    • Allow users to choose their preferred database system.
  • Hosted Version:
    • Develop a hosted solution for users who prefer a managed service.
    • Provide easy setup without the need for self-hosting or complex configuration.

Feedback

The above roadmap represents my vision for Lifevisor's growth and future, but your feedback matters, if you have any ideas for features, use cases or integrations which you would like to see feel free to share them in the comments or contribute to the project on Github.