From c75fab5e65b7f60a908da28dad1bec54437e2545 Mon Sep 17 00:00:00 2001 From: NekoRabi <1215791340@qq.com> Date: Fri, 16 Jun 2023 18:22:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BE=9D=E8=B5=96=E5=92=8C?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 2 + utils/Logger.py | 248 ++++++++++++++++++----------------- utils/MessageChainBuilder.py | 18 ++- utils/MessageChainSender.py | 22 ++-- utils/echarts.py | 229 +++++++++++++++++++++++++++++--- utils/file_cleaner.py | 3 +- 6 files changed, 365 insertions(+), 157 deletions(-) diff --git a/requirements.txt b/requirements.txt index f312f52..b77a281 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,3 +10,5 @@ uvicorn~=0.17.6 tencentcloud-sdk-python==3.0.638 pytz~=2022.1 websockets~=10.3 +pyecharts~=2.0.3 +snapshot-selenium~=0.0.2 \ No newline at end of file diff --git a/utils/Logger.py b/utils/Logger.py index 3964b60..db877c7 100644 --- a/utils/Logger.py +++ b/utils/Logger.py @@ -1,120 +1,128 @@ -import logging -from logging.handlers import TimedRotatingFileHandler -from utils.cfg_loader import read_file - -import time -import os - -__all__ = ['root_logger', 'create_logger'] - - -def make_dir(make_dir_path): - path = make_dir_path.strip() - if not os.path.exists(path): - os.makedirs(path) - return path - - -_cfg = read_file(r'./config/config.yml') - - -def log_config(): - LOG_FORMAT = "[%(asctime)s][%(levelname)s]: %(message)s" - fname = time.strftime("news_%Y%m%d.log", time.localtime()) - level = logging.INFO - logging.basicConfig(level=level, format=LOG_FORMAT) - - # 创建TimedRotatingFileHandler对象,每天生成一个文件 - log_file_handler = TimedRotatingFileHandler(filename='test.log', when="D", interval=1, backupCount=3) - # 设置日志打印格式 - formatter = logging.Formatter(LOG_FORMAT) - log_file_handler.setFormatter(formatter) - logging.getLogger('').addHandler(log_file_handler) - - -def create_logger(log_level: str = 'INFO', logger_name: str = None, log_file_folder: str = r'./log', - fmt='%(asctime)s - %(name)s - %(levelname)-6s - %(message)s', date_fmt='%Y-%m-%d %H:%M:%S', - timer_config=None): - """ - 创建Logger - - Args: - log_level: 日志等级 - logger_name: Logger_Name,默认root - log_file_folder: 日志存储路径 - fmt: 日志输出格式 - date_fmt: 时间格式 - timer_config: Timer配置 - - Returns:Logger - - """ - if timer_config is None: - timer_config = dict(when="D", interval=1, backupCount=0) - project_name = "log" - folder_format = time.strftime('%Y-%m', time.localtime(time.time())) - log_file_name = time.strftime('%Y-%m-%d', time.localtime(time.time())) + '.log' - # log_file_folder = os.path.abspath( - # os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) + os.sep + project_name + os.sep + folder_format - make_dir(log_file_folder) - log_file_str = log_file_folder + os.sep + log_file_name - if logger_name: - logger = logging.getLogger(logger_name) - else: - logger = logging.getLogger() - loglevel = log_level.upper() - if loglevel in ["CRITICAL", "FATAL"]: - loggerlevel = logging.CRITICAL - elif loglevel == "ERROR": - loggerlevel = logging.ERROR - elif loglevel == "INFO": - loggerlevel = logging.INFO - elif loglevel in ["WARNING", "WARN"]: - loggerlevel = logging.WARNING - else: - loggerlevel = logging.DEBUG - logger.setLevel(loggerlevel) - # logger_format = logging.Formatter( - # fmt='%(asctime)s - %(name)s - %(levelname)-9s - %(filename)-8s : %(lineno)s line - %(message)s', - # datefmt='%Y-%m-%d %H:%M:%S') - logger_format = logging.Formatter( - fmt=fmt, - datefmt=date_fmt) - - timerhandler = TimedRotatingFileHandler(filename=log_file_str, when=timer_config.get('when', 'D'), - interval=timer_config.get('interval', 1), - backupCount=timer_config.get('backupCount', 0), - encoding='utf-8') - timerhandler.setFormatter(logger_format) - - logger.addHandler(timerhandler) - - return logger - - -def getQQlogger(): - project_name = "qq-log" - folder_format = time.strftime('%Y-%m', time.localtime(time.time())) - log_file_name = time.strftime('%Y-%m-%d', time.localtime(time.time())) + '.log' - # log_file_folder = os.path.abspath( - # os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) + os.sep + project_name + os.sep + folder_format - log_file_folder = r'./qq-log' - make_dir(log_file_folder) - log_file_str = log_file_folder + os.sep + log_file_name - - logger = logging.getLogger("qqlogger") - logger.setLevel(20) - logger_format = logging.Formatter(fmt='time="%(asctime)s" - level=%(levelname)s - %(message)s', - datefmt='%Y-%m-%d %H:%M:%S') - - timerhandler = TimedRotatingFileHandler(filename=log_file_str, when="D", interval=1, backupCount=0, - encoding='utf-8') - timerhandler.setFormatter(logger_format) - - logger.addHandler(timerhandler) - - return logger - - -root_logger = create_logger(_cfg.get('loglevel', 'INFO')) -# QQ_logger = getQQlogger() +import logging +from logging.handlers import TimedRotatingFileHandler +from utils.cfg_loader import read_file + +import time +import os + +__all__ = ['root_logger', 'create_logger'] + + +def make_dir(make_dir_path): + path = make_dir_path.strip() + if not os.path.exists(path): + os.makedirs(path) + return path + + +_cfg = read_file(r'./config/config.yml') + + +def log_config(): + LOG_FORMAT = "[%(asctime)s][%(levelname)s]: %(message)s" + fname = time.strftime("news_%Y%m%d.log", time.localtime()) + level = logging.INFO + logging.basicConfig(level=level, format=LOG_FORMAT) + + # 创建TimedRotatingFileHandler对象,每天生成一个文件 + log_file_handler = TimedRotatingFileHandler(filename='test.log', when="D", interval=1, backupCount=3) + # 设置日志打印格式 + formatter = logging.Formatter(LOG_FORMAT) + log_file_handler.setFormatter(formatter) + logging.getLogger('').addHandler(log_file_handler) + + +def create_logger(log_level: str = 'INFO', logger_name: str = None, log_file_folder: str = r'./log', + fmt='%(asctime)s - %(name)s - %(levelname)-6s - %(message)s', date_fmt='%Y-%m-%d %H:%M:%S', + timer_config=None): + """ + 创建Logger + + Args: + log_level: 日志等级 + logger_name: Logger_Name,默认root + log_file_folder: 日志存储路径 + fmt: 日志输出格式 + date_fmt: 时间格式 + timer_config: Timer配置 + + Returns:Logger + + """ + if timer_config is None: + timer_config = dict(when="D", interval=1, backupCount=0) + if logger_name: + logger = logging.getLogger(logger_name) + else: + logger = logging.getLogger() + loglevel = log_level.upper() + if loglevel in ["CRITICAL", "FATAL"]: + loggerlevel = logging.CRITICAL + elif loglevel == "ERROR": + loggerlevel = logging.ERROR + elif loglevel == "INFO": + loggerlevel = logging.INFO + elif loglevel in ["WARNING", "WARN"]: + loggerlevel = logging.WARNING + else: + loggerlevel = logging.DEBUG + logger.setLevel(loggerlevel) + # logger_format = logging.Formatter( + # fmt='%(asctime)s - %(name)s - %(levelname)-9s - %(filename)-8s : %(lineno)s line - %(message)s', + # datefmt='%Y-%m-%d %H:%M:%S') + logger_format = logging.Formatter( + fmt=fmt, + datefmt=date_fmt) + + timerhandler = TimedRotatingFileHandler(filename=_get_rootlog_filename(log_file_folder), + when=timer_config.get('when', 'D'), + interval=timer_config.get('interval', 1), + backupCount=timer_config.get('backupCount', 0), + encoding='utf-8') + timerhandler.setFormatter(logger_format) + + logger.addHandler(timerhandler) + + return logger + + +def _get_rootlog_filename(log_file_folder): + """自动生成日志文件名""" + # project_name = "log" + folder_format = time.strftime('%Y-%m', time.localtime(time.time())) + log_file_name = time.strftime('%Y-%m-%d', time.localtime(time.time())) + '.log' + # log_file_folder = os.path.abspath( + # os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) + os.sep + project_name + os.sep + folder_format + make_dir(log_file_folder) + log_file_str = log_file_folder + os.sep + log_file_name + return log_file_str + + +# def getQQlogger(): +# """已弃用的聊天记录日志记录器""" +# project_name = "qq-log" +# # log_file_folder = os.path.abspath( +# # os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) + os.sep + project_name + os.sep + folder_format +# +# log_file_folder = r'./qq-log' +# make_dir(log_file_folder) +# folder_format = time.strftime('%Y-%m', time.localtime(time.time())) +# log_file_name = time.strftime('%Y-%m-%d', time.localtime(time.time())) + '.log' +# log_file_str = log_file_folder + os.sep + log_file_name +# logger = logging.getLogger("qqlogger") +# logger.setLevel(20) +# logger_format = logging.Formatter(fmt='time="%(asctime)s" - level=%(levelname)s - %(message)s', +# datefmt='%Y-%m-%d %H:%M:%S') +# +# timerhandler = TimedRotatingFileHandler(filename=log_file_str, when="D", interval=1, backupCount=1, +# encoding='utf-8') +# timerhandler.setFormatter(logger_format) +# +# logger.addHandler(timerhandler) +# +# return logger + + +root_logger = create_logger(_cfg.get('loglevel', 'INFO')) +# QQ_logger = getQQlogger() +# 每隔 1000 Byte 划分一个日志文件,备份文件为 3 个 diff --git a/utils/MessageChainBuilder.py b/utils/MessageChainBuilder.py index 6ded721..fdb68dd 100644 --- a/utils/MessageChainBuilder.py +++ b/utils/MessageChainBuilder.py @@ -20,7 +20,8 @@ __all__ = ['messagechain_builder'] -async def messagechain_builder(reply_choices: list = None, text: str = None, imgpath: str = None, rndimg=False, +async def messagechain_builder(reply_choices: list = None, text: str = None, imgpath: Union[str, list] = None, + rndimg=False, imgurl: str = None, imgbase64=None, at: Union[list, int] = None, atall=False) -> MessageChain: """ @@ -63,15 +64,20 @@ async def messagechain_builder(reply_choices: list = None, text: str = None, img msgchain.append( await Image.from_local( filename=f"./data/reply/img/{replydata['replyimgpath']}/{random.choice(replydata['img'])}")) - if imgpath: - if reply_choices or text: - msgchain.append(Plain("\n")) - msgchain.append( - await Image.from_local(filename=f"{imgpath}")) if imgbase64: if reply_choices or text: msgchain.append(Plain("\n")) msgchain.append(Image(base64=imgbase64)) + if imgpath: + if reply_choices or text: + msgchain.append(Plain("\n")) + if isinstance(imgpath, str): + msgchain.append( + await Image.from_local(filename=f"{imgpath}")) + elif isinstance(imgpath, list): + for path in imgpath: + msgchain.append( + await Image.from_local(filename=f"{path}")) if imgurl: if reply_choices or text: msgchain.append(Plain("\n")) diff --git a/utils/MessageChainSender.py b/utils/MessageChainSender.py index c2c652e..0bae738 100644 --- a/utils/MessageChainSender.py +++ b/utils/MessageChainSender.py @@ -3,9 +3,8 @@ :Create: 2022/8/16 16:15 :Update: / :Describe: 消息链发送工具 -:Version: 0.0.1 +:Version: 0.0.2 """ -import logging import time import traceback from typing import Union @@ -27,7 +26,7 @@ async def messagechain_sender(msg: Union[MessageChain, str, MessageComponent], e grouptarget: int = None, friendtarget: int = None, errortext: str = None) -> int: """ 消息链发送工具\n - event,grouptarget,friendtarget三者有一个就行 + event,grouptarget,friendtarget三者有一个就行\n Args: msg: 消息,可以是字符串、消息组件、消息链 @@ -58,9 +57,9 @@ async def messagechain_sender(msg: Union[MessageChain, str, MessageComponent], e onlyImg = True try: if event: - if isinstance(event,GroupMessage): + if isinstance(event, GroupMessage): grouptarget = event.group.id - elif isinstance(event,FriendMessage): + elif isinstance(event, FriendMessage): friendtarget = event.sender.id # res = await bot.send(event, msg) # target = event @@ -94,7 +93,8 @@ async def messagechain_sender(msg: Union[MessageChain, str, MessageComponent], e elif event: await bot.send(event, await messagechain_builder(text=imgSendErrText, rndimg=True)) elif friendtarget: - await bot.send_friend_message(friendtarget, await messagechain_builder(text=imgSendErrText, rndimg=True)) + await bot.send_friend_message(friendtarget, + await messagechain_builder(text=imgSendErrText, rndimg=True)) except mirai.exceptions.ApiError as _e: # 消息发送失败时,进行日志记录,并尝试告诉机器人主人,每次发送CD 3600 s nowtime = int(time.time()) @@ -103,19 +103,19 @@ async def messagechain_sender(msg: Union[MessageChain, str, MessageComponent], e if nowtime - last_time > 3600: _last_error_message['groupmessage'] = dict(time=nowtime, target=target, message=msg, error='Bot被禁言') - await bot.send_friend_message(master, f"在{target.group.id}群消息发送失败,疑似被禁言") - print('Bot被禁言') - root_logger.error('Bot发送消息失败,Bot被禁言') + await bot.send_friend_message(master, f"向 {target} 发送消息失败,可能被禁言") + print(f"向 {target} 发送消息失败,可能被禁言") + root_logger.error(f"向 {target} 发送消息失败,可能被禁言") else: if nowtime - last_time > 3600: _last_error_message['groupmessage'] = dict(time=nowtime, target=target, message=msg, error=_e) - await bot.send_friend_message(master, f"群消息发送失败,可能被群消息风\n{_e}控") + await bot.send_friend_message(master, f"群消息发送失败,可能被群消息风控\n{_e}") print(f'Bot发送消息失败,MiraI错误码{_e}') root_logger.error(f'Bot发送消息失败,Mirai错误码{_e}') res = -1 except Exception as _e: traceback.print_exc() - logging.error(f'出现未知错误:{_e}') + root_logger.error(f'出现未知错误:{_e}') nowtime = int(time.time()) last_time = _last_error_message.get('groupmessage').get('time', 0) if nowtime - last_time > 3600: diff --git a/utils/echarts.py b/utils/echarts.py index 6fa3fa0..ac77246 100644 --- a/utils/echarts.py +++ b/utils/echarts.py @@ -1,15 +1,14 @@ +import os + +from pyecharts import options as opts +from pyecharts.charts import Bar, Line from pyecharts.faker import Faker from pyecharts.globals import ThemeType from pyecharts.render import make_snapshot from snapshot_selenium import snapshot -from pyecharts import options as opts -from pyecharts.charts import Sankey, Bar, Line - -import os - -def create_bar_chart(filename:str,x_data,y_data): +def create_bar_chart(filename: str, x_data, y_data): b = Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT)) \ .add_xaxis(Faker.days_attrs) \ .add_yaxis("商家1", Faker.days_values, color=Faker.rand_color()) \ @@ -17,6 +16,14 @@ def create_bar_chart(filename:str,x_data,y_data): title_opts=opts.TitleOpts(title="对局图表"), datazoom_opts=opts.DataZoomOpts(orient="vertical"), ) + l1 = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期七', '星期日'] + l2 = [100, 200, 300, 400, 500, 400, 300] + bar = ( + Bar() + .add_xaxis(l1) + .add_yaxis("l2", l2, category_gap=0, color='#FFFF00') + .set_global_opts(title_opts=opts.TitleOpts(title="Bar-基本示例", subtitle="我是副标题")) + ) # sankey = Sankey( # init_opts=opts.InitOpts( @@ -38,9 +45,10 @@ def create_bar_chart(filename:str,x_data,y_data): # .render("Hourly data volumn.html") # print(":".join(["CSDN叶庭云", "https://yetingyun.blog.csdn.net/"])) # sankey.render("./results/009.html") - make_snapshot(snapshot, b.render(), "Pyecharts生成图片.png") + make_snapshot(snapshot, b.render(), "Pyecharts生成条形图.png") return + def create_charts_from_option(option: dict, filename: str) -> dict: result = {'success': True} title = option.get("title") @@ -48,22 +56,205 @@ def create_charts_from_option(option: dict, filename: str) -> dict: return result -def majsoul_lines(filename="xyshu的2023-9的雀魂图表", x_data="", y_data="",timecross="2022-2"): - x = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期七', '星期日'] - y1 = [100, 200, 300, 400, 100, 400, 300] - y2 = [200, 300, 200, 100, -200, 300, 400] +def majsoul_bar(filename: str, x_data: list, y1_data: list, timecross="2022-2"): + y1_data.reverse() + y2_data = [] + newy1 = [] + for value in y1_data: + if value < 0: + y2_data.append(f'{value}') + newy1.append(None) + else: + y2_data.append(None) + newy1.append(value) + y1_data = newy1 + bar = ( + Bar(init_opts=opts.InitOpts(bg_color='rgba(255,255,255,1)')) + .add_xaxis(x_data) + # .add_yaxis("PT得失", y1_data, category_gap=0, color='#FF0000') + .add_yaxis("PT增加", y1_data, stack='1', color='#28a745') + .add_yaxis("PT减少", y2_data, stack='1', color='#dc3545') + .set_global_opts(title_opts=opts.TitleOpts(title=filename, subtitle=timecross)) + .set_series_opts(label_opts=opts.LabelOpts(is_show=True if len(x_data) < 40 else False), + markpoint_opts=opts.MarkPointOpts( + data=[ + opts.MarkPointItem(type_="min", name="最小值"), + opts.MarkPointItem(type_="max", name="最大值")]) + ) + + ) + make_snapshot(snapshot, bar.render(f"{filename}.html"), f"images/MajSoulInfo/{filename}.png") + # make_snapshot(snapshot, bar.render(f"{filename}.html"), f"{filename}.png") + os.remove(f'{filename}.html') + return + + +def majsoul_line(filename: str, x_data: list, y1_data: list, y2_data: list = None, timecross="2022-2"): + # x = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期七', '星期日'] + # print(x_data) + # print(y1_data) + # y1 = [100, 200, 300, 400, 100, 400, 300] + # y2 = [200, 300, 200, 100, -200, 300, 400] + # y1_data.reverse() + newy1 = [] + sum_score = 0 + for value in y1_data: + sum_score += value + newy1.append(sum_score) + y1_data = newy1 line = ( - Line() - .add_xaxis(xaxis_data=x) - .add_yaxis(series_name="y1线", y_axis=y1, areastyle_opts=opts.AreaStyleOpts(opacity=0.5)) - .add_yaxis(series_name="y2线", y_axis=y2, areastyle_opts=opts.AreaStyleOpts(opacity=0.5)) + # Line(init_opts=opts.InitOpts(bg_color='rgba(255,250,205,0.2)')) + Line(init_opts=opts.InitOpts(bg_color='rgba(255,255,255,1)')) + .add_xaxis(xaxis_data=x_data) + .add_yaxis(series_name="PT变化", y_axis=y1_data, areastyle_opts=opts.AreaStyleOpts(opacity=0.5)) .set_global_opts( - title_opts=opts.TitleOpts(title=filename, subtitle=timecross), - tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross") + title_opts=opts.TitleOpts(title=filename, subtitle=timecross), + tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross") + # ,visualmap_opts=opts.VisualMapOpts( + # is_piecewise=True, + # dimension=0, + # pieces=[ + # {"lte": 6, "color": "green"}, + # {"gt": 6, "lte": 8, "color": "red"}, + # {"gt": 8, "lte": 14, "color": "yellow"}, + # {"gt": 14, "lte": 17, "color": "red"}, + # {"gt": 17, "color": "green"}, + # ], + # pos_right=0, + # pos_bottom=100 + # ) ) + .set_series_opts(label_opts=opts.LabelOpts(is_show=True if len(x_data) < 40 else False), + markpoint_opts=opts.MarkPointOpts( + data=[ + opts.MarkPointItem(type_="min", name="最小值"), + opts.MarkPointItem(type_="max", name="最大值")]) + ) + # .set_series_opts( + # markarea_opts=opts.MarkAreaOpts( + # data=[ + # opts.MarkAreaItem(name="4", x=("1", "5")), + # opts.MarkAreaItem(name="1", x=("4", "5")), + # ] + # ) + # ) ) - make_snapshot(snapshot, line.render(f"{filename}.html"),f"{filename}.png") + make_snapshot(snapshot, line.render(f"{filename}.html"), f"images/MajSoulInfo/{filename}.png") + # make_snapshot(snapshot, line.render(f"{filename}.html"), f"{filename}.png") os.remove(f'{filename}.html') return -majsoul_lines() + +def tenhou_bar(filename: str, x_data: list, y1_data: list, timecross="2022-2"): + y2_data = [] + newy1 = [] + for value in y1_data: + if value < 0: + y2_data.append(f'{value}') + newy1.append(None) + else: + y2_data.append(None) + newy1.append(value) + y1_data = newy1 + bar = ( + Bar(init_opts=opts.InitOpts(bg_color='rgba(255,255,255,1)')) + .add_xaxis(x_data) + # .add_yaxis("PT得失", y1_data, category_gap=0, color='#FF0000') + .add_yaxis("PT增加", y1_data, stack='1', color='#28a745') + .add_yaxis("PT减少", y2_data, stack='1', color='#dc3545') + .set_global_opts(title_opts=opts.TitleOpts(title=filename, subtitle=timecross)) + .set_series_opts(label_opts=opts.LabelOpts(is_show=True if len(x_data) < 40 else False), + markpoint_opts=opts.MarkPointOpts( + data=[ + opts.MarkPointItem(type_="min", name="最小值"), + opts.MarkPointItem(type_="max", name="最大值")]) + ) + + ) + make_snapshot(snapshot, bar.render(f"{filename}.html"), f"images/MajSoulInfo/{filename}.png") + # make_snapshot(snapshot, bar.render(f"{filename}.html"), f"{filename}.png") + os.remove(f'{filename}.html') + return + + +def tenhou_line(filename: str, x_data: list, y1_data: list, y2_data: list = None, timecross="2022-2"): + # x = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期七', '星期日'] + # print(x_data) + # print(y1_data) + # y1 = [100, 200, 300, 400, 100, 400, 300] + # y2 = [200, 300, 200, 100, -200, 300, 400] + # y1_data.reverse() + newy1 = [] + sum_score = 0 + for value in y1_data: + sum_score += value + newy1.append(sum_score) + y1_data = newy1 + line = ( + # Line(init_opts=opts.InitOpts(bg_color='rgba(255,250,205,0.2)')) + Line(init_opts=opts.InitOpts(bg_color='rgba(255,255,255,1)')) + .add_xaxis(xaxis_data=x_data) + .add_yaxis(series_name="PT变化", y_axis=y1_data, areastyle_opts=opts.AreaStyleOpts(opacity=0.5)) + .set_global_opts( + title_opts=opts.TitleOpts(title=filename, subtitle=timecross), + tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross") + # ,visualmap_opts=opts.VisualMapOpts( + # is_piecewise=True, + # dimension=0, + # pieces=[ + # {"lte": 6, "color": "green"}, + # {"gt": 6, "lte": 8, "color": "red"}, + # {"gt": 8, "lte": 14, "color": "yellow"}, + # {"gt": 14, "lte": 17, "color": "red"}, + # {"gt": 17, "color": "green"}, + # ], + # pos_right=0, + # pos_bottom=100 + # ) + ) + .set_series_opts(label_opts=opts.LabelOpts(is_show=True if len(x_data) < 40 else False), + markpoint_opts=opts.MarkPointOpts( + data=[ + opts.MarkPointItem(type_="min", name="最小值"), + opts.MarkPointItem(type_="max", name="最大值")]) + ) + # .set_series_opts( + # markarea_opts=opts.MarkAreaOpts( + # data=[ + # opts.MarkAreaItem(name="4", x=("1", "5")), + # opts.MarkAreaItem(name="1", x=("4", "5")), + # ] + # ) + # ) + ) + make_snapshot(snapshot, line.render(f"{filename}.html"), f"images/MajSoulInfo/{filename}.png") + # make_snapshot(snapshot, line.render(f"{filename}.html"), f"{filename}.png") + os.remove(f'{filename}.html') + return + + + +# 下 inforesponse +# """{'count': 104, '和牌率': 0.3173076923076923, '自摸率': 0.45454545454545453, '默听率': 0.030303030303030304, '放铳率': 0.18269230769230768, '副露率': 0.34615384615384615, '立直率': 0.3173076923076923, '平均打点': 9348, '最大连庄': 2, '和了巡数': 11.151515151515152, '平均铳点': 8663, '流局率': 0.14423076923076922, '流听率': 0.6666666666666666, '一发率': 0.058823529411764705, '里宝率': 0.5294117647058824, '被炸率': 0.16666666666666666, '平均被炸点数': 9150, '放铳时立直率': 0.2631578947368421, '放铳时副露率': 0.3684210526315789, '立直后放铳率': 0.15151515151515152, '立直后非瞬间放铳率': 0.09090909090909091, '副露后放铳率': 0.19444444444444445, '立直后和牌率': 0.5151515151515151, '副露后和牌率': 0.4166666666666667, '立直后流局率': 0.18181818181818182, '副露后流局率': 0.1111111111111111, '放铳至立直': 7, '放铳至副露': 9, '放铳至默听': 3, '立直和了': 17, '副露和了': 15, '默听和了': 1, '立直巡目': 8.91919191919192, '立直收支': 4109, '立直收入': 10335, ' 立直支出': 8420, '先制率': 0.7575757575757576, '追立率': 0.24242424242424243, '被追率': 0.15151515151515152, '振听立直率': 0, '立直好型': 0.8181818181818182, '立直多面': 0.8181818181818182, '立直好型2': 0.48484848484848486, '最大累计番数': 10, '打点效率': 2966, '铳点损失': 1583, '净打点效率': 1384, '平均起手向听': 3.298076923076923, '平均起手向听亲': 3.0588235294117645, '平均起手向听子': 3.414285714285714, '最近大铳': {'id': '220905-2f058eef-7e52-425a-9bdf-30b279bc7c38', 'start_time': 1662348873, 'fans': [{'id': 29, 'label': '清一色', 'count': 6, '役满': 0}, {'id': 31, 'label': '宝牌', 'count': 2, '役满': 0}, {'id': 32, 'label': '红宝牌', 'count': 1, '役满': 0}]}, 'id': 1056373, 'played_modes': [23]}""" +# data = '''[{'_id': '8cjC7rEJRHY', 'modeId': 11, 'uuid': '230530-a01bcd14-24f1-4723-837a-f313168f85ba', 'startTime': 1685384713, 'endTime': 1685386444, 'players': [{'accountId': 1096838, 'nickname': '二次元給爺爬', 'level': 10401, 'score': 3600, 'gradingScore': -116}, {'accountId': 12768618, 'nickname': 'Ming789', 'level': 10502, 'score': 21900, 'gradingScore': -8}, {'accountId': 228839, 'nickname': '小真帆', 'level': 10501, 'score': 30300, 'gradingScore': 41}, {'accountId': 69615865, 'nickname': 'Elsodia', 'level': 10503, 'score': 44200, 'gradingScore': 90}]}, {'_id': '8ciGKHhiqTg', 'modeId': 11, 'uuid': '230529-765f5030-5543-48e6-aa84-f5cd16740724', 'startTime': 1685337321, 'endTime': 1685338244, 'players': [{'accountId': 67345411, 'nickname': '_みみお', 'level': 10401, 'score': 18200, 'gradingScore': -101}, {'accountId': 107400096, 'nickname': '奇襲に強い陰獣', 'level': 10502, 'score': 19700, 'gradingScore': -10}, {'accountId': 1096838, 'nickname': '二次元給爺爬', 'level': 10401, 'score': 29000, 'gradingScore': 39}, {'accountId': 72475395, 'nickname': 'がるむちゃん', 'level': 10401, 'score': 33100, 'gradingScore': 79}]}, {'_id': '8cgVrn9TfEV', 'modeId': 11, 'uuid': '230528-26f4036f-72b3-4cb5-876f-28a01716f883', 'startTime': 1685248391, 'endTime': 1685249816, 'players': [{'accountId': 67113774, 'nickname': 'lロックl', 'level': 10402, 'score': 18800, 'gradingScore': -111}, {'accountId': 74285568, 'nickname': 'いくもん', 'level': 10401, 'score': 19500, 'gradingScore': -10}, {'accountId': 68576962, 'nickname': '農家の次男', 'level': 10401, 'score': 27400, 'gradingScore': 38}, {'accountId': 1096838, 'nickname': '二次元給爺爬', 'level': 10401, 'score': 34300, 'gradingScore': 80}]}, {'_id': '8cezLzkUyPO', 'modeId': 11, 'uuid': '230527-4dbd1626-1d74-461e-98d3-51497cb56ec5', 'startTime': 1685170896, 'endTime': 1685172516, 'players': [{'accountId': 1096838, 'nickname': '二次元給爺爬', 'level': 10401, 'score': 11000, 'gradingScore': -109}, {'accountId': 8926230, 'nickname': '皮龘龘', 'level': 10501, 'score': 24800, 'gradingScore': -5}, {'accountId': 59422, 'nickname': '鬼畜天丶使', 'level': 10403, 'score': 29000, 'gradingScore': 39}, {'accountId': 11111922, 'nickname': '一直输怎么办', 'level': 10401, 'score': 35200, 'gradingScore': 81}]}, {'_id': '8cdyARRGru7', 'modeId': 11, 'uuid': '230527-4e0cdabb-9723-45ba-a3ea-419c3366a285', 'startTime': 1685119087, 'endTime': 1685119953, 'players': [{'accountId': 72602862, 'nickname': 'のどぼと毛', 'level': 10502, 'score': 16300, 'gradingScore': -143}, {'accountId': 13916168, 'nickname': '凜喵嗚', 'level': 10401, 'score': 24600, 'gradingScore': -5}, {'accountId': 107350459, 'nickname': 'ねんねこねご', 'level': 10401, 'score': 24900, 'gradingScore': 35}, {'accountId': 1096838, 'nickname': '二次元給爺爬', 'level': 10401, 'score': 34200, 'gradingScore': 80}]}, {'_id': '8cc8ypwPAuV', 'modeId': 11, 'uuid': '230525-a2e97c4f-52c8-4b47-98aa-57b84d0a86b6', 'startTime': 1685026280, 'endTime': 1685027429, 'players': [{'accountId': 74608749, 'nickname': 'Hawkiwi', 'level': 10401, 'score': 18400, 'gradingScore': -101}, {'accountId': 74784302, 'nickname': ' チキモフ', 'level': 10403, 'score': 21000, 'gradingScore': -9}, {'accountId': 1096838, 'nickname': '二次元給爺爬', 'level': 10401, 'score': 26900, 'gradingScore': 37}, {'accountId': 67664246, 'nickname': 'bishabisha', 'level': 10401, 'score': 33700, 'gradingScore': 79}]}, {'_id': '8caYv2wQnQV', 'modeId': 11, 'uuid': '230525-68fd73ff-9922-4f85-9848-1ae0b74bb84c', 'startTime': 1684945876, 'endTime': 1684947252, 'players': [{'accountId': 1096838, 'nickname': '二次元給爺爬', 'level': 10401, 'score': 6300, 'gradingScore': -113}, {'accountId': 74466352, 'nickname': 'myz2', 'level': 10403, 'score': 24800, 'gradingScore': -5}, {'accountId': 71054923, 'nickname': 'パール真珠', 'level': 10401, 'score': 27500, 'gradingScore': 38}, {'accountId': 73285256, 'nickname': 'ミルモでチー', 'level': 10401, 'score': 41400, 'gradingScore': 87}]}, {'_id': '8ca9fR6KWvQ', 'modeId': 11, 'uuid': '230524-78a15088-a700-41d7-9c81-a526469f1bb8', 'startTime': 1684925171, 'endTime': 1684926066, 'players': [{'accountId': 15651430, 'nickname': '在、也不见', 'level': 10501, 'score': 21100, 'gradingScore': -8}, {'accountId': 74041972, 'nickname': 'pazikami', 'level': 10402, 'score': 21100, 'gradingScore': -108}, {'accountId': 73956952, 'nickname': 'ぐで。', 'level': 10401, 'score': 25800, 'gradingScore': 36}, {'accountId': 1096838, 'nickname': '二次元給爺爬', 'level': 10401, 'score': 32000, 'gradingScore': 77}]}, {'_id': '8cYvV3FVWuO', 'modeId': 11, 'uuid': '230524-b5ef7000-766d-4607-a9f9-7cc1d3e34092', 'startTime': 1684862718, 'endTime': 1684863423, 'players': [{'accountId': 105946548, 'nickname': 'Aoxys', 'level': 10401, 'score': 6000, 'gradingScore': -114}, {'accountId': 100914807, 'nickname': 'Decelerator', 'level': 10401, 'score': 26700, 'gradingScore': -3}, {'accountId': 107011269, 'nickname': 'ひよQ', 'level': 10402, 'score': 31300, 'gradingScore': 42}, {'accountId': 1096838, 'nickname': '二次元給爺爬', 'level': 10401, 'score': 36000, 'gradingScore': 81}]}, {'_id': '8cYG0uUXHlP', 'modeId': 11, 'uuid': '230523-90e3e597-e041-45d4-86e4-a2bb046c8b74', 'startTime': 1684828702, 'endTime': 1684830206, 'players': [{'accountId': 68608894, 'nickname': 'Torank', 'level': 10401, 'score': 18500, 'gradingScore': -101}, {'accountId': 75316973, 'nickname': 'まいのりてぃー', 'level': 10501, 'score': 21800, 'gradingScore': -8}, {'accountId': 12947397, 'nickname': '憨憨空板鸭', 'level': 10502, 'score': 25700, 'gradingScore': 36}, {'accountId': 1096838, 'nickname': '二次元給爺爬', 'level': 10401, 'score': 34000, 'gradingScore': 79}]}, {'_id': '8cWHvMqCzFB', 'modeId': 11, 'uuid': '230522-9be68d81-bbda-4d6e-8e53-439c14ce1641', 'startTime': 1684728596, 'endTime': 1684729295, 'players': [{'accountId': 68091759, 'nickname': 'shabomb', 'level': 10403, 'score': 14400, 'gradingScore': -125}, {'accountId': 70346241, 'nickname': 'マーミット', 'level': 10402, 'score': 23000, 'gradingScore': -7}, {'accountId': 74780152, 'nickname': 'りつたろう', 'level': 10401, 'score': 29000, 'gradingScore': 39}, {'accountId': 1096838, 'nickname': '二次元給爺爬', 'level': 10401, 'score': 33600, 'gradingScore': 79}]}, {'_id': '8cWGrEXse0u', 'modeId': 11, 'uuid': '230522-0017d2b8-de01-424c-98cf-164ae9b59f61', 'startTime': 1684727722, 'endTime': 1684728371, 'players': [{'accountId': 67412541, 'nickname': 'たったです', 'level': 10403, 'score': 12400, 'gradingScore': -127}, {'accountId': 72013153, 'nickname': 'えんぱす', 'level': 10402, 'score': 18700, 'gradingScore': -11}, {'accountId': 11783486, 'nickname': '終世のリコリス', 'level': 10401, 'score': 23000, 'gradingScore': 33}, {'accountId': 1096838, 'nickname': ' 二次元給爺爬', 'level': 10401, 'score': 45900, 'gradingScore': 91}]}, {'_id': '8cUzzpydZHJ', 'modeId': 11, 'uuid': '230521-8a1ca1a5-4849-4906-809c-facc7ddb4d59', 'startTime': 1684663060, 'endTime': 1684663727, 'players': [{'accountId': 16655447, 'nickname': '朔罗雨夜', 'level': 10402, 'score': 12600, 'gradingScore': -117}, {'accountId': 1096838, 'nickname': '二次元給爺爬', 'level': 10401, 'score': 25500, 'gradingScore': -4}, {'accountId': 16698359, 'nickname': '若不辞', 'level': 10401, 'score': 27000, 'gradingScore': 37}, {'accountId': 12242166, 'nickname': '寶馒头', 'level': 10401, 'score': 34900, 'gradingScore': 80}]}]''' +# data = eval(data) +# # print(data) +# length = len(data) +# xdata = [f'{i + 1}' for i in range(length)] +# ydata = [] +# for d in data: +# player = d.get("players") +# # print(player) +# for p in player: +# if p.get("accountId") == 1096838: +# ydata.append(p.get("gradingScore")) +# # print(p.get("gradingScore")) +# # break +# # +# majsoul_line(filename='二次元給爺爬最近一个月的折线图表', x_data=xdata, y1_data=ydata, timecross="最近一个月") +# majsoul_bar(filename='二次元給爺爬最近一个月的柱状图表', x_data=xdata, y1_data=ydata, timecross="最近一个月") +# # # print(player) +# # # print(data) +# # # majsoul_lines() +# # +# # # await getmonthreport() diff --git a/utils/file_cleaner.py b/utils/file_cleaner.py index 06581c7..2894358 100644 --- a/utils/file_cleaner.py +++ b/utils/file_cleaner.py @@ -64,6 +64,7 @@ def list_allfile(path, all_files=None): return all_files -_folders = read_file(r'./config/config.yml').get('trash_folders', []) +# _folders = read_file(r'./config/config.yml').get('trash_folders', []) +_folders = read_file(r'./images') cleaner = FileCleaner(_folders)