FocusFlow α Sprint Blog Series (Part 2) - Tasks Creation, Deletion and Modification Report

FOCUS_2025_SE 2025-12-15 21:30:19

目录

  • Overview
  • 1. Sprint Burndown Chart
  • 2. Function realization demonstration
  • 2.1 Task Creation, Editing, and Deletion
  • 2.2 Task Completion and Categorization
  • 3. Code Check-in Records (GitHub Commits)
  • 4. Core Code Analysis
  • 4.1 Task CRUD and Status Update (app.py)
  • Task Listing with Tags
  • Creating and Editing Tasks
  • Creating and Editing Tasks
  • 4.2 Marking Tasks as Completed
  • 4.3 Tag-Based Categorization During Task Creation/Editing
  • 5. Sprint Summary
  • Completed Deliverables
  • Technical Challenges and Resolutions

Overview

Coursehttps://bbs.csdn.net/forums/2501_MU_SE_FZU
Assignment Requirementhttps://bbs.csdn.net/topics/620061759
Team NameFocus_2025
AuthorChenhe Zhu FZU: 832301108 MU: 23125047
Goal of this assignmentClarify Code Standards, Sprint Tasks, and Plans for the team Alpha Sprint
Other referencesIEEE Std 830-1998, GB/T 8567-2006

1. Sprint Burndown Chart

img

2. Function realization demonstration

This sprint, I implemented the Task Management Module, which allows users to organize their study goals efficiently. Below are key feature demonstrations.

2.1 Task Creation, Editing, and Deletion

Users can add new tasks via the “+ New Task” button, specifying title, description, due date, and category. Tasks can be edited inline or deleted permanently with confirmation.

在这里插入图片描述

在这里插入图片描述

2.2 Task Completion and Categorization

Each task includes a checkbox to mark it as completed. Completed tasks are visually dimmed and moved to a separate “Already-done” section.
Tasks are grouped by user-defined subjects, enabling structured planning.

在这里插入图片描述


在这里插入图片描述

3. Code Check-in Records (GitHub Commits)

请添加图片描述


As the co-developer of the Task Management Module, I assisted in implementing both frontend templates and backend logic. All changes were committed to the main branch of our repository.

4. Core Code Analysis

The task management system in FocusFlow is built around three key operations: CRUD (Create, Read, Update, Delete), status tracking, and tag-based organization. All logic is implemented in app.py using Flask routes and SQLite queries.

4.1 Task CRUD and Status Update (app.py)

Task Listing with Tags

The /tasks route fetches all user tasks and enriches each with its associated tags from the task_tags table:

@app.route('/tasks')
@login_required
def tasks():
    user_id = session['user_id']
    conn = get_db_connection()
    try:
        tasks = conn.execute(
            'SELECT * FROM tasks WHERE user_id = ? ORDER BY due_date ASC',
            (user_id,)
        ).fetchall()

        tasks_with_tags = []
        today = datetime.now().date()
        for task in tasks:
            # Fetch tags for this 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)
    finally:
        conn.close()
    return render_template('tasks.html', tasks=tasks_with_tags)

This ensures every task displayed includes its dynamic tag list, enabling flexible categorization without a fixed "category" column.

Creating and Editing Tasks

The /tasks add endpoint handles both creation and editing via a single POST route. It uses task_id to distinguish between modes:

@app.route('/tasks/add', methods=['POST'])
@login_required
def add_task():
    task_id = request.form.get('task_id')  # None for new tasks
    # ... (form data extraction)

    if task_id:
        # Edit existing task
        conn.execute('''
            UPDATE tasks SET title = ?, description = ?, ..., status = ?
            WHERE id = ? AND user_id = ?
        ''', (title, ..., status, task_id, user_id))
        # Clear old tags
        conn.execute('DELETE FROM task_tags WHERE task_id = ?', (task_id,))
    else:
        # Create new task
        cursor = conn.cursor()
        cursor.execute('''
            INSERT INTO tasks (user_id, title, description, ...)
            VALUES (?, ?, ?, ...)
        ''', (user_id, title, description, ...))
        task_id = cursor.lastrowid  # Get new ID

    # Re-insert tags (for both create/edit)
    if tags:
        for tag in [t.strip() for t in tags.split(',') if t.strip()]:
            conn.execute(
                'INSERT INTO task_tags (task_id, tag) VALUES (?, ?)',
                (task_id, tag)
            )
    conn.commit()

Creating and Editing Tasks

The delete operation first validates ownership, then removes both the task and its tags:

@app.route('/tasks/delete/<int:task_id>', methods=['POST'])
@login_required
def delete_task(task_id):
    user_id = session['user_id']
    conn = get_db_connection()
    try:
        # Verify ownership
        task = conn.execute(
            'SELECT * FROM tasks WHERE id = ? AND user_id = ?',
            (task_id, user_id)
        ).fetchone()
        if not task:
            flash('Permission denied!')
            return redirect(url_for('tasks'))

        # Clean up: delete tags first, then task
        conn.execute('DELETE FROM task_tags WHERE task_id = ?', (task_id,))
        conn.execute('DELETE FROM tasks WHERE id = ?', (task_id,))
        conn.commit()
        flash('Task deleted successfully!')
    except Exception as e:
        conn.rollback()
        flash('Delete failed!')
    finally:
        conn.close()
    return redirect(url_for('tasks'))

4.2 Marking Tasks as Completed

Task completion is handled by a dedicated JSON API endpoint (/tasks/update_status/int:task_id). This allows frontend components to trigger status changes without page reloads:

@app.route('/tasks/update_status/<int:task_id>', methods=['POST'])
@login_required
def update_task_status(task_id):
    user_id = session['user_id']
    data = request.get_json()
    new_status = data.get('status', 'completed')

    conn = get_db_connection()
    try:
        # Ensure the task belongs to the current user
        task = conn.execute(
            'SELECT * FROM tasks WHERE id = ? AND user_id = ?',
            (task_id, user_id)
        ).fetchone()
        if not task:
            return jsonify({'success': False}), 403

        # Update status and timestamp
        conn.execute('''
            UPDATE tasks SET status = ?, updated_at = CURRENT_TIMESTAMP
            WHERE id = ?
        ''', (new_status, task_id))
        conn.commit()
        return jsonify({'success': True})
    finally:
        conn.close()

The status field in the tasks table stores either 'pending' or 'completed', enabling filtering and progress tracking.

4.3 Tag-Based Categorization During Task Creation/Editing

When a user creates or edits a task, tags are parsed from a comma-separated string and stored in the task_tags table:

# In /tasks/add route
if tags:
    tag_list = [tag.strip() for tag in tags.split(',') if tag.strip()]
    for tag in tag_list:
        conn.execute(
            'INSERT INTO task_tags (task_id, tag) VALUES (?, ?)',
            (task_id, tag)
        )

5. Sprint Summary

Completed Deliverables

The Alpha Sprint deliverables for the task management module include the following functionalities, all implemented in the Flask backend (app.py) with SQLite persistence:

  • Full CRUD operations for user tasks, including creation, retrieval, in-place editing, and deletion.
  • Task status tracking, supporting two states: pending and completed, with updates handled via a dedicated RESTful endpoint.
  • Dynamic categorization through user-defined tags, stored in a normalized task_tags table to support many-to-many relationships between tasks and labels.
  • Strict access control: All write operations validate task ownership by verifying the user_id against the session context, preventing cross-user data manipulation.
  • Atomic database transactions: Each mutating operation uses explicit commit() on success and rollback() on exception to ensure data consistency.

The module is fully integrated with the dashboard view, where task lists and completion metrics are rendered based on the same underlying data model.

Technical Challenges and Resolutions

1. Tag Consistency During Task Updates
Initial implementations appended new tags without removing existing ones, resulting in tag duplication upon repeated edits.

Resolution: Prior to inserting new tags, all records associated with the task ID are purged from the task_tags table:

conn.execute('DELETE FROM task_tags WHERE task_id = ?', (task_id,))

This guarantees that the tag set reflects exactly the user’s current input.

2. Unauthorized Task Manipulation
Without explicit ownership verification, malicious users could modify or delete tasks by supplying arbitrary task IDs.

Resolution: Every mutating endpoint includes a pre-check query:

SELECT id FROM tasks WHERE id = ? AND user_id = ?

Operations proceed only if a matching record exists, thereby enforcing data isolation at the application layer.
Planned Enhancements for Beta Sprint

  • Introduce task priority levels and due-date validation logic.
  • Implement client-side filtering by tag, status, or date range.
  • Establish data pipelines from task completions to the reporting and
    focus analytics modules.
  • Add server-side input sanitization and structured error responses for
    invalid form submissions.

The task management module now constitutes a secure, maintainable, and extensible component of the FocusFlow system, fulfilling all Alpha Sprint requirements.

...全文
174 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:本文围绕基于三电平ANPC-VSG(虚拟同步发电机)的构网型逆变器控制展开研究,重点设计并实现了双闭环控制与中点电位平衡控制策略。通过Simulink仿真实现,验证了该控制体系在提升逆变器并网性能方面的有效性。系统采用虚拟同步发电机技术,使逆变器具备类似同步电机的惯量与阻尼特性,显著增强电网稳定性;结合电压外环与电流内环构成的双闭环控制结构,实现对输出电压和电流的精确动态调节与高稳态精度;同时,针对三电平拓扑中存在的中点电位漂移问题,引入有效的平衡控制算法,确保母线电压对称,保障系统安全可靠运行。整体方案不仅支持电压、频率的自主恢复,还能实现功率的合理分配,特别适用于高比例新能源接入的弱电网或孤岛运行环境。; 适合人群:电气工程、电力电子与电力系统相关专业的研究生、科研人员及从事新能源并网逆变器开发的高级工程师。; 使用场景及目标:①应用于高比例可再生能源电网中构网型逆变器的设计与仿真;②实现三电平ANPC逆变器在孤岛或弱电网条件下的稳定并网运行;③解决中点电位不平衡问题,提升多电平逆变器的电能质量和运行可靠性;④为VSG控制、双闭环设计及中点电位控制提供完整的理论依据与仿真验证平台。; 阅读建议:此资源以Simulink仿真为核心,建议读者结合文中控制策略进行模型复现,重点关注双闭环参数整定、VSG惯量阻尼系数设置及中点电位平衡算法的实现细节,并通过稳态、动态与不平衡工况下的仿真结果分析系统性能。
内容概要:本文研究了基于二阶锥双层凸规划的分布式风光与电动汽车协同调压降损调度方法,旨在通过优化调度策略实现配电网的电压稳定与网损降低。研究构建了一个包含分布式光伏、风力发电及电动汽车V2G(Vehicle-to-Grid)能力的多时段协同优化模型,采用二阶锥松弛技术将原本非凸非线性的复杂优化问题转化为可高效求解的凸优化问题,并通过Matlab编程实现了算法仿真与验证。文中系统阐述了模型的数学建模过程,包括以最小化网络损耗和电压偏差为目标的目标函数设计,以及涵盖功率平衡、节点电压范围、设备容量限制等在内的多重约束条件。结合标准算例进行仿真分析,结果表明所提出的调度方法在改善配电网电压质量、降低网络损耗方面具有显著效果,尤其适用于高比例可再生能源与大规模电动汽车接入的复杂运行场景。该研究为现代智能配电网的安全、经济、高效运行提供了坚实的理论依据与可行的技术路径。; 适合人群:具备电力系统分析、优化理论基础及Matlab编程能力的研究生、科研人员,以及从事智能电网、分布式能源系统规划与运行、电动汽车与电网互动(V2G)等领域的工程技术人员。; 使用场景及目标:①应用于高渗透率新能源与电动汽车共同接入背景下的配电网多时段协同调度仿真与优化;②支撑科研工作者对二阶锥规划(SOCP)、双层优化建模范式的复现、学习与改进;③为电力系统运行部门提供一套切实可行的节能降损、电压稳定控制的技术方案参考,助力新型电力系统建设;④作为高级调度算法的教学案例,深化对现代优化技术在电力系统中应用的理解。; 阅读建议:读者应结合文中的数学模型推导与提供的Matlab代码进行对照学习,重点掌握二阶锥松弛技术的应用技巧、双层优化问题的分解策略与求解逻辑,建议动手调试代码以深入理解各约束条件与目标函数项的实际作用机制,并可在此基础上进一步拓展至多目标优化、不确定性优化(如鲁棒优化、随机规划)或考虑通信延迟等更复杂的实际因素。

164

社区成员

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

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