add hour_count in analysis

This commit is contained in:
DzhiWang
2023-12-07 19:48:59 +08:00
parent 92d0314b7c
commit f3bc7c8f28
2 changed files with 63 additions and 0 deletions
+20
View File
@@ -227,6 +227,26 @@ class Msg:
# result.sort(key=lambda x: x[5])
return result
def get_messages_by_hour(self, username_, year_='2023'):
sql = '''
SELECT strftime('%H:00',CreateTime,'unixepoch','localtime') as hours,count(MsgSvrID)
from MSG
where StrTalker = ? and strftime('%Y',CreateTime,'unixepoch','localtime') = ?
group by hours
'''
result = None
if not self.open_flag:
return None
try:
lock.acquire(True)
self.cursor.execute(sql, [username_, year_])
result = self.cursor.fetchall()
except sqlite3.DatabaseError:
logger.error(f'{traceback.format_exc()}\n数据库损坏请删除msg文件夹重试')
finally:
lock.release()
# result.sort(key=lambda x: x[5])
return result
def get_first_time_of_message(self, username_):
if not self.open_flag: