53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
from file_define import FileReader, TextFileReader, JsonFileReader
|
|
from data_define import Record
|
|
from pyecharts.charts import Bar
|
|
from pyecharts.options import *
|
|
from pyecharts.globals import ThemeType
|
|
from pymysql import Connection
|
|
|
|
text_file_reader = TextFileReader("2011年1月销售数据.txt")
|
|
text_file_reader1 = JsonFileReader("2011年2月销售数据JSON.txt")
|
|
|
|
jan_data: list[Record] = text_file_reader.read_data()
|
|
feb_data: list[Record] = text_file_reader1.read_data()
|
|
|
|
# 将2个月数据合并为1个list存储
|
|
all_data: list[Record] = jan_data + feb_data
|
|
|
|
# # 开始进行数据计算
|
|
# data_dict = {}
|
|
# for record in all_data:
|
|
# if record.data in data_dict.keys():
|
|
# # 当前已有记录,与旧记录累加
|
|
# data_dict[record.data] += record.money
|
|
# else:
|
|
# data_dict[record.data] = record.money
|
|
#
|
|
# # 可视化图彪开发
|
|
# bar = Bar(init_opts=InitOpts(theme=ThemeType.LIGHT)) # 柱状图
|
|
# bar.add_xaxis(list(data_dict.keys()))
|
|
# bar.add_yaxis("销售额",list(data_dict.values()),label_opts=LabelOpts(is_show=False))
|
|
# bar.set_global_opts(
|
|
# title_opts=TitleOpts(title="每日销售额")
|
|
# )
|
|
# bar.render("每日销售额.html")
|
|
|
|
# 将数据写入到数据库中
|
|
conn = Connection(
|
|
host="localhost",
|
|
port=3306,
|
|
user="root",
|
|
password="123123",
|
|
autocommit=True
|
|
)
|
|
|
|
cursur = conn.cursor()
|
|
|
|
conn.select_db("py_sql")
|
|
|
|
for record in all_data:
|
|
sql=f"insert into orders(order_date,order_id,money,province) " \
|
|
f"values('{record.data}','{record.order_id}',{record.money},'{record.province}')"
|
|
cursur.execute(sql)
|
|
|
|
conn.close() |