CodingNic

Final Capstone Project

Dashboard Logic

Final Capstone Project 50 min read

Dashboard Logic

Dashboard Logic

Now you will build the logic that combines your data into useful summaries.

The dashboard is where users quickly see:

  • how many tasks they have
  • how many tasks are completed
  • how much they have spent

This is where your application starts to feel like a real product.


Goal of This Lesson

By the end of this lesson, you will:

  • calculate task statistics
  • calculate expense summaries
  • combine data from multiple services
  • prepare data for display in the GUI

Step 1: Create Dashboard Service File

Create:

text
app/services/dashboard_service.py

Step 2: Import Required Services

python
from app.services.task_service import get_tasks
from app.services.expense_service import get_total_expenses

Step 3: Total Task Count

python
def get_total_tasks(user_id):
    tasks = get_tasks(user_id)
    return len(tasks)

Step 4: Completed Task Count

python
def get_completed_tasks(user_id):
    tasks = get_tasks(user_id)
    completed = [task for task in tasks if task[2] == 1]
    return len(completed)

Step 5: Expense Summary

python
def get_expense_total(user_id):
    return get_total_expenses(user_id)

Step 6: Combine Dashboard Data

python
def get_dashboard_data(user_id):
    return {
        "total_tasks": get_total_tasks(user_id),
        "completed_tasks": get_completed_tasks(user_id),
        "total_expenses": get_expense_total(user_id)
    }

Step 7: Test in main.py

Update your main.py:

python
from app.services.database import create_tables
from app.services.user_service import register_user, login_user
from app.services.task_service import add_task
from app.services.expense_service import add_expense
from app.services.dashboard_service import get_dashboard_data

def main():
    create_tables()

    register_user("tom", "123")
    user_id = login_user("tom", "123")

    # add sample data
    add_task(user_id, "Study Python")
    add_task(user_id, "Build App")
    add_expense(user_id, 20, "Food")
    add_expense(user_id, 40, "Transport")

    dashboard = get_dashboard_data(user_id)
    print(dashboard)

if __name__ == "__main__":
    main()

Example Output

text
{
    'total_tasks': 2,
    'completed_tasks': 0,
    'total_expenses': 60
}

Data Structure

Dashboard data:

text
{
    total_tasks,
    completed_tasks,
    total_expenses
}

Why This Step Matters

You are now combining multiple features into one view.

This is how real applications:

  • summarize data
  • display insights
  • provide value to users

Current Project Structure

text
app/
    services/
        database.py
        user_service.py
        task_service.py
        expense_service.py
        dashboard_service.py

Important Notes

  • Keep logic separate from GUI
  • Return clean data structures (like dictionaries)
  • Avoid printing inside service files

Summary

You built dashboard logic that combines task and expense data into a single summary for the user.