@
John60676 这是我 views 代码的一部分 觉得问题应该就在这里
from app import app
from flask import render_template,request,flash,session
from .models import CostForm,dowmlist
import numpy as np
from flask import make_response
# 全局基础数据
Salary_Increase = 0.02 #工资涨幅,
Rate_Insurance = 0.48 #五险一金占年薪的百分比
Rate_Welfare = 0.06 #其他福利占年薪的百分比
Rate_CommonRepair = 0.55
Rate_BigRepair = 0.45
Rate_LineRepair = 0.5
Rate_StructureRepair = 0.2
Rate_DeviceRepair = 0.3
TrainPower = 1150 #列车额定功率,1150kw
Rate_power = 0.8 #功率利用率
Rate_water = 0.07
Rate_gas = 0.05
Rate_heat = 0.06
Rate_transport = 0.14
Rate_accident = 0.34
Rate_ticket = 0.25
Rate_clean = 0.11
Rate_ManagerSalary = 0.35
Rate_Active = 0.25
Rate_Travel = 0.3
Rate_Education = 0.1
# 存放提交的基础数据
datum={}
# 存放计算后的数据
LineLength = []
Flow = []
TrainCount = []
StaffCount = []
TrainRunKM = []
Salary = []
Total_Salary = []
TrainRepair = []
OtherRepair = []
Train_electric = []
Lighting_electric = []
Total_electric = []
Operation = []
Management = []
TotalCost = []
@
app.route('/')
def index():
k = request.remote_addr
m = request.user_agent
session['user'] = k+m.browser+m.platform+m.string+m.version
return render_template('Default.html')
@
app.route('/base')
def base():
return render_template('base.html')
@
app.route('/Input', methods=('GET', 'POST'))
def register():
form = CostForm()
if form.validate_on_submit():
flash("sucess")
# 其他数据
datum['Cal_year']=form.text_year.data
datum['Investment']=form.text_investment.data
datum['speed']=form.text_speed.data
datum['BaseSalary']=form.text_salary.data
datum['Price_TrainRepair']=form.text_trainRepair.data
datum['Price_OtherRepair']=form.text_repair.data
datum['Price_electric']=form.text_e_cost.data
datum['Price_Operation']=form.text_operation.data
datum['Rate_management']=form.text_management.data/100
for i in range(form.text_year.data):
if i<3:
LineLength.append(form.text_length1.data)
Flow.append((0.8 + i / 10)*form.text_flow1.data)
TrainCount.append((0.8 + i / 10) * form.text_train1.data)
StaffCount.append((0.8 + i / 10) * form.text_person1.data)
Lighting_electric.append(datum['Price_electric'] * (0.8 + i / 10) * form.text_e1.data)
elif 3<=i<10:
LineLength.append(form.text_length1.data)
Flow.append(form.text_flow1.data+(i - 2) * (form.text_flow2.data - form.text_flow1.data)/ 7)
TrainCount.append(form.text_train1.data+(i - 2) * (form.text_train2.data - form.text_train1.data)/ 7)
StaffCount.append(form.text_person1.data+(i - 2) * (form.text_person2.data - form.text_person1.data)/ 7)
Lighting_electric.append(datum['Price_electric'] *( form.text_e1.data + (i - 2) * (form.text_e2.data - form.text_e1.data) / 7))
elif 10<=i<25:
LineLength.append(form.text_length2.data)
Flow.append(form.text_flow2.data + (i - 9) * (form.text_flow3.data - form.text_flow2.data) /15)
TrainCount.append(form.text_train2.data + (i - 9) * (form.text_train3.data - form.text_train2.data)/15)
StaffCount.append(form.text_person2.data + (i - 9) * (form.text_person3.data - form.text_person2.data)/15)
Lighting_electric.append(datum['Price_electric']*(form.text_e2.data + (i - 9) * (form.text_e3.data - form.text_e2.data)/15))
else:
LineLength.append(form.text_length3.data)
Flow.append(form.text_flow3.data)
TrainCount.append(form.text_train3.data)
StaffCount.append(form.text_person3.data)
Lighting_electric.append(datum['Price_electric'] * form.text_e3.data)
TrainRunKM.append(LineLength[i] * TrainCount[i] * 2 * 365 * 1.1 / 10000)
Salary.append(LineLength[i] * StaffCount[i] * datum['BaseSalary'] * (1 + Salary_Increase)**i)
Total_Salary.append(round(Salary[i] * (1 + Rate_Insurance + Rate_Welfare),1))
TrainRepair.append(round(datum['Price_TrainRepair'] * TrainRunKM[i],1))
OtherRepair.append(round(datum['Price_OtherRepair'] * TrainRunKM[i],1))
# Train_electric[i] = datum['Price_electric'] * TrainPower * Rate_power * TrainRunKM[i] / datum['speed']
Train_electric.append(round(datum['Price_electric']* 5 * TrainRunKM[i],1))
Total_electric.append(round(Train_electric[i] + Lighting_electric[i],1))
Operation.append(round(datum['Price_Operation'] * TrainRunKM[i],1))
TotalCost.append(round((Total_Salary[i] + TrainRepair[i] + OtherRepair[i] + Total_electric[i] + Operation[
i]) / (1-datum['Rate_management']),1))
Management.append(round(datum['Rate_management'] * TotalCost[i],1))
# 添加跳转页面或者弹窗
return render_template('Input.html', form=form)
@
app.route('/simple')
def simple():
year=datum['Cal_year']
all_total_salary = round(sum(Total_Salary),1)
all_trainrepair = round(sum(TrainRepair),1)
all_otherrepair = round(sum(OtherRepair),1)
all_total_electric = round(sum(Total_electric),1)
all_operation = round(sum(Operation),1)
all_management = round(sum(Management),1)
all_totalcost = round(sum(TotalCost),1)
return render_template('simple.html', all_total_salary=all_total_salary,all_trainrepair=all_trainrepair,all_otherrepair=all_otherrepair,all_total_electric=all_total_electric,all_operation=all_operation,all_management=all_management,all_totalcost=all_totalcost,year=year,Total_Salary=Total_Salary,TrainRepair=TrainRepair,OtherRepair=OtherRepair,Total_electric=Total_electric,Operation=Operation,TotalCost=TotalCost,Management=Management)