Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add calender_chart analysis #97

Merged
merged 3 commits into from
Dec 7, 2023
Merged
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
20 changes: 19 additions & 1 deletion app/DataBase/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,24 @@ 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
'''
result = None
if not self.open_flag:
return None
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 Expand Up @@ -213,4 +231,4 @@ def __del__(self):
pprint(msg.get_message_by_num('wxid_0o18ef858vnu22', local_id))
print(msg.get_messages_by_keyword(wxid, '干嘛'))
pprint(msg.get_messages_by_keyword(wxid, '干嘛')[0])
print(msg.get_first_time_of_message('wxid_fervbwign7m822'))
print(msg.get_first_time_of_message('wxid_0o18ef858vnu22'))
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)