FocusFlow α Sprint Blog Series (Part 3) - Focus Mode & Focus Time Count

FOCUS_2025_SE FOCUS_2025_SE 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

目录

  • 1. Overview
  • 2. Function Realization Demonstration
  • 2.1 Focus Mode
  • 2.2 Countdown
  • 2.3 Total Learning Time
  • 3. Code Check-in Records (GitHub Commits)
  • 4. Core Code Analysis
  • 4.1 Task CRUD and Status Update (app.py)
  • 4.2 Marking Tasks as Completed
  • 4.3 Tag-Based Categorization During Task Creation/Editing
  • 5. Sprint Summary

1. Overview

ItemDetails
Course2025 Fall - Software Engineering Class
Assignment RequirementTeam Project - Alpha Sprint Blog
Team NameFocusFlow
AuthorShengpeng Yang (FZU: 832301120, MU: 23126434)
Goal of this AssignmentShowcase the Alpha Sprint progress, including Focus Mode implementation, Timer logic, and Total Study Time tracking.
Other ReferencesIEEE Std 830-1998, GB/T 8567-2006

Sprint Burndown Chart
We tracked our progress meticulously throughout the sprint. The chart below illustrates our team's velocity in completing the task management user stories against our estimated timeline.

img


2. Function Realization Demonstration

We have successfully implemented the core interfaces for managing learning tasks.

2.1 Focus Mode

We offer a Focus Mode for users to choose from, suitable for times when concentration is needed.

img

2.2 Countdown

For different learning tasks or personal preferences, we provide various countdown durations to choose from.

img

2.3 Total Learning Time

In the personal feedback module, users can also view their total learning time.

img


3. Code Check-in Records (GitHub Commits)

Our development process is backed by regular code commits ensuring version control and collaboration.

img


4. Core Code Analysis

The backend logic is powered by Flask and SQLite. Below is an analysis of the key functions in app.py that drive the task management features.

4.1 Task CRUD and Status Update (app.py)

Task Listing with Tags
The /tasks route handles the display of tasks. It fetches tasks specific to the logged-in user and retrieves associated tags for each task to ensure the frontend displays all relevant categorization data.

# app.py
@app.route('/tasks')
@login_required
def tasks():
    # ...
    # Fetch tasks sorted by due date
    tasks = conn.execute('SELECT * FROM tasks WHERE user_id = ? ORDER BY due_date ASC', (user_id,)).fetchall()

    tasks_with_tags = []
    for task in tasks:
        # Fetch tags for each specific task
        tags = conn.execute('SELECT tag FROM task_tags WHERE task_id = ?', (task['id'],)).fetchall()
        task_dict = dict(task)
        task_dict['tags'] = [tag['tag'] for tag in tags]
        # ... (Date formatting logic)
        tasks_with_tags.append(task_dict)
    # ...

Creating and Editing Tasks
We streamlined the creation and editing process into a single route /tasks/add. This function checks if a task_id is present in the form data. If it is, the system performs an UPDATE; otherwise, it performs an INSERT.

# app.py
@app.route('/tasks/add', methods=['POST'])
@login_required
def add_task():
    # ... (Data retrieval from request.form)
    
    if task_id:
        # Edit Mode: Update existing task
        conn.execute('''
            UPDATE tasks 
            SET title = ?, description = ?, course = ?, priority = ?, 
                due_date = ?, repeat = ?, status = ?, updated_at = CURRENT_TIMESTAMP 
            WHERE id = ? 
        ''', (title, description, course, priority, due_date, repeat, status, task_id))
        
        # Clear old tags to re-insert new ones
        conn.execute('DELETE FROM task_tags WHERE task_id = ?', (task_id,))
    else:
        # Create Mode: Insert new task
        cursor = conn.cursor()
        cursor.execute('''
            INSERT INTO tasks (user_id, title, description, course, priority, due_date, repeat, status)
            VALUES (?, ?, ?, ?, ?, ?, ?, ?)
        ''', (user_id, title, description, course, priority, due_date, repeat, status))
        task_id = cursor.lastrowid
    # ...

4.2 Marking Tasks as Completed

To allow for asynchronous status updates (e.g., via AJAX), we implemented a dedicated API endpoint /tasks/update_status/<int:task_id>. This verifies task ownership before updating the status to prevent unauthorized modifications.

# app.py
@app.route('/tasks/update_status/<int:task_id>', methods=['POST'])
@login_required
def update_task_status(task_id):
    # ...
    # Verification: Ensure task belongs to current user
    task = conn.execute('SELECT * FROM tasks WHERE id = ? AND user_id = ?', (task_id, user_id)).fetchone()
    
    # Update status
    conn.execute('UPDATE tasks SET status = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?', (new_status, task_id))
    # ...
    return jsonify({'success': True, 'message': 'Task status updated successfully!'})

4.3 Tag-Based Categorization During Task Creation/Editing

Handling tags requires parsing a comma-separated string from the frontend and creating associations in the task_tags table. This logic is embedded within the add_task route.

# app.py - Inside add_task function
    # ...
    if tags:
        # Split string by comma and strip whitespace
        tag_list = [tag.strip() for tag in tags.split(',') if tag.strip()]

        for tag in tag_list:
            # Insert individual tags into the association table
            conn.execute(
                'INSERT INTO task_tags (task_id, tag) VALUES (?, ?)',
                (task_id, tag)
            )
    # ...

5. Sprint Summary

  • Completed Deliverables

    • Distraction-Free Focus Interface: A specialized UI that isolates the user by displaying only pending tasks and the active timer, filtering out completed items to reduce cognitive load.
    • Pomodoro State Machine: A robust JavaScript timer (FocusTimer) that automatically manages transitions between "Focus" and "Break" states and handles audio notifications.
    • Session Data Persistence: Backend logic to securely validate and record completed focus durations into the SQLite database via asynchronous API calls.
    • Global Study Statistics: Implementation of a site-wide tracker that calculates and displays the user's total study hours on the navigation bar of every page.
  • Technical Challenges and Resolutions:

    • Conditional Data Saving: One major challenge was ensuring that the application only recorded "Focus" time and ignored "Break" time in the database. We resolved this by implementing a state flag (isFocusMode) within the FocusTimer class. The saveFocusSession function is strictly gated behind this flag in the handleTimerComplete method, ensuring only valid learning data is committed.
    • Global Data Accessibility: Displaying the "Total Study Time" on the dashboard and sidebar required access to database statistics across every route. Instead of repeating the query code in every view function, we utilized Flask's @app.before_request decorator. This allows us to calculate the aggregate time once and inject it into the global g object, making it accessible to the base template and all child pages automatically.
...全文

相关推荐

《模式识别与数据挖掘》配套PPT课件

《模式识别与数据挖掘》配套PPT课件

Bryan Ding

科技成果转化项目进场交易前,评估备案环节需要准备哪些材料?_8.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN

人工智能通识教育(中职版)课程标准+PPT课件+部分素材+电子活页+在线考核

人工智能通识教育(中职版)课程标准+PPT课件+部分素材+电子活页+在线考核

Bryan Ding

跨境电商供应链管理(AIGC版)课件+教案+参考答案

跨境电商供应链管理(AIGC版)课件+教案+参考答案

Bryan Ding

110KV单电源电网三段式电流保护+距离继电保护整定计算说明报告(23页+6000字)

内容概要:本文是一份关于110kV单电源电网继电保护整定计算的综合性技术报告,全文共23页、约6000字,系统阐述了三段式电流保护与距离保护的设计原理及其整定计算方法。报告深入分析了电力系统在短路故障条件下的电流与阻抗特性,详细推导了电流保护Ⅰ、Ⅱ、Ⅲ段的动作范围、整定原则、灵敏度校验及时间配合机制,确保满足继电保护的选择性、速动性、灵敏性和可靠性“四性”要求。同时,针对长距离或重要输电线路,补充介绍了距离保护的阻抗整定计算方法,并可能结合Matlab进行仿真验证与辅助计算,提升整定结果的准确性与工程实用性。; 适合人群:适用于电气工程及其自动化相关专业的高年级本科生、研究生,以及从事电力系统继电保护设计、运行维护的工程技术人员;要求读者具备电力系统分析、短路计算及继电保护的基础理论知识。; 使用场景及目标:①掌握110kV单电源辐射型电网中三段式电流保护的整定流程与实际计算步骤;②理解距离保护的工作原理及其在复杂工况下的应用优势;③完成实际工程项目的保护配置与整定计算任务,或作为课程设计、毕业设计及科研课题的技术参考资料;④结合Matlab工具实现整定计算的程序化处理与动作特性仿真验证。; 阅读建议:建议读者结合《电力系统继电保护原理》等相关教材同步学习,重点研读整定公式的推导过程与典型算例的计算细节,注意区分电流保护与距离保护的适用场景与配置逻辑,有条件时应利用Matlab等工具对保护动作行为进行建模与仿真,以深化对保护协调配合机制的理解。

欢多天天写代码
评论
收藏 已收藏
分享
返回顶部