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.
...全文
166 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:本文针对多渗透率电动汽车接入对配电网造成的影响,系统性地研究了其承载能力的评估方法,提出了一套融合多类型分布式能源的综合性评估体系。研究首先建立了包含配电网、电动汽车、分布式光伏及静止无功补偿装置(SVC)的协同运行基础模型,并据此构建了涵盖一次设备安全、负荷平稳性、电能质量与系统效率四个维度的多维评价指标体系。为实现客观、全面的量化评估,采用基于熵权法的客观赋权与模糊综合评价相结合的双层评分模型,有效避免了主观赋权的偏差,增强了评估结果的科学性与可信度。通过典型算例仿真,系统分析了不同电动汽车渗透率水平下各指标的演变规律,并开展了指标灵敏度分析,验证了所提评估模型的有效性、合理性和鲁棒性。; 适合人群:具备电力系统、电气工程及其自动化等相关专业背景,熟悉Matlab编程与电力系统仿真工具,从事新能源并网、智能配电网规划、电动汽车充放电管理等领域研究的研究生、高校科研人员及电网公司、设计院的工程技术人员。; 使用场景及目标:① 用于定量评估城市或区域配电网在不同电动汽车发展规模下的接纳能力与安全裕度;② 为电网规划部门制定充电基础设施布局、配电网升级改造方案提供决策依据;③ 支持研究高比例可再生能源与电动汽车耦合对电网稳定性的影响,优化负荷管理与无功补偿策略。; 阅读建议:建议读者结合文中的Matlab代码,动手复现算例仿真过程,深入理解熵权法计算权重与模糊综合评价的实现逻辑,并尝试调整电动汽车渗透率、光伏出力等关键参数,观察评价结果的变化趋势,从而深刻掌握模型的内在机理与应用方法。
内容概要:本文系统研究了分布式光伏储能系统的优化配置方法,重点聚焦于多渗透率电动汽车接入背景下配电网承载能力的评估问题。研究构建了涵盖配电网基础架构、电动汽车充放电行为、分布式光伏出力特性及无功补偿设备运行的协同仿真模型,并建立了集成设备安全、负荷特性、电能质量和系统效率的多维评价指标体系。创新性地提出基于熵权法与模糊综合评价相结合的双层评分模型,实现对承载能力的客观赋权与科学量化评估。通过Matlab平台进行算例仿真,分析不同电动汽车渗透率下的系统运行特性,开展关键指标的灵敏度分析,验证了方法的有效性与鲁棒性,为高比例新能源与电动汽车融合发展的配电网规划、优化调度及储能配置提供了理论支撑与技术工具。; 适合人群:电力系统、新能源、智能电网、综合能源系统及相关领域的科研人员、高校研究生以及从事电网规划与运行的工程技术人员。; 使用场景及目标:①用于研究高比例分布式光伏与规模化电动汽车接入对配电网运行特性的综合影响;②为配电网承载能力的科学评估、储能系统的优化配置及电网升级改造提供决策支持;③支持相关领域课题研究、学术论文复现、毕业设计及工程项目方案论证。; 阅读建议:建议结合提供的Matlab代码进行仿真复现,深入理解熵权法计算指标权重与模糊综合评价的实现细节,通过调整电动汽车渗透率、光伏出力水平等关键参数进行多场景对比和敏感性分析,以全面掌握系统运行规律与评估模型的内在逻辑。
内容概要:本文针对传统三电平并网逆变器在谐波抑制、电网不平衡适应性及动态响应方面的不足,提出了一种基于有源中点箝位(ANPC)三电平拓扑的高性能并网控制体系。该体系融合双极性倍频脉宽调制(DPWMA)、正负序分离锁相控制与电网电压前馈控制三大核心技术,构建了“精准同步-扰动补偿-优质调制”的一体化控制架构。ANPC拓扑通过有源箝位器件实现开关损耗均衡与中点电位主动调控,显著提升系统效率与稳定性;DPWMA调制在不增加器件开关频率的前提下,使输出等效开关频率翻倍,有效降低低次谐波含量,提升波形质量;正负序分离锁相技术可精准提取电网正序分量,抑制负序扰动对锁相精度的影响,保障不平衡电网下的稳定并网;电网电压前馈控制则打破传统反馈控制的滞后局限,实现对电网扰动的快速预补偿,大幅提升系统动态响应能力与抗扰性能。通过多工况仿真验证,该复合控制策略在稳态运行、电网不平衡及动态扰动等场景下均展现出优异的电能质量、锁相精度与运行稳定性,适用于新能源发电、工业大功率变流等对并网性能要求严苛的应用场合。; 适合人群:电力电子、新能源并网、自动控制及相关领域的科研人员与工程技术人员,以及具备一定电力系统分析与控制理论基础的研究生或高年级本科生。; 使用场景及目标:①研究高电能质量、高可靠性的三电平并网逆变器设计与控制方法;②解决电网电压不平衡、畸变等非理想工况下的并网稳定性问题;③提升大功率逆变系统的动态响应速度与抗干扰能力,推动高性能逆变技术在光伏、风电、储能等新能源系统中的应用。; 阅读建议:建议结合提供的Simulink仿真模型进行实践验证,重点掌握DPWMA调制的实现逻辑、正负序分离锁相算法的设计原理以及前馈-反馈复合控制结构的搭建方法,深入理解各模块间的协同工作机制,并通过对比不同工况下的仿真结果,全面评估控制策略的有效性与鲁棒性。

164

社区成员

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

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