feat: v1.1.0 - 图片按日期分文件夹保存、设置面板、序号显示模式、自动刷新

This commit is contained in:
2026-04-16 10:42:36 +08:00
parent 3503ee35ab
commit f703c0491c
9 changed files with 639 additions and 220 deletions

View File

@@ -25,7 +25,7 @@ class Database:
"""获取数据库连接"""
return sqlite3.connect(self.db_path)
def add_image(self, path, camera_id=0):
def add_image(self, path, camera_id=0, date_folder=None):
"""添加图片记录
Returns:
@@ -34,8 +34,8 @@ class Database:
conn = self._get_conn()
cursor = conn.cursor()
cursor.execute(
"INSERT INTO images (path, camera_id, timestamp) VALUES (?, ?, ?)",
(path, camera_id, datetime.datetime.now().isoformat())
"INSERT INTO images (path, camera_id, timestamp, date_folder) VALUES (?, ?, ?, ?)",
(path, camera_id, datetime.datetime.now().isoformat(), date_folder)
)
image_id = cursor.lastrowid
conn.commit()
@@ -59,22 +59,28 @@ class Database:
conn.commit()
conn.close()
def get_images(self, limit=50, offset=0, analyzed_only=False):
def get_images(self, limit=50, offset=0, analyzed_only=False, date_folder=None):
"""获取图片列表"""
conn = self._get_conn()
conn.row_factory = sqlite3.Row
if analyzed_only:
cursor = conn.execute(
"SELECT * FROM images WHERE analyzed = 1 ORDER BY timestamp DESC LIMIT ? OFFSET ?",
(limit, offset)
)
else:
cursor = conn.execute(
"SELECT * FROM images ORDER BY timestamp DESC LIMIT ? OFFSET ?",
(limit, offset)
)
query = "SELECT * FROM images"
params = []
conditions = []
if analyzed_only:
conditions.append("analyzed = 1")
if date_folder:
conditions.append("date_folder = ?")
params.append(date_folder)
if conditions:
query += " WHERE " + " AND ".join(conditions)
query += " ORDER BY timestamp DESC LIMIT ? OFFSET ?"
params.extend([limit, offset])
cursor = conn.execute(query, params)
rows = cursor.fetchall()
conn.close()
@@ -87,7 +93,7 @@ class Database:
if event_type:
cursor = conn.execute(
"""SELECT e.*, i.path as image_path, i.timestamp as image_timestamp
"""SELECT e.*, i.path as image_path, i.timestamp as image_timestamp, i.id as image_id
FROM events e JOIN images i ON e.image_id = i.id
WHERE e.event_type = ?
ORDER BY e.timestamp DESC LIMIT ? OFFSET ?""",
@@ -95,7 +101,7 @@ class Database:
)
else:
cursor = conn.execute(
"""SELECT e.*, i.path as image_path, i.timestamp as image_timestamp
"""SELECT e.*, i.path as image_path, i.timestamp as image_timestamp, i.id as image_id
FROM events e JOIN images i ON e.image_id = i.id
ORDER BY e.timestamp DESC LIMIT ? OFFSET ?""",
(limit, offset)
@@ -144,6 +150,12 @@ class Database:
)
event_types = [{'type': row[0], 'count': row[1]} for row in cursor.fetchall()]
# 日期文件夹统计
cursor = conn.execute(
"SELECT date_folder, COUNT(*) as count FROM images WHERE date_folder IS NOT NULL GROUP BY date_folder ORDER BY date_folder DESC"
)
date_folders = [{'date': row[0], 'count': row[1]} for row in cursor.fetchall()]
conn.close()
return {
@@ -151,7 +163,8 @@ class Database:
'analyzed_images': analyzed_images,
'unanalyzed_images': total_images - analyzed_images,
'total_events': total_events,
'event_types': event_types
'event_types': event_types,
'date_folders': date_folders
}
def delete_image(self, image_id):
@@ -190,6 +203,16 @@ class Database:
rows = cursor.fetchall()
conn.close()
return [dict(row) for row in rows]
def get_date_folders(self):
"""获取所有日期文件夹"""
conn = self._get_conn()
cursor = conn.execute(
"SELECT DISTINCT date_folder FROM images WHERE date_folder IS NOT NULL ORDER BY date_folder DESC"
)
folders = [row[0] for row in cursor.fetchall()]
conn.close()
return folders
# 全局实例