安顺学院本科毕业论文(设计)题目申请表
院别:数学与计算机科学 专业:数据科学与大数据 时间:2022年 5月26日
安顺学院本科毕业论文(设计)开题报告
完成时间: 年 月 日
核心算法代码分享如下:
# coding=utf-8
import sys
import demjson
from tool import SqlHelper
"""
绘画动态国家线柱状图需要的数据
"""
# 定义结构
total_data = {}
def createJson(subject, scores):
# sql调用
sql = SqlHelper.MySQLhelper()
# 年份
years = []
# 查询年份
information = sql.fetch_all_args("select distinct year from stateline where subject = %s order by year", (subject))
for infor in information:
# 添加年份
years.append(str(infor['year']))
# 根据年份和类别查询分数
inforsA = sql.fetch_all_args("select * from stateline where subject = %s and year = %s and classifier = 'A类'",
("理学", infor['year']))
inforsB = sql.fetch_all_args("select * from stateline where subject = %s and year = %s and classifier = 'B类'",
("理学", infor['year']))
# 转换格式,添加列表
for inforA, inforB in zip(inforsA, inforsB):
datas = []
data = {}
daA = []
daB = []
daY = []
# 添加B类地区分数
daB.append(inforB['equal100'])
daB.append(inforB['greater100'])
daB.append(inforB['total'])
data['data'] = daB
datas.append(data)
data = {}
# 添加你输入的分数
daY.append(scores[0])
daY.append(scores[1])
daY.append(scores[2])
data['data'] = daY
datas.append(data)
data = {}
# 添加A类地区分数
daA.append(inforA['equal100'])
daA.append(inforA['greater100'])
daA.append(inforA['total'])
data['data'] = daA
datas.append(data)
# 添加分数数据
total_data['y' + str(infor['year'])] = datas
# 添加年份
total_data['years'] = years
# 添加专业
total_data['subject'] = subject
if __name__ == '__main__':
subject = sys.argv[1]
scores = demjson.decode(sys.argv[2])
# subject = '理学'
# scores = {'scores': [55,55,155]}
# 调用生成json函数
createJson(subject, scores['scores'])
print(total_data)