164
社区成员
发帖
与我相关
我的任务
分享| Course | https://bbs.csdn.net/forums/2501_MU_SE_FZU |
|---|---|
| Assignment Requirement | https://bbs.csdn.net/topics/620061759 |
| Team name | FocusFlow |
| Author | Hongzhi He(FZU:832302220 MU:23125390 |
| Goal of this Assignment | Showcase the Alpha Sprint progress, including homepage check-in, homepage overview, etc. |
| Other References | IEEE 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.

We have implemented functions such as homepage check-in and homepage overview
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.



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

Our development process is backed by regular code commits ensuring version control and collaboration.

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.
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.