From a2f6ec74b4c8aa0d662e048d72ea8f9c9602c427 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 10 Sep 2026 23:25:57 +0800 Subject: [PATCH] =?utf8?q?split:=20=E4=BF=AE=E6=AD=A3=E6=8B=86=E5=88=86?= =?utf8?q?=E7=88=B6=E7=BB=84=E8=BF=9B=E5=BA=A6=E7=BB=A7=E6=89=BF=E9=80=BB?= =?utf8?q?=E8=BE=91=EF=BC=8C=E5=AD=90=E5=8D=95=E5=85=83=E4=B8=93=E5=B1=9E?= =?utf8?q?=E8=AE=B0=E5=BD=95=E4=B8=8D=E5=86=8D=E5=A4=96=E6=BA=A2=E5=88=B0?= =?utf8?q?=E5=85=84=E5=BC=9F=E5=AD=90=E5=8D=95=E5=85=83=EF=BC=88=E4=BF=AE?= =?utf8?q?=E5=A4=8D=20G70.2=20=E8=AF=AF=E6=98=BE=20study/test=20=E5=B7=B2?= =?utf8?q?=E5=AE=8C=E6=88=90=EF=BC=9B=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=AD=A3?= =?utf8?q?=E6=97=A5=E5=8E=86=E5=B1=95=E5=BC=80=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- backend/main.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/backend/main.py b/backend/main.py index b166364..45c96ad 100644 --- a/backend/main.py +++ b/backend/main.py @@ -198,8 +198,8 @@ def _split_parent_subunits(conn): def get_effective_progress(): # split 视图的"有效完成进度": # 键 = new_group_id(拆分组); 值 = {op_type: (date, duration_sec)} - # 含"父组完成 → 各子单元继承"展开: 若某 groupid 被拆分, 且其本身已有某 op 完成记录, - # 则每个子单元 new_group_id 也视为完成(用于早期已学完的拆分组 G25/G46/G47 等)。 + # 含"父组整体完成 → 各子单元继承"展开: 仅当某 groupid 被拆分且其本身作为整体学习 + # (记录 new_group_id 为空或等于父组id)时, 各子单元才视为完成; 子单元专属记录不外溢到兄弟。 if not os.path.exists(DATABASE_PATH): return {} conn = sqlite3.connect(DATABASE_PATH) @@ -214,10 +214,14 @@ def get_effective_progress(): eff = {} for ng, op, date, dur in cur.fetchall(): eff.setdefault(ng, {})[op] = (date, dur or 0) - # 父组完成情况: 按 group_id 聚合 + # 父组"整体学习"完成情况: 仅当记录代表整个父组(原 groupid 作为整体学习, + # new_group_id 为空或等于父组id)时才向子单元继承; 子单元专属记录不外溢。 cur.execute(""" SELECT group_id, op_type, MAX(COALESCE(log_date, created_at)) - FROM study_logs WHERE status='completed' GROUP BY group_id, op_type + FROM study_logs + WHERE status='completed' + AND (new_group_id IS NULL OR new_group_id = CAST(group_id AS TEXT)) + GROUP BY group_id, op_type """) parent = {} for gid, op, date in cur.fetchall(): @@ -543,10 +547,12 @@ async def get_calendar(): conn.close() # 展开: 父组(被拆分)的每条完成记录, 复制给其每个子单元 new_group_id expanded = [] # (day, op, ng, gid) - for day, op_type, ng, gid in base: - ng = ng if ng else str(gid) + for day, op_type, raw_ng, gid in base: + ng = raw_ng if raw_ng else str(gid) expanded.append((day, op_type, ng, str(gid))) - if str(gid) in subs: + # 仅"父组整体学习"记录(new_group_id 为空或等于父组id)才展开到各子单元; + # 子单元专属记录不外溢到兄弟子单元。 + if str(gid) in subs and (raw_ng is None or raw_ng == str(gid)): for sng in subs[str(gid)]: if sng != ng: expanded.append((day, op_type, sng, str(gid))) -- 2.43.0