From 31f82db044a3dc8339f70882bba3d6989cc0f7e6 Mon Sep 17 00:00:00 2001 From: Saipo Date: Fri, 23 May 2025 12:19:13 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E7=BB=98=E5=88=B6=E6=97=A5=E4=BA=A7?= =?UTF-8?q?=E9=87=8F=E6=8A=98=E7=BA=BF=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 319b1c4..84c29b9 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ from astrbot.api import logger import random from .back import time_long, volume, isUserExist, insertUser, seconds_to_hms, ml_to_l_ml, get_user_name import pymysql +import matplotlib.pyplot as plt from .Tool import get_tool_name import astrbot.api.message_components as Comp from astrbot.core.utils.session_waiter import ( @@ -304,6 +305,53 @@ class MyPlugin(Star): cur.close() conn.close() + @filter.command("我的日产量") + async def mydayvolume(self, event: AstrMessageEvent): + if isUserExist(event.get_sender_id()) != True: + insertUser(event.get_sender_id()) + conn=pymysql.connect(host = '192.168.31.9' # 连接名称,默认 + ,user = 'saipo' + ,passwd='Grasste0403' # 密码 + ,port= 3306 # 端口,默认为3306 + ,db='saipo' # 数据库名称 + ,charset='utf8' # 字符编码 + ) + cur = conn.cursor() + sql = "SELECT DAY(eventTime),round(sum(volume),2) FROM dajiao WHERE openid = %s and DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(eventTime) GROUP BY DAY(eventTime);" + openid = event.get_sender_id() + cur.execute(sql,(openid,)) + date = cur.fetchall() + if len(date) == 0: + cur.close() + conn.close() + yield event.plain_result(f"没有找到数据哦!") + day = [] + volume = [] + + for i in range(len(date)): + day.append(date[i][0]) + volume.append(date[i][1]) + plt.pyplot.plot(day, volume) + plt.pyplot.title('日产量') + plt.pyplot.xlabel('日期') + plt.pyplot.ylabel('日产量') + plt.pyplot.xticks(day) + plt.pyplot.grid() + plt.pyplot.savefig('dayvolume.png') + plt.pyplot.close() + with open('dayvolume.png', 'rb') as f: + image_data = f.read() + image = Comp.Image.fromBytes(image_data) + chain = [ + Comp.At(qq=event.get_sender_id()), + Comp.Plain("日产量折线图:"), + image, + ] + yield event.chain_result(chain) + cur.close() + conn.close() + + testNumber = 0 @filter.command("测试") @@ -345,8 +393,7 @@ class MyPlugin(Star): ] yield event.chain_result(chain) else: - yield "获取骚话失败" - + yield "获取骚话失败" @filter.command("部署") async def bushutest(self, event: AstrMessageEvent): From 87a2ef7a1e367197e1bc0bd526a22cd339affe4e Mon Sep 17 00:00:00 2001 From: Saipo Date: Fri, 23 May 2025 12:27:36 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BB=98=E5=9B=BEbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 84c29b9..97975b1 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ from astrbot.api import logger import random from .back import time_long, volume, isUserExist, insertUser, seconds_to_hms, ml_to_l_ml, get_user_name import pymysql +import matplotlib import matplotlib.pyplot as plt from .Tool import get_tool_name import astrbot.api.message_components as Comp @@ -331,14 +332,14 @@ class MyPlugin(Star): for i in range(len(date)): day.append(date[i][0]) volume.append(date[i][1]) - plt.pyplot.plot(day, volume) - plt.pyplot.title('日产量') - plt.pyplot.xlabel('日期') - plt.pyplot.ylabel('日产量') - plt.pyplot.xticks(day) - plt.pyplot.grid() - plt.pyplot.savefig('dayvolume.png') - plt.pyplot.close() + plt.plot(day, volume) + plt.title('日产量') + plt.xlabel('日期') + plt.ylabel('日产量') + plt.xticks(day) + plt.grid() + plt.savefig('dayvolume.png') + plt.close() with open('dayvolume.png', 'rb') as f: image_data = f.read() image = Comp.Image.fromBytes(image_data) From 08f05ccaf922bf29fb3d7d73a859e9af761542d6 Mon Sep 17 00:00:00 2001 From: Saipo Date: Fri, 23 May 2025 12:32:07 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E5=9C=A8=E6=8A=98=E7=8E=B0=E4=B8=8A?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 97975b1..0a62717 100644 --- a/main.py +++ b/main.py @@ -333,10 +333,13 @@ class MyPlugin(Star): day.append(date[i][0]) volume.append(date[i][1]) plt.plot(day, volume) - plt.title('日产量') - plt.xlabel('日期') - plt.ylabel('日产量') + plt.title('dayvolume') + plt.xlabel('day') + plt.ylabel('volume') plt.xticks(day) + #设置显示数据 + for x, y in zip(day, volume): + plt.text(x, y, f'{y}', ha='center', va='bottom', fontsize=10) plt.grid() plt.savefig('dayvolume.png') plt.close() From f4f40cd4aaea2a8da651b1877610fd3a1b588e59 Mon Sep 17 00:00:00 2001 From: Ruler229 Date: Fri, 23 May 2025 14:27:05 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20main.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 0a62717..2a17a11 100644 --- a/main.py +++ b/main.py @@ -66,7 +66,7 @@ class MyPlugin(Star): a.append(time_long(time[i])) b.append(volume(V[i])) sql = "INSERT INTO dajiao (openid, timelong, volume) VALUES (%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s)" - values = (user_name,time[0],V[0]),(user_name,time[1],V[1]),(user_name,time[2],V[2]),(user_name,time[3],V[3]),(user_name,time[4],V[4]),(user_name,time[5],V[5]),(user_name,time[6],V[6]),(user_name,time[7],V[7]),(user_name,time[8],V[8]),(user_name,time[9],V[9]) + values = (user_name,time[0],V[0],user_name,time[1],V[1],user_name,time[2],V[2],user_name,time[3],V[3],user_name,time[4],V[4],user_name,time[5],V[5],user_name,time[6],V[6],user_name,time[7],V[7],user_name,time[8],V[8],user_name,time[9],V[9]) cur.execute(sql,values) conn.commit() cur.close() From 49e1bb15a9a01d9d2d20d6b6659fb5193c59b057 Mon Sep 17 00:00:00 2001 From: Ruler229 Date: Fri, 23 May 2025 14:55:44 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20main.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 2a17a11..65227da 100644 --- a/main.py +++ b/main.py @@ -61,7 +61,7 @@ class MyPlugin(Star): cur = conn.cursor() time = [];V = [];a = [];b = [] for i in range(0,10): - time.append(round(random.uniform(1, 600), 2)) + time.append(round(random.uniform(1, 600), 2)) if i==0 else time.append(round(random.uniform(1, time[i-1]), 2)) V.append(round(random.uniform(0.01,100), 2)) a.append(time_long(time[i])) b.append(volume(V[i])) From 9391193e271cd789a2a796746382e62e956df57a Mon Sep 17 00:00:00 2001 From: Ruler229 Date: Fri, 23 May 2025 15:03:05 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20main.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 65227da..104ecc8 100644 --- a/main.py +++ b/main.py @@ -61,8 +61,8 @@ class MyPlugin(Star): cur = conn.cursor() time = [];V = [];a = [];b = [] for i in range(0,10): - time.append(round(random.uniform(1, 600), 2)) if i==0 else time.append(round(random.uniform(1, time[i-1]), 2)) - V.append(round(random.uniform(0.01,100), 2)) + time.append(round(random.uniform(1, 600), 2)) + V.append(round(random.uniform(0.01,100), 2)) if i==0 else V.append(round(random.uniform(1, V[i-1]), 2)) a.append(time_long(time[i])) b.append(volume(V[i])) sql = "INSERT INTO dajiao (openid, timelong, volume) VALUES (%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s)" From f1bc92f73f62ff9ed5772bfc9fc2ee4f337b29f9 Mon Sep 17 00:00:00 2001 From: Ruler229 Date: Fri, 23 May 2025 15:25:58 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20main.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 104ecc8..af71d81 100644 --- a/main.py +++ b/main.py @@ -62,7 +62,7 @@ class MyPlugin(Star): time = [];V = [];a = [];b = [] for i in range(0,10): time.append(round(random.uniform(1, 600), 2)) - V.append(round(random.uniform(0.01,100), 2)) if i==0 else V.append(round(random.uniform(1, V[i-1]), 2)) + V.append(round(random.uniform(0.01,100), 2)) if i==0 else V.append(round(random.uniform(1, V[i-1]+1), 2)) a.append(time_long(time[i])) b.append(volume(V[i])) sql = "INSERT INTO dajiao (openid, timelong, volume) VALUES (%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s)"