Use flask doing web analysis excel results

Technologies used: pyecharts flask

First pip install flask and download pip install pyecharts == 0.5.5

Project structure:

 

 

Code:

Import the Flask Flask from, the render_template 
App = the Flask (name__ __)
@ app.route ( '/')
DEF the hello_world ():
return the render_template ( 'the test.html')
@ app.route ( '/ AVG', Methods = [ 'the GET ',' POST '])
DEF avg_score ():
return render_template ( "different years overall grade point average case .html")
@ app.route (' / sex ')
DEF sex_score ():
return render_template ( "gender student achievement situation bar graph - line chart .html ")
@ app.route ( '/ MANY')
DEF many_score ():
return render_template (" a page rendering multiple chart .html ")
@ app.route ( '/ Bing')
DEF bing_score ():
return the render_template ( "pie .html")

IF the __name__ == '__main__':
app.run (Debug = True)
# Import module xlrd 
Import xlrd
from pyecharts Import *
page = Page () # class instantiates page, a page read sequence charts infection
# Set filename and path
fname = 'course grade .xlsx'
# open file
filename = xlrd.open_workbook ( fname)
sheets obtained sheet # = filename.nsheets number
sheet_list = filename.sheet_names () # sheet name
list_x = []
years = [ "2016", "2017", "2018"] # year
for i in range (len (sheet_list)):
ListX = [] # storage class
dirx = {} # storage class size
listy = [] # score stored
diry = {} # store statistics class score
sheet = filename.sheets () [i] # current obtained the sheet
nrows # = sheet.nrows obtain the current sheet number of rows
diravg = {} # average store
for J in Range (. 1, nrows):
row_datas = sheet.row_values (J) # get all the information of the current row
listx.append(row_datas[0])
listy.append(row_datas[4])
for k in range(len(listx)):
if listx[k] not in dirx:
dirx[listx[k]]=1
if "".join(listy[k].split())!='缺考':
diry[listx[k]]=int(listy[k])
else:
diry[listx[k]]=0
else:
dirx[listx[k]]=dirx[listx[k]]+1
if "".join(listy[k].split())!='缺考':
diry[listx[k]]=int(listy[k])+diry[listx[k]]
for d in dirx:
if d not in diravg:
diravg[d]="%.1f"%(diry.get(d)/dirx.get(d))
keys=list(diravg.keys())
values=list(diravg.values())
bar = Bar (years [i] + " performance analysis")
bar.add (years [i], Keys, values)
Page.add (bar)
page.render ( "../ Templates / a page rendering multiple charts. html ")
Screenshot:

 

# 导入xlrd模块
import xlrd
from pyecharts import Bar
#设置文件名和路径
fname = '课程成绩.xlsx'
# 打开文件
filename = xlrd.open_workbook(fname)
sheets=filename.nsheets#获得sheet的个数
sheet_list = filename.sheet_names()#sheet名字
avg=[]
for i in range(len(sheet_list)):#获取sheet个数
sheet=filename.sheets()[i]#获取当前的sheet
nrows=sheet.nrows#获取行数
sumscore=0#总分
count=0#学生的个数
for j in range(1,nrows):
row_datas = sheet.row_values(j)#获得当前行的所有信息
if "".join(row_datas[4].split())!='缺考':
count=count+1
sumscore+=int(row_datas[4])
avg.append("%.1f"%(sumscore/count))#存放保留一位小数的成绩
#print(avg)
years=['2016','2017','2018']#设计x坐标
bar=Bar("标题:不同年份总体平均成绩情况")#设置标题
#画图
bar.add("图注:平均成绩",years,avg, is_label_show=True)
bar.render("../templates/不同年份总体平均成绩情况.html")

 

 

 

import xlrd
from pyecharts import *
#设置文件名和路径
fname = '课程成绩.xlsx'
# 打开文件
filename = xlrd.open_workbook(fname)
page = Page() # 实例化page类,一个页面顺序熏染读个图表
sheets=filename.nsheets#获得sheet的个数
sheet_list = filename.sheet_names()#sheet名字
dirk={"不及格":0,"及格":0,'良好':0,'优秀':0}
years=["2016","2017","2018"]#年份
for i in range(len(sheet_list)):
sheet=filename.sheets()[i]#获取当前的sheet
nrows=sheet.nrows#获取行数
sumscore=0#总分
for j in range(1,nrows):
row_datas = sheet.row_values(j)#获得当前行的所有信息
if "".join(row_datas[4].split())!='缺考':
if int(row_datas[4])<60:
dirk["不及格"]=dirk.get("不及格")+1
elif 60<=int(row_datas[4])<70 :
dirk["及格"]=dirk.get("及格")+1
elif 70<=int(row_datas[4])<90 :
dirk["良好"]=dirk.get("良好")+1
else:
dirk["优秀"]=dirk.get("优秀")+1
pie = Pie(years[i]+"成绩等级分析")
listname=list(dirk.keys())
# print(listname)
attr = []
for i in listname:
attr.append(i)
values=[dirk.get("不及格"),dirk.get("及格"),dirk.get("良好"),dirk.get("优秀")]
pie.add("", attr, values, is_label_show=True)
page.add(pie)

page.render("../templates/饼图.html")




#
# attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
# v1 = [11, 12, 13, 10, 10, 10]
# pie = Pie("饼图示例")
# pie.add("", attr, v1, is_label_show=True)
# pie.render('pie.html')

Guess you like

Origin www.cnblogs.com/tangchenxian/p/12046313.html