Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions lifetrace_backend/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,27 +329,51 @@ def _is_duplicate(self, screen_id: int, image_hash: str) -> bool:
if not self.deduplicate:
return False

is_duplicate = False

if screen_id not in self.last_hashes:
# 第一次截图,不是重复
self.last_hashes[screen_id] = image_hash
# 初始化状态跟踪
if not hasattr(self, '_last_duplicate_status'):
self._last_duplicate_status = {}
self._last_duplicate_status[screen_id] = False
return False

last_hash = self.last_hashes[screen_id]

try:
# 计算汉明距离
current = imagehash.hex_to_hash(image_hash)
previous = imagehash.hex_to_hash(last_hash)
previous = imagehash.hex_to_hash(self.last_hashes[screen_id])
distance = current - previous

is_duplicate = distance <= self.hash_threshold

# 简单的去重通知
if is_duplicate:
logger.info(f"屏幕 {screen_id}: 跳过重复截图")
print(f"[去重] 屏幕 {screen_id}: 跳过重复截图")
# 检查状态是否发生变化
if not hasattr(self, '_last_duplicate_status'):
self._last_duplicate_status = {}

last_status = self._last_duplicate_status.get(screen_id, False)

return is_duplicate
# 只有状态发生变化时才打印日志
if is_duplicate and not last_status:
logger.info(f"屏幕 {screen_id}: 开始重复截图")
print(f"[去重] 屏幕 {screen_id}: 开始重复截图")
elif not is_duplicate and last_status:
logger.info(f"屏幕 {screen_id}: 重复结束,恢复截图")
print(f"[去重] 屏幕 {screen_id}: 重复结束,恢复截图")
elif is_duplicate and last_status:
# 连续重复,可以选择性地每N次打印一次或者完全不打印
pass
Comment on lines +358 to +366
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): We've found these issues:


# 更新状态记录
self._last_duplicate_status[screen_id] = is_duplicate
self.last_hashes[screen_id] = image_hash

except Exception as e:
logger.error(f"比较图像哈希失败: {e}")
return False
is_duplicate = False

return is_duplicate

def _capture_screen(self, screen_id: int, app_name: str = None, window_title: str = None) -> Optional[str]:
"""截取指定屏幕"""
Expand Down
2 changes: 1 addition & 1 deletion lifetrace_backend/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ def get_statistics(self) -> Dict[str, Any]:
with self.get_session() as session:
total_screenshots = session.query(Screenshot).count()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Extract code out into method (extract-method)

processed_screenshots = session.query(Screenshot).filter_by(is_processed=True).count()
pending_tasks = session.query(ProcessingQueue).filter_by(status='pending').count()
pending_tasks = session.query(Screenshot).filter_by(is_processed=False).count()

# 今日统计
today = datetime.now().date()
Expand Down
1 change: 1 addition & 0 deletions lifetrace_backend/templates/chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -2594,6 +2594,7 @@
<a href="/chat/settings" class="btn btn-ghost btn-icon" title="设置">
<i data-lucide="settings"></i>
</a>
<a href="/" class="btn btn-outline">首页</a>
</div>
</div>
</header>
Expand Down