forked from saipo/astrbot_plugin_dajiao
绘制日产量折线图
This commit is contained in:
parent
612115f7fc
commit
31f82db044
51
main.py
51
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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user