master #43
59
main.py
59
main.py
@ -5,6 +5,8 @@ from astrbot.api import logger
|
|||||||
import random
|
import random
|
||||||
from .back import time_long, volume, isUserExist, insertUser, seconds_to_hms, ml_to_l_ml, get_user_name
|
from .back import time_long, volume, isUserExist, insertUser, seconds_to_hms, ml_to_l_ml, get_user_name
|
||||||
import pymysql
|
import pymysql
|
||||||
|
import matplotlib
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
from .Tool import get_tool_name
|
from .Tool import get_tool_name
|
||||||
import astrbot.api.message_components as Comp
|
import astrbot.api.message_components as Comp
|
||||||
from astrbot.core.utils.session_waiter import (
|
from astrbot.core.utils.session_waiter import (
|
||||||
@ -60,11 +62,11 @@ class MyPlugin(Star):
|
|||||||
time = [];V = [];a = [];b = []
|
time = [];V = [];a = [];b = []
|
||||||
for i in range(0,10):
|
for i in range(0,10):
|
||||||
time.append(round(random.uniform(1, 600), 2))
|
time.append(round(random.uniform(1, 600), 2))
|
||||||
V.append(round(random.uniform(0.01,100), 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]))
|
a.append(time_long(time[i]))
|
||||||
b.append(volume(V[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)"
|
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)
|
cur.execute(sql,values)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
cur.close()
|
cur.close()
|
||||||
@ -304,6 +306,56 @@ class MyPlugin(Star):
|
|||||||
cur.close()
|
cur.close()
|
||||||
conn.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.plot(day, volume)
|
||||||
|
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()
|
||||||
|
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
|
testNumber = 0
|
||||||
@filter.command("测试")
|
@filter.command("测试")
|
||||||
@ -345,8 +397,7 @@ class MyPlugin(Star):
|
|||||||
]
|
]
|
||||||
yield event.chain_result(chain)
|
yield event.chain_result(chain)
|
||||||
else:
|
else:
|
||||||
yield "获取骚话失败"
|
yield "获取骚话失败"
|
||||||
|
|
||||||
|
|
||||||
@filter.command("部署")
|
@filter.command("部署")
|
||||||
async def bushutest(self, event: AstrMessageEvent):
|
async def bushutest(self, event: AstrMessageEvent):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user