FocusFlow α Sprint Blog Series (Part 4) - Homepage check-in & Overview

FOCUS_2025_SE 2025-12-19 20:42:55

目录

  • 1. Overview
  • 2. Function Realization Demonstration
  • 2.1 Daily check-in system
  • 2.2 Data Overview Panel
  • 3. Code Check-in Records (GitHub Commits)
  • 4. Core Code Analysis
  • 5.Sprint Summary
  • 5.1 Completed Deliverables
  • 5.2Technical Challenges and Resolutions:

1. Overview

Coursehttps://bbs.csdn.net/forums/2501_MU_SE_FZU
Assignment Requirementhttps://bbs.csdn.net/topics/620061759
Team nameFocusFlow
AuthorHongzhi He(FZU:832302220 MU:23125390
Goal of this AssignmentShowcase the Alpha Sprint progress, including homepage check-in, homepage overview, etc.
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 implemented functions such as homepage check-in and homepage overview

2.1 Daily check-in system

In FocusFlow, the check-in function is not only a record of user login, but also an important incentive mechanism for cultivating study habits. Users gain a sense of achievement through continuous check-in, forming a positive feedback loop.

img

img

img

2.2 Data Overview Panel

The data overview panel can visually display learning progress, making users' goals clearer and their actions faster

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

This task involves some core code, and the key parts will be presented below for analysis.
Firstly, the core code of the check-in function belongs to the data layer design
models.py

class Checkin:
    def __init__(self, id=None, user_id=None, date=None, created_at=None):
        self.id = id
        self.user_id = user_id
        self.date = date
        self.created_at = created_at

The Checkin class follows the "single responsibility principle" and is only responsible for storing the core information of check-in records By associating the user_id field with the User table, a one to many relationship between users and check-in records can be achieved. The date field is specifically used to store check-in dates (excluding specific times), making it easy to perform statistics and queries based on dates. The created date record is used to record the specific time point of check-in for subsequent auditing and analysis

The next step is the implementation of the check-in logic in the control layer, mainly consisting of the app.py file:
app.py

@app.route('/checkin', methods=['POST'])
@login_required
def checkin():
    user_id = session['user_id']
    today = datetime.now().strftime('%Y-%m-%d')  # 关键:标准化日期格式
    
    conn = get_db_connection()
    try:
        # 防重签机制:检查今天是否已经签到
        existing_checkin = conn.execute(
            'SELECT * FROM checkins WHERE user_id = ? AND date = ?',
            (user_id, today)
        ).fetchone()

        if existing_checkin:
            flash('You have already signed in today!', 'info')
        else:
            # 执行签到:插入新记录
            conn.execute(
                'INSERT INTO checkins (user_id, date) VALUES (?, ?)',
                (user_id, today)
            )
            conn.commit()
            flash('Sign in successful! Keep up the good work!', 'success')
    finally:
        conn.close()
    
    return redirect(url_for('dashboard'))

Ensure that the same user can only check in once on the same day through UNIQUE (user_id, date) database constraints and pre checks Perform operations in database transactions to ensure data consistency Provide instant feedback through flash messages to enhance user experience Store dates in% Y -% m -% d format to avoid time zone issues.

In addition, we have also implemented the function of continuous check-in, and the key part of it is also in the app.py file:
app.py

# 获取连续签到天数
streak_days = 0
checkin_dates = conn.execute('''
    SELECT date FROM checkins WHERE user_id = ? ORDER BY date DESC
''', (user_id,)).fetchall()

if checkin_dates:
    current_date = datetime.now().date()
    for checkin_date in checkin_dates:
        checkin_date_obj = datetime.strptime(checkin_date['date'], '%Y-%m-%d').date()
        if (current_date - checkin_date_obj).days == streak_days:
            streak_days += 1
        else:
            break

Calculate the consecutive days by checking the most recent check-in records in a loop Use (Current_date checkin_date_obj). days to calculate the date interval Sort by date DESC in descending order, starting from the most recent Terminate the loop immediately when discontinuous dates are detected.

In order to achieve real-time display of today's check-in status and task completion percentage, provide weekly learning trends, highlight consecutive check-in days, and other homepage functions, we still implement homepage aggregation in app.py. Some of the code is as follows:
app.py

# 获取签到信息
today = datetime.now().strftime('%Y-%m-%d')
has_checked_in = conn.execute('SELECT * FROM checkins WHERE user_id = ? AND date = ?',
                              (user_id, today)).fetchone() is not None

# 获取本周专注时长
week_start = (datetime.now() - timedelta(days=datetime.now().weekday())).strftime('%Y-%m-%d')
focus_time_query = conn.execute('''
    SELECT SUM(duration) as total_minutes 
    FROM focus_sessions 
    WHERE user_id = ? AND date(start_time) >= ?
''', (user_id, week_start)).fetchone()

# 获取任务统计
completed_tasks_query = conn.execute('''
    SELECT COUNT(*) as count FROM tasks WHERE user_id = ? AND status = 'completed'
''', (user_id,)).fetchone()

Aggregate data from the checkins, foci sessions, and tasks tables Calculate using relative time (this week, today) Reduce application layer computation by utilizing built-in functions such as SUM and COUNT in databases Only query relevant data when needed to avoid unnecessary database access.

Finally, we present the key code of our database design pattern:

-- 签到表的核心设计
CREATE TABLE checkins (
    id INTEGER PRIMARY KEY,
    user_id INTEGER NOT NULL,
    date DATE NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    UNIQUE(user_id, date)  -- 防止重复签到
);

The checkins table serves as the fact table, and the users table serves as the dimension table Store summary data such as stream_days in the users table to improve query performance Store check-in records by date partition for easy management of historical data.

5.Sprint Summary

5.1 Completed Deliverables

  1. Core Homepage Redesign – Implemented dynamic dashboard with real-time data widgets
  2. Daily Check-in System – Functional check-in button with streak tracking and calendar view
  3. User Data Overview Panel – Displays pending tasks, study duration, completion rate, and weekly stats
  4. Personalized Greetings – Time-based greetings (morning/afternoon/evening) with user name
  5. Weekly Learning Trends – 7-day visual trend chart integrating check-ins and focus sessions
  6. Database Schema Enhancement – Added checkins table and user statistics fields (current_streak, total_checkins, etc.)

5.2Technical Challenges and Resolutions:

  1. Consecutive Day Calculation Logic:
    Solution:Implemented date-difference iteration algorithm with early termination on break detection
  2. Preventing Duplicate Check-ins:
    Solution:Combined database UNIQUE constraint (user_id, date) with pre-check in application logic
  3. Real-time Data Synchronization:
    Solution:Used AJAX polling for stats updates and optimistic UI updates for check-in actions
  4. Timezone Handling:
    Solution:Stored all dates in UTC and converted to local time only for display purposes
  5. Database Performance with Aggregates:
    Solution:Added indexes on user_id, date fields and used SQL aggregation functions (SUM, COUNT)
  6. Responsive Dashboard Layout:
    Solution:Applied Bootstrap 5 grid system with conditional card stacking on mobile devices

The sprint successfully delivered a fully functional homepage with integrated check-in system and real-time learning analytics. All core acceptance criteria were met, with particular attention given to data accuracy, user experience, and system performance.

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

164

社区成员

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

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