Skip to the content.

Technical Guide

The Lavender app front-end is made with React and uses the Firestore JS SDK to connect to a Google Firebase Firestore cloud project. Account management happens through Firebase Authentication.

User-facing error validation happens client-side through the JavaScript util files, but Firebase Security Rules perform additional role-based enforcements server-side. Account creation and deletion happen through Cloud Functions for Firebase.

Algorithm

The algorithm is built with Python and uses JSON as the input and output format. The sleep optimization algorithm analyzes a user’s schedule to provide personalized sleep recommendations based on their work shifts and available free time.

Core Components

The algorithm consists of several key functions:

  1. Schedule Analysis

    • build_matrix(): Processes the input JSON data containing schedule information
    • get_start_end_times(): Identifies work shift boundaries
    • night_or_day_shift(): Classifies shifts as day, evening, or night shifts based on timing
  2. Sleep Pattern Detection

    • king_of_the_hill_algo(): Finds the longest continuous period of available sleep time
    • get_sleep_episode(): Identifies potential “booster” sleep periods after shifts
  3. Schedule Optimization

    • modify_sleep_schedule(): Generates sleep recommendations based on:
      • Current total sleep hours
      • Shift patterns (day/night/evening)
      • Previous and upcoming shift schedules
      • Global metadata about sleep patterns

How It Works

  1. The algorithm takes a JSON input containing:

    • Time intervals (in minutes) for the schedule
    • Work shift information
    • Available free time slots
    • Global metadata about sleep patterns
  2. It analyzes the schedule to:

    • Identify work shift boundaries
    • Classify shift types (day/night/evening)
    • Find optimal sleep windows
    • Calculate total available sleep time
  3. Based on the analysis, it provides recommendations for:

    • Primary sleep periods
    • Additional “booster” sleep episodes when needed
    • Schedule modifications to achieve optimal sleep duration

Currently the algorithm is not yet integrated with the app front-end, but eventually this will happen through Cloud Functions as well.

Development Challenges and Solutions

Throughout the development process, we encountered several significant challenges:

Codebase Rewrite

The decision to rewrite the codebase was driven by the need for a more maintainable and user-friendly application. While this was a substantial undertaking, it allowed us to:

Sleep Optimization Algorithm Development

Developing the sleep optimization algorithm presented unique challenges:

Firebase Integration

Working with Firebase, especially Cloud Functions and the Admin SDK required significant learning and adaptation:

These challenges were addressed through extensive research and iterative development processes. The solutions implemented have resulted in a more robust and maintainable application.