|
|
|
@ -1,100 +1,14 @@
|
|
|
|
|
import os
|
|
|
|
|
import platform
|
|
|
|
|
from Text2Sql.Util.Text2SqlUtil import *
|
|
|
|
|
|
|
|
|
|
from Text2Sql.Util.PostgreSQLUtil import PostgreSQLUtil
|
|
|
|
|
from Text2Sql.Util.SaveToExcel import save_to_excel
|
|
|
|
|
from pyecharts.charts import Bar
|
|
|
|
|
from pyecharts import options as opts
|
|
|
|
|
from pyecharts.commons.utils import JsCode
|
|
|
|
|
import pandas as pd
|
|
|
|
|
import webbrowser
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process_data(raw_data):
|
|
|
|
|
"""
|
|
|
|
|
处理原始数据:
|
|
|
|
|
1. 过滤无效行政区
|
|
|
|
|
2. 按上传数量降序排序
|
|
|
|
|
3. 取前10名
|
|
|
|
|
"""
|
|
|
|
|
df = pd.DataFrame(raw_data)
|
|
|
|
|
df = df[df['行政区划名称'].notna() & (df['行政区划名称'] != '')]
|
|
|
|
|
df = df.sort_values('上传课程数量', ascending=False).head(10)
|
|
|
|
|
return df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_top10_chart(data):
|
|
|
|
|
# 准备数据
|
|
|
|
|
schools = data['学校名称'].tolist()
|
|
|
|
|
counts = data['上传课程数量'].tolist()
|
|
|
|
|
districts = data['行政区划名称'].tolist()
|
|
|
|
|
|
|
|
|
|
# 生成颜色渐变(从深到浅)
|
|
|
|
|
colors = [f"rgb({75 + i * 15}, {115 - i * 10}, {220 - i * 20})" for i in range(10)]
|
|
|
|
|
|
|
|
|
|
# 创建图表
|
|
|
|
|
bar = Bar(init_opts=opts.InitOpts(width='1200px', height='600px'))
|
|
|
|
|
bar.add_xaxis(schools)
|
|
|
|
|
bar.add_yaxis(
|
|
|
|
|
series_name="上传数量",
|
|
|
|
|
y_axis=counts,
|
|
|
|
|
itemstyle_opts=opts.ItemStyleOpts(color=JsCode(
|
|
|
|
|
"function(params){"
|
|
|
|
|
f" return {colors}[params.dataIndex];"
|
|
|
|
|
"}"
|
|
|
|
|
)),
|
|
|
|
|
label_opts=opts.LabelOpts(
|
|
|
|
|
position="right",
|
|
|
|
|
formatter=JsCode(
|
|
|
|
|
"function(params){"
|
|
|
|
|
" return params.value + ' (' + params.name.split('').join('\\n') + ')';"
|
|
|
|
|
"}"
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 全局配置
|
|
|
|
|
bar.set_global_opts(
|
|
|
|
|
title_opts=opts.TitleOpts(
|
|
|
|
|
title="上传资源数量TOP10学校排名",
|
|
|
|
|
subtitle="数据来源:课程资源管理系统"
|
|
|
|
|
),
|
|
|
|
|
tooltip_opts=opts.TooltipOpts(
|
|
|
|
|
formatter=JsCode(
|
|
|
|
|
"""function(params){
|
|
|
|
|
return params.name + '<br/>'
|
|
|
|
|
+ '所属行政区:' + %s[params.dataIndex] + '<br/>'
|
|
|
|
|
+ '上传数量:<b style="color:#5470C6">' + params.value + '</b>'
|
|
|
|
|
}""" % districts
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
xaxis_opts=opts.AxisOpts(
|
|
|
|
|
axislabel_opts=opts.LabelOpts(
|
|
|
|
|
rotate=30,
|
|
|
|
|
formatter=JsCode(
|
|
|
|
|
"function(value){"
|
|
|
|
|
" return value.length > 6 ? value.substring(0,6)+'...' : value;"
|
|
|
|
|
"}"
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
yaxis_opts=opts.AxisOpts(name="上传数量(件)"),
|
|
|
|
|
datazoom_opts=[opts.DataZoomOpts(type_="inside")],
|
|
|
|
|
visualmap_opts=opts.VisualMapOpts(
|
|
|
|
|
min_=min(counts),
|
|
|
|
|
max_=max(counts),
|
|
|
|
|
orient="horizontal",
|
|
|
|
|
pos_left="center",
|
|
|
|
|
range_color=["#91CC75", "#5470C6"]
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 反转Y轴使降序排列
|
|
|
|
|
bar.reversal_axis()
|
|
|
|
|
|
|
|
|
|
return bar
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from Text2Sql.Util.Text2SqlUtil import *
|
|
|
|
|
'''
|
|
|
|
|
经验:
|
|
|
|
|
1、尽量使用宽表,少用关联,越少越好
|
|
|
|
|
2、应该有一些固定的组合用法预置出来,给出范例,让用户可以简单修改后就能使用
|
|
|
|
|
3、应该有类似于 保存为用例,查询历史等功能,让用户方便利旧。
|
|
|
|
|
'''
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
vn = DeepSeekVanna()
|
|
|
|
|
|
|
|
|
|