增加聊天情况热力图

This commit is contained in:
xaoyaoo 2024-08-07 10:24:19 +08:00
parent 535a767375
commit 187b9cce41
2 changed files with 6 additions and 3 deletions

View File

@ -462,11 +462,13 @@ def get_date_count():
word = rq_data.get("wxid", "")
start_time = rq_data.get("start_time", 0)
end_time = rq_data.get("end_time", 0)
time_format = rq_data.get("time_format", "%Y-%m-%d")
my_wxid = get_conf(g.caf, g.at, "last")
if not my_wxid: return ReJson(1001, body="my_wxid is required")
db_config = get_conf(g.caf, my_wxid, "db_config")
date_count = DBHandler(db_config).get_date_count(wxid=word, start_time=start_time, end_time=end_time)
db = DBHandler(db_config)
date_count = db.get_date_count(wxid=word, start_time=start_time, end_time=end_time, time_format=time_format)
return ReJson(0, date_count)

View File

@ -291,7 +291,7 @@ class MsgHandler(DatabaseBase):
return rdata, list(wxid_list)
@db_error
def get_date_count(self, wxid='', start_time: int = 0, end_time: int = 0):
def get_date_count(self, wxid='', start_time: int = 0, end_time: int = 0, time_format='%Y-%m-%d'):
"""
获取每日聊天记录数量包括发送者数量接收者数量和总数
"""
@ -312,7 +312,8 @@ class MsgHandler(DatabaseBase):
sql_time = "AND CreateTime BETWEEN ? AND ? " if start_time and end_time else ""
params = params + (start_time, end_time) if start_time and end_time else params
sql = ("SELECT strftime('%Y-%m-%d', CreateTime, 'unixepoch', 'localtime') AS date, COUNT(*) AS total_count ,"
sql = (f"SELECT strftime('{time_format}', CreateTime, 'unixepoch', 'localtime') AS date, "
" COUNT(*) AS total_count ,"
" SUM(CASE WHEN IsSender = 1 THEN 1 ELSE 0 END) AS sender_count, "
" SUM(CASE WHEN IsSender = 0 THEN 1 ELSE 0 END) AS receiver_count "
"FROM MSG "