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

FOCUS_2025_SE 2025-12-17 20:52:46

目录

  • 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.
...全文
191 回复 打赏 收藏 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:本文介绍了基于Matlab代码实现的电力系统机组组合优化调度方法,适用于IEEE14、IEEE30和IEEE118节点标准测试系统。该资源聚焦于电力系统中发电机组的优化调度问题,通过智能优化算法实现对机组启停、出力分配等决策的最优化,旨在降低运行成本、提升系统可靠性和经济性。文中系统阐述了从数学模型构建、多类型约束处理到优化算法设计与仿真实验验证的完整研究流程,并提供了可复现的Matlab代码,涵盖目标函数设定、约束条件建模及算法求解过程,适用于电力系统调度、能源优化等相关领域的科研与教学实践。; 适合人群:具备电力系统分析、运筹学基础及Matlab编程能力的高校学生、科研人员和工程技术人员,尤其适合从事电力系统优化、智能算法应用研究的研究生与青年学者。; 使用场景及目标:①用于电力系统机组组合(UC)问题的教学实验与课程设计;②支撑科研工作中对遗传算法、粒子群算法等智能优化算法在电力系统调度中应用的研究;③为含可再生能源接入的现代电网调度提供仿真平台与技术参考,助力低碳电力系统规划与运行。; 阅读建议:建议读者结合电力系统调度理论与优化建模知识,深入理解机组组合问题的数学本质与物理约束,再通过Matlab代码进行仿真实践,重点关注算法收敛性、多目标权衡策略与不同测试系统间的性能对比,以实现理论与实践的深度融合。
内容概要:本文研究了一种基于TCN-BiGRU-Attention混合神经网络模型的风电功率预测方法,旨在提升预测精度。该模型融合了时间卷积网络(TCN)对局部时序特征的强大提取能力、双向门控循环单元(BiGRU)对时间序列前后依赖关系的双向捕捉能力,以及注意力(Attention)机制对关键时间步特征的自适应加权聚焦能力。研究采用多变量输入方式,综合纳入风速、风向、温度等多种气象因素作为输入特征,实现风电功率的单步预测。通过对实际风电场数据的实验验证,该模型在预测精度方面相较于单一模型或其他组合模型展现出显著优势,有效降低了预测误差。; 适合人群:具备一定机器学习与深度学习基础,从事新能源预测、电力系统调度或相关领域研究的科研人员与工程技术人员。; 使用场景及目标:①应用于风电场功率实时预测,提升电网调度的稳定性与安全性;②为电力市场交易、储能配置和可再生能源消纳提供高精度数据支持;③作为深度学习模型融合设计的参考案例,推动时序预测技术的发展。; 阅读建议:此资源提供了完整的Matlab代码实现,读者在学习时应重点关注模型结构的设计原理、多变量特征的处理方式以及Attention机制的融入方法,建议结合代码进行复现实验,调整参数以深入理解各组件对最终预测性能的影响。

165

社区成员

发帖
与我相关
我的任务
社区描述
2501_MU_SE_FZU
软件工程 高校
社区管理员
  • FZU_SE_LQF
  • 助教_林日臻
  • 朱仕君
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧