Skip to content

Commit

Permalink
add calender_chart analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
DzhiWang committed Dec 7, 2023
1 parent 2efc528 commit 3a3baa5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
15 changes: 15 additions & 0 deletions app/DataBase/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ def get_messages_by_keyword(self, username_, keyword, num=5, max_len=10):

return res

def get_messages_by_days(self, username_, year_='2023'):
sql = '''
SELECT strftime('%Y-%m-%d',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID)
from MSG
where StrTalker = ? and strftime('%Y',CreateTime,'unixepoch','localtime') = ?
group by days
'''
try:
lock.acquire(True)
self.cursor.execute(sql, [username_, year_])
result = self.cursor.fetchall()
finally:
lock.release()
return result

def get_first_time_of_message(self, username_):
if not self.open_flag:
return None
Expand Down
43 changes: 41 additions & 2 deletions app/analysis/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

from PyQt5.QtCore import QFile, QTextStream, QIODevice

import sys
sys.path.append('.')

from app.DataBase import msg_db, MsgType
from app.person_pc import ContactPC
import jieba
Expand Down Expand Up @@ -76,11 +79,47 @@ def wordcloud(wxid):
}


def calendar_chart(wxid, year):
calendar_data = msg_db.get_messages_by_days(wxid, year)

if not calendar_data:
return False
min_ = min(map(lambda x: x[1], calendar_data))
max_ = max(map(lambda x: x[1], calendar_data))

c = (
Calendar(init_opts=opts.InitOpts(width=f"{charts_width}px", height=f"{charts_height}px"))
.add(
"",
calendar_data,
calendar_opts=opts.CalendarOpts(range_=year)
)
.set_global_opts(
title_opts=opts.TitleOpts(title="2023年聊天情况"),
visualmap_opts=opts.VisualMapOpts(
max_=max_,
min_=min_,
orient="horizontal",
# is_piecewise=True,
# pos_top="200px",
pos_bottom="0px",
pos_left="0px",
),
legend_opts=opts.LegendOpts(is_show=False)
)
)
return {
'chart_data': c
}


class Analysis:
pass


if __name__ == '__main__':
msg_db.init_database(path='../DataBase/Msg/MSG.db')
w = wordcloud('wxid_0o18ef858vnu22')
print(w)
# w = wordcloud('wxid_0o18ef858vnu22')
c = calendar_chart('wxid_27hqbq7vx5hf22', '2023')
c['chart_data'].render("./data/聊天统计/calendar.html")
print('c:::', c)

0 comments on commit 3a3baa5

Please sign in to comment.