This commit is contained in:
shuaikangzhou 2023-04-05 00:01:06 +08:00
parent 19d529c36e
commit e307794507
7 changed files with 152 additions and 89 deletions

View File

@ -4,4 +4,7 @@
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="py.test" />
</component>
</module>

View File

@ -13,8 +13,9 @@ class AnalysisController(QWidget):
def __init__(self, username, parent=None):
super().__init__(parent)
self.ta_username = username
self.setWindowTitle('数据分析')
self.setWindowIcon(QIcon('./app/data/icon.png'))
# self.setWindowTitle('数据分析')
# self.setWindowIcon(QIcon('./app/data/icon.png'))
# self.setWindowFlag(Qt.FramelessWindowHint)
self.setStyleSheet('''QWidget{background-color:rgb(255, 255, 255);}''')
# self.setBackground()
@ -37,7 +38,8 @@ class AnalysisController(QWidget):
def label_01(self):
self.label = QLabel(self)
self.label.setGeometry(150, 100, 100, 100)
size = self.geometry()
self.label.setGeometry(size.width() // 2, self.height() // 2, 100, 100)
self.label.setToolTip("这是一个标签")
self.m_movie()
@ -49,29 +51,19 @@ class AnalysisController(QWidget):
def initUI(self):
self.label.setVisible(False)
self.setStyleSheet('''QWidget{background-color:rgb(244, 244, 244);}''')
main_box = QHBoxLayout(self)
main_box = QVBoxLayout(self)
self.browser1 = QWebEngineView()
self.browser1.load(QUrl('file:///data/聊天统计/title.html'))
# self.browser1 = QFrame(self)
# self.browser1.setFrameShape(QFrame.StyledPanel)
# self.layoutWidget = QtWidgets.QWidget(self.browser1)
# # self.layoutWidget.setGeometry(QtCore.QRect(71, 63, 227, 155))
# self.verticalLayout = QtWidgets.QVBoxLayout(self.layoutWidget)
# self.verticalLayout.setContentsMargins(0, 0, 0, 0)
# self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
# self.label_2 = QtWidgets.QLabel(self.layoutWidget)
# _translate = QtCore.QCoreApplication.translate
# conRemark = data.get_conRemark(self.ta_username)
# self.label_2.setText(_translate("Dialog", f"{conRemark}"))
# self.horizontalLayout_2.addWidget(self.label_2)
# self.browser1.setLayout(self.horizontalLayout_2)
self.browser2 = QWebEngineView()
self.browser2.load(QUrl('file:///data/聊天统计/wordcloud.html'))
self.browser3 = QWebEngineView()
self.browser3.load(QUrl('file:///data/聊天统计/time.html'))
self.browser4 = QWebEngineView()
self.browser4.load(QUrl('http://www.baidu.com'))
# self.browser4.resize(800, 600)
self.browser5 = QWebEngineView()
self.browser5.load(QUrl('file:///data/聊天统计/chat_session.html'))
self.browser6 = QWebEngineView()
@ -85,6 +77,42 @@ class AnalysisController(QWidget):
self.browser10 = QWebEngineView()
self.browser10.load(QUrl('file:///data/聊天统计/send_recv_rate.html'))
main_box.addWidget(self.browser1)
scrollArea = QScrollArea(self)
scrollAreaContent = QWidget(scrollArea)
Vlayout2 = QVBoxLayout(scrollAreaContent)
splitter2 = QSplitter(Qt.Vertical)
splitter2.addWidget(self.browser2)
Vlayout2.addWidget(splitter2)
splitter3 = QSplitter(Qt.Vertical)
splitter3.addWidget(self.browser3)
Vlayout2.addWidget(splitter3)
splitter4 = QSplitter(Qt.Vertical)
splitter4.addWidget(self.browser4)
Vlayout2.addWidget(splitter4)
splitter5 = QSplitter(Qt.Vertical)
splitter5.addWidget(self.browser6)
Vlayout2.addWidget(splitter5)
Vlayout2.addWidget(self.browser3)
Vlayout2.addWidget(self.browser6)
Vlayout2.addWidget(self.browser5)
Vlayout2.addWidget(self.browser7)
Vlayout2.addWidget(self.browser8)
Vlayout2.addWidget(self.browser9)
Vlayout2.addWidget(self.browser10)
scrollAreaContent.setLayout(Vlayout2)
scrollArea.setWidget(scrollAreaContent)
main_box.addWidget(scrollArea)
main_box.setStretch(0, 1)
main_box.setStretch(1, 10)
'''
splitter1 = QSplitter(Qt.Vertical)
splitter2 = QSplitter(Qt.Horizontal)
splitter3 = QSplitter(Qt.Horizontal)
@ -97,7 +125,7 @@ class AnalysisController(QWidget):
splitter1.addWidget(self.browser1)
splitter1.addWidget(splitter2)
splitter1.setSizes([1, 8])
splitter1.setSizes([1, 13])
splitter2.addWidget(splitter6)
splitter2.addWidget(splitter3)
@ -109,7 +137,7 @@ class AnalysisController(QWidget):
splitter4.addWidget(splitter5)
splitter4.addWidget(self.browser2)
splitter4.setSizes([1, 5])
splitter4.setSizes([2, 13])
splitter5.addWidget(self.browser3)
# splitter5.addWidget(self.browser4)
@ -127,9 +155,10 @@ class AnalysisController(QWidget):
splitter9.addWidget(self.browser9)
splitter9.addWidget(self.browser10)
main_box.addWidget(splitter1)
'''
# main_box.addWidget(splitter1)
self.setLayout(main_box)
# self.setLayout(Vlayout1)
def setBackground(self):
palette = QPalette()

View File

@ -32,6 +32,10 @@ Type = {
'436207665': '发红包',
'49': '分享链接'
}
charts_width = 700
charts_height = 600
wordcloud_width = 700
wordcloud_height = 600
def send_recv_rate(username):
@ -40,7 +44,7 @@ def send_recv_rate(username):
total_num = send_num + recv_num
print(send_num, recv_num)
c = (
Pie(init_opts=opts.InitOpts(width="463px", height="243px"))
Pie(init_opts=opts.InitOpts(width=f"{charts_width}px", height=f"{charts_height}px"))
.add(
"",
[
@ -74,7 +78,7 @@ def msg_type_rate(username):
new_data.append(('其他', data2))
c = (
Pie(init_opts=opts.InitOpts(width="460px", height="240px"))
Pie(init_opts=opts.InitOpts(width=f"{charts_width}px", height=f"{charts_height}px"))
.add(
"",
new_data
@ -110,7 +114,7 @@ def message_word_cloud(username):
text_data = text_data[:100]
# print(text_data)
(
WordCloud(init_opts=opts.InitOpts(width="900px", height="700px"))
WordCloud(init_opts=opts.InitOpts(width=f"{wordcloud_width}px", height=f"{wordcloud_height}px"))
.add(series_name="聊天文字", data_pair=text_data, word_size_range=[20, 100])
.set_global_opts(
title_opts=opts.TitleOpts(
@ -126,10 +130,12 @@ def message_word_cloud(username):
def calendar_chart(username):
msg_data = data.get_msg_by_days(username, year='2022')
if not msg_data:
return False
min_ = min(map(lambda x: x[1], msg_data))
max_ = max(map(lambda x: x[1], msg_data))
c = (
Calendar(init_opts=opts.InitOpts(width="460px", height="270px"))
Calendar(init_opts=opts.InitOpts(width=f"{charts_width}px", height=f"{charts_height}px"))
.add(
"",
msg_data,
@ -160,11 +166,11 @@ def month_num(username):
y_data = list(map(lambda x: x[1], msg_data))
x_axis = list(map(lambda x: x[0], msg_data))
c = (
Bar(init_opts=opts.InitOpts(width="440px", height="265px"))
Bar(init_opts=opts.InitOpts(width=f"{charts_width}px", height=f"{charts_height}px"))
.add_xaxis(x_axis)
.add_yaxis("消息数量", y_data)
.set_global_opts(
title_opts=opts.TitleOpts(title="逐月聊天统计", subtitle=None),
title_opts=opts.TitleOpts(title="逐月统计", subtitle=None),
datazoom_opts=opts.DataZoomOpts(),
toolbox_opts=opts.ToolboxOpts(),
)
@ -180,7 +186,7 @@ def chat_session(username):
# print(y_data)
# max_ = max(y_data)
c = (
Line(init_opts=opts.InitOpts(width="460px", height="270px"))
Line(init_opts=opts.InitOpts(width=f"{charts_width}px", height=f"{charts_height}px"))
.add_xaxis(xaxis_data=x_axis)
.add_yaxis(
series_name="聊天频率",
@ -236,12 +242,12 @@ def sport(username):
continue
df = pd.DataFrame({'ranks': ranks, 'score': steps, 'date': date}, index=date)
months = pd.date_range(date[0], date[-1], freq='M')
tl = Timeline(init_opts=opts.InitOpts(width="440px", height="265px"))
tl = Timeline(init_opts=opts.InitOpts(width=f"{charts_width}px", height=f"{charts_height}px"))
tl.add_schema(is_auto_play=True)
for i in range(len(months) - 1):
da = df[(months[i + 1].strftime("%Y-%m-%d") >= df['date']) & (df['date'] > months[i].strftime("%Y-%m-%d"))]
bar = (
Bar(init_opts=opts.InitOpts(width="440px", height="265px"))
Bar(init_opts=opts.InitOpts(width=f"{charts_width}px", height=f"{charts_height}px"))
.add_xaxis(list(da['date']))
.add_yaxis(
"步数",
@ -284,7 +290,10 @@ def sport(username):
)
)
.set_global_opts(
title_opts=opts.TitleOpts(title="{}".format(months[i + 1].strftime("%Y-%m"))),
title_opts=opts.TitleOpts(
title="{}".format(months[i + 1].strftime("%Y-%m")),
),
# legend_opts=opts.LegendOpts(is_show=False),
yaxis_opts=opts.AxisOpts(is_inverse=True),
# xaxis_opts=opts.AxisOpts(type_='time')
@ -297,7 +306,7 @@ def sport(username):
)
# init_opts = opts.InitOpts(width="400px", height="235px")
line = (
Line(init_opts=opts.InitOpts(width="440px", height="265px"))
Line(init_opts=opts.InitOpts(width=f"{charts_width}px", height=f"{charts_height}px"))
.add_xaxis(list(da['date']))
.add_yaxis(
"排名",
@ -319,7 +328,7 @@ def sport(username):
)
bar.overlap(line)
grid = Grid()
grid.add(bar, opts.GridOpts(pos_left="7%", pos_right="11%"), is_control_axis_index=True)
grid.add(bar, opts.GridOpts(pos_left="5%", pos_right="11%"), is_control_axis_index=True)
# grid.render("grid_multi_yaxis.html")
tl.add(grid, "{}".format(months[i].strftime("%Y-%m")))
tl.render("./data/聊天统计/sports.html")
@ -349,8 +358,8 @@ def chat_start_endTime(username):
<style>
/* 倒计时开始 */
.gn_box {
padding: 10px 14px;
margin-bottom: 10px;
padding: 0px 0px;
margin-bottom:0px;
text-align: center;
background-color: #fff;
}
@ -430,8 +439,8 @@ def title(username):
<style>
/* 倒计时开始 */
.gn_box {
padding: 10px 14px;
margin-bottom: 10px;
padding: 0px 0px;
margin-bottom: 0px;
text-align: center;
background-color: #fff;
}
@ -460,7 +469,7 @@ font-size: 18px;
font-size: 28px;
}
#table {
width: 600px; height: 400px;//可随意
width: 600px; height: 100px;//可随意
position: absolute; left: 0; top: 0; right: 0; bottom: 0;
margin: auto; /* 有了这个就自动居中了 */
}
@ -475,7 +484,7 @@ font-size: 18px;
<table>
<tr>
<td>
<img src="../../../%s" height="50" width="50"
<img src="../../../%s" height="40" width="40"
alt="Avatar"/>
</td>
</tr>

View File

@ -38,6 +38,7 @@ class ContactController(QWidget, Ui_Dialog):
self.setupUi(self)
self.setWindowTitle('WeChat')
self.setWindowIcon(QIcon('./app/data/icon.png'))
# self.setStyleSheet('''QWidget{background-color:rgb(255, 255, 255);}''')
self.initui()
self.Me = Me
self.Thread = ChatMsg(self.Me.username, None)
@ -60,22 +61,21 @@ class ContactController(QWidget, Ui_Dialog):
self.last_btn = None
def initui(self):
# 槽函数连接
self.btn_back.clicked.connect(self.back)
self.btn_output.clicked.connect(self.output)
self.btn_analysis.clicked.connect(self.analysis)
self.btn_emotion.clicked.connect(self.emotionale_Analysis)
self.qurl = QUrl('baidu.com')
self.lay0 = QHBoxLayout()
self.widget.setLayout(self.lay0)
self.lay0 = QVBoxLayout()
self.widget.setLayout(self.lay0)
self.widget.setStyleSheet('''QWidget{background-color:rgb(255, 255, 255);}''')
self.frame = QtWidgets.QFrame()
self.frame.setObjectName("frame")
self.userinfo = userinfoUi.Ui_Frame() # 联系人信息界面
self.userinfo.setupUi(self.frame)
# self.userinfo.btn_outbut.clicked.connect(self.output)
self.userinfo.progressBar.setVisible(False)
self.lay0.addWidget(self.frame)
# self.userinfo.btn_analysis.clicked.connect(self.analysis)
def showContact(self):
"""
@ -88,12 +88,15 @@ class ContactController(QWidget, Ui_Dialog):
self.show_flag = True
rconversations = data.get_rconversation()
max_hight = max(len(rconversations) * 80, 680)
# 设置滚动区域的高度
self.scrollAreaWidgetContents.setGeometry(
QtCore.QRect(0, 0, 300, max_hight))
for i in range(len(rconversations)):
rconversation = rconversations[i]
username = rconversation[1]
# print('联系人:', i, rconversation)
# 创建联系人按钮对象
# 将实例化对象添加到self.contacts储存起来
pushButton_2 = Contact(self.scrollAreaWidgetContents, i, rconversation)
pushButton_2.setGeometry(QtCore.QRect(0, 80 * i, 300, 80))
pushButton_2.setLayoutDirection(QtCore.Qt.LeftToRight)
@ -114,14 +117,15 @@ class ContactController(QWidget, Ui_Dialog):
if self.last_talkerId and self.last_talkerId != talkerId:
print('对方账号:', self.last_talkerId)
self.contacts[self.last_talkerId].setStyleSheet(
"QPushButton {background-color: rgb(253,253,253);}"
"QPushButton:hover{background-color: rgb(209,209,209);}\n"
"QPushButton {background-color: rgb(220,220,220);}"
"QPushButton:hover{background-color: rgb(208,208,208);}\n"
)
self.last_talkerId = talkerId
self.contacts[talkerId].setStyleSheet(
"QPushButton {background-color: rgb(198,198,198);}"
"QPushButton:hover{background-color: rgb(209,209,209);}\n"
)
# 设置联系人的基本信息
conRemark = data.get_conRemark(talkerId)
nickname, alias = data.get_nickname(talkerId)
self.label_remark.setText(conRemark)
@ -173,8 +177,10 @@ class ContactController(QWidget, Ui_Dialog):
聊天分析
:return:
"""
self.frame.setVisible(False)
self.frame.setVisible(False) # 将userinfo界面设置为不可见
# 判断talkerId是否已经分析过了
# 是:则清空其他界面,直接显示该界面
# 否:清空其他界面,创建用户界面并显示
if self.now_talkerId in self.view_analysis:
self.setViewVisible(self.now_talkerId, mod=ANALYSIS)
return True
@ -186,7 +192,10 @@ class ContactController(QWidget, Ui_Dialog):
def emotionale_Analysis(self):
print('情感分析', data.get_conRemark(self.now_talkerId))
self.frame.setVisible(False)
self.frame.setVisible(False) # 将userinfo界面设置为不可见
# 判断talkerId是否已经分析过了
# 是:则清空其他界面,直接显示该界面
# 否:清空其他界面,创建用户界面并显示
if self.now_talkerId in self.view_emotion:
self.setViewVisible(self.now_talkerId, mod=EMOTION)
return True
@ -204,6 +213,9 @@ class ContactController(QWidget, Ui_Dialog):
self.lay0.addWidget(self.analysisView)
def back(self):
"""
将userinfo界面设置为可见其他界面设置为不可见
"""
self.frame.setVisible(True)
self.setViewVisible(self.now_talkerId)
@ -292,8 +304,8 @@ class Contact(QtWidgets.QPushButton):
self.gridLayout1.setRowStretch(1, 3)
self.setLayout(self.gridLayout1)
self.setStyleSheet(
"QPushButton {background-color: rgb(253,253,253);}"
"QPushButton:hover{background-color: rgb(209,209,209);}\n"
"QPushButton {background-color: rgb(220,220,220);}"
"QPushButton:hover{background-color: rgb(208,208,208);}\n"
)
self.msgCount = contact[0]
self.username = contact[1]

View File

@ -29,6 +29,7 @@ class Ui_Dialog(object):
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setSpacing(0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.scrollArea = QtWidgets.QScrollArea(self.frame_2)
self.scrollArea.setEnabled(True)
self.scrollArea.setMinimumSize(QtCore.QSize(325, 0))
@ -42,9 +43,11 @@ class Ui_Dialog(object):
self.scrollArea.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContentsOnFirstShow)
self.scrollArea.setWidgetResizable(False)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 300, 12000))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.pushButton_2 = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.pushButton_2.setGeometry(QtCore.QRect(0, 0, 300, 80))
self.pushButton_2.setLayoutDirection(QtCore.Qt.LeftToRight)
@ -55,15 +58,19 @@ class Ui_Dialog(object):
self.label = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label.setGeometry(QtCore.QRect(220, 10, 72, 15))
self.label.setObjectName("label")
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.horizontalLayout_2.addWidget(self.scrollArea)
self.frame = QtWidgets.QFrame(self.frame_2)
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame.setFrameShape(QtWidgets.QFrame.NoFrame)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.verticalLayout = QtWidgets.QVBoxLayout(self.frame)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setSpacing(0)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setSpacing(0)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.label_remark = QtWidgets.QLabel(self.frame)
self.label_remark.setMaximumSize(QtCore.QSize(16777215, 100))
@ -87,6 +94,7 @@ class Ui_Dialog(object):
self.horizontalLayout_3.addWidget(self.btn_back)
self.verticalLayout.addLayout(self.horizontalLayout_3)
self.widget = QtWidgets.QWidget(self.frame)
self.widget.setAutoFillBackground(True)
self.widget.setObjectName("widget")
self.verticalLayout.addWidget(self.widget)
self.verticalLayout.setStretch(0, 1)

View File

@ -153,14 +153,32 @@
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,30">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_remark">
<property name="maximumSize">
@ -210,7 +228,11 @@
</layout>
</item>
<item>
<widget class="QWidget" name="widget" native="true"/>
<widget class="QWidget" name="widget" native="true">
<property name="autoFillBackground">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>

View File

@ -21,20 +21,26 @@
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="frame_info">
<property name="minimumSize">
<size>
<width>100</width>
<width>80</width>
<height>500</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<width>80</width>
<height>16777215</height>
</size>
</property>
@ -50,9 +56,9 @@
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>0</x>
<x>10</x>
<y>190</y>
<width>91</width>
<width>61</width>
<height>271</height>
</rect>
</property>
@ -137,42 +143,16 @@
<widget class="QLabel" name="myavatar">
<property name="geometry">
<rect>
<x>10</x>
<x>5</x>
<y>40</y>
<width>80</width>
<height>80</height>
<width>70</width>
<height>70</height>
</rect>
</property>
<property name="text">
<string>avatar</string>
</property>
</widget>
<widget class="QPushButton" name="sign_up">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>40</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>退出</string>
</property>
</widget>
<widget class="QPushButton" name="btn_destroy">
<property name="geometry">
<rect>
<x>50</x>
<y>0</y>
<width>40</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>注销</string>
</property>
</widget>
</widget>
</item>
<item>