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.

...全文
135 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:本文围绕不确定环境下的多式联运路径优化问题展开研究,提出并实现了基于AFO算法、遗传算法(GA)和粒子群优化算法(PSO)的三种智能优化方法,并借助Matlab平台完成算法编程与仿真。研究构建了考虑时间、成本、转运风险等多重不确定因素的路径优化模型,系统比较了AFO、GA、PSO三种算法在收敛速度、全局寻优能力和稳定性方面的表现,同时引入Matlab自带的全局优化搜索器作为基准对照,深入分析各算法在复杂物流网络中的适用边界与性能差异。研究表明,AFO算法在解决此类组合优化问题时展现出更快的收敛效率和更强的局部规避能力。; 适合人群:具备一定Matlab编程基础与运筹优化知识,从事物流工程、交通运输规划、智能算法开发等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于多式联运、综合货运网络中的路径决策支持系统构建;②为不确定性条件下复杂路径规划问题提供智能算法选型依据与技术实现方案;③支持科研人员复现主流优化算法并开展横向性能对比实验,推动算法改进与实际落地。; 阅读建议:建议读者结合提供的Matlab代码逐模块分析算法实现流程,重点理解目标函数设计、约束条件处理及参数敏感性分析部分,可通过调整问题规模与算法参数进行对比实验,进一步拓展至动态路径规划或大规模网络优化等延伸场景。
内容概要:本文研究了基于QLearning自适应强化学习的PID控制器在自主水下航行器(AUV)运动控制中的应用,通过Matlab代码实现了控制算法的仿真验证。该方法融合强化学习的在线自适应能力与传统PID控制的稳定性优势,利用QLearning算法动态优化PID控制器的比例、积分、微分参数,以应对水下复杂流体环境、模型不确定性及外部干扰等挑战,从而提升AUV轨迹跟踪的精度、鲁棒性与动态响应性能。文中系统阐述了AUV的六自由度非线性动力学建模过程、QLearning算法的状态空间与动作空间设计、奖励函数构造及训练机制,并详细说明了PID参数自整定的闭环控制架构。仿真结果表明,相较于传统固定参数PID控制器,该智能控制策略在多种工况下均展现出更优的控制效果,有效抑制了超调,加快了响应速度,并增强了抗干扰能力。; 适合人群:具备自动控制理论、强化学习基础及Matlab/Simulink仿真能力,从事水下机器人、智能控制、海洋工程、自动化等领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于AUV、UUV等无人水下平台的高精度自主导航与运动控制;②为解决非线性、强耦合、时变系统的控制器参数自适应整定问题提供智能化解决方案;③作为强化学习与经典控制理论深度融合的技术范例,推动智能控制算法在海洋装备中的工程化应用。; 阅读建议:建议读者结合提供的Matlab代码深入理解算法实现细节,重点剖析QLearning的状态-动作-奖励机制设计、PID参数更新逻辑及仿真对比实验结果,有条件者可在更复杂的动力学模型或实际硬件平台上进一步验证与优化算法性能。

164

社区成员

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

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