| @ -0,0 +1,175 @@ | |||||||
|  | from flask import Flask,render_template,request,redirect | ||||||
|  | from flask_sqlalchemy import SQLAlchemy | ||||||
|  | from sqlalchemy import func | ||||||
|  | 
 | ||||||
|  | app = Flask(__name__) | ||||||
|  | app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:265679@127.0.0.1:3306/pandemic' | ||||||
|  | db=SQLAlchemy(app) | ||||||
|  | 
 | ||||||
|  | class China(db.Model): | ||||||
|  |     date=db.Column(db.Date,primary_key=True) | ||||||
|  |     total_confirmed=db.Column(db.Integer,nullable=False) | ||||||
|  |     new_confirmed=db.Column(db.Integer,nullable=False) | ||||||
|  |     active_cases=db.Column(db.Integer,nullable=False) | ||||||
|  |     imported_cases=db.Column(db.Integer,nullable=False) | ||||||
|  |     # symptomless_cases=db.Column(db.Integer,nullable=False) | ||||||
|  |     recovered=db.Column(db.Integer,nullable=False) | ||||||
|  |     new_recovered=db.Column(db.Integer,nullable=False) | ||||||
|  |     deaths=db.Column(db.Integer,nullable=False) | ||||||
|  |     new_deaths=db.Column(db.Integer,nullable=False) | ||||||
|  | #创建世界的疫情数据表 | ||||||
|  | class World(db.Model): | ||||||
|  |     date=db.Column(db.String(255),primary_key=True) | ||||||
|  |     country=db.Column(db.String(255),primary_key=True) | ||||||
|  |     country_name=db.Column(db.String(255)) | ||||||
|  |     region=db.Column(db.String(255)) | ||||||
|  |     deaths=db.Column(db.Integer,nullable=False) | ||||||
|  |     cumulative_deaths=db.Column(db.Integer,nullable=False) | ||||||
|  |     confirmed=db.Column(db.Integer,nullable=False) | ||||||
|  |     cumlative_confirmed=db.Column(db.Integer,nullable=False) | ||||||
|  | #创建中国省份的相关信息表 | ||||||
|  | class provinces_info(db.Model): | ||||||
|  |     province_name=db.Column(db.String(50),primary_key=True) | ||||||
|  | ##创建市的信息表(省市的从属关系) | ||||||
|  | class cities_info(db.Model): | ||||||
|  |     city_name=db.Column(db.String(50),primary_key=True) | ||||||
|  |     province_name=db.Column(db.String(50),db.ForeignKey('provinces_info.province_name')) | ||||||
|  | #创建区的相关信息,包含区和市的从属关系 | ||||||
|  | class districts_info(db.Model): | ||||||
|  |     district_name=db.Column(db.String(50),primary_key=True) | ||||||
|  |     city_name=db.Column(db.String(50),db.ForeignKey('cities_info.city_name')) | ||||||
|  |     provinces_name=db.Column(db.String(50),db.ForeignKey('provinces_info.province_name')) | ||||||
|  | #创建武汉病区的相关信息 | ||||||
|  | class community_info(db.Model): | ||||||
|  |     id=db.Column(db.Integer,primary_key=True,autoincrement=True) | ||||||
|  |     district_name=db.Column(db.String(50),db.ForeignKey('districts_info.district_name')) | ||||||
|  |     address=db.Column(db.String(50)) | ||||||
|  | #创建医院的相关信息 | ||||||
|  | class hospitals_info(db.Model): | ||||||
|  |     hospital_name=db.Column(db.String(50),primary_key=True) | ||||||
|  |     district_name=db.Column(db.String(50),db.ForeignKey('districts_info.district_name')) | ||||||
|  |     capacity=db.Column(db.Integer) | ||||||
|  |     test=db.Column(db.Integer) | ||||||
|  |     confirmed = db.Column(db.Integer) | ||||||
|  |     rate=db.Column(db.Float) | ||||||
|  | class patients_info(db.Model): | ||||||
|  |     id=db.Column(db.Integer,primary_key=True,autoincrement=True) | ||||||
|  |     date=db.Column(db.Date) | ||||||
|  |     condition=db.Column(db.String(30)) | ||||||
|  |     district=db.Column(db.String(30)) | ||||||
|  | #创建省一级的疫情相关信息province_data | ||||||
|  | class province_data(db.Model): | ||||||
|  |     date = db.Column(db.Date, primary_key=True) | ||||||
|  |     # province_name = db.Column(db.String(50),db.ForeignKey('provinces_info.province_name'),primary_key=True) | ||||||
|  |     province_name = db.Column(db.String(50), primary_key=True) | ||||||
|  |     total_confirmed = db.Column(db.Integer, nullable=False) | ||||||
|  |     new_confirmed=db.Column(db.Integer, nullable=False) | ||||||
|  |     active_cases = db.Column(db.Integer, nullable=False) | ||||||
|  |     imported_cases = db.Column(db.Integer, nullable=False) | ||||||
|  |     # symptomless_cases = db.Column(db.Integer, nullable=False) | ||||||
|  |     recovered = db.Column(db.Integer, nullable=False) | ||||||
|  |     deaths = db.Column(db.Integer, nullable=False) | ||||||
|  | #创建市一级的疫情相关信息city_data | ||||||
|  | class city_data(db.Model): | ||||||
|  |     date = db.Column(db.Date, primary_key=True) | ||||||
|  |     # province_name = db.Column(db.String(50), db.ForeignKey('provinces_info.province_name')) | ||||||
|  |     # city_name = db.Column(db.String(50), db.ForeignKey('cities_info.city_name'),primary_key=True) | ||||||
|  |     province_name = db.Column(db.String(50),primary_key=True) | ||||||
|  |     city_name = db.Column(db.String(50),primary_key=True) | ||||||
|  |     total_confirmed = db.Column(db.Integer, nullable=False) | ||||||
|  |     active_cases = db.Column(db.Integer, nullable=False) | ||||||
|  |     recovered = db.Column(db.Integer, nullable=False) | ||||||
|  |     deaths = db.Column(db.Integer, nullable=False) | ||||||
|  | class wuhan_data(db.Model): | ||||||
|  |     date = db.Column(db.Date, primary_key=True) | ||||||
|  |     district = db.Column(db.String(50),primary_key=True) | ||||||
|  |     confirmed = db.Column(db.Integer, nullable=False) | ||||||
|  | # @app.route("/select") | ||||||
|  | # def selectAll(): | ||||||
|  | #     china = China.query.all() | ||||||
|  | #     return render_template("china.html",china = china) | ||||||
|  | 
 | ||||||
|  | @app.route('/') | ||||||
|  | def cover(): | ||||||
|  |     return render_template('cover.html') | ||||||
|  | 
 | ||||||
|  | @app.route("/china/") | ||||||
|  | def china(): | ||||||
|  |     china = China.query.order_by(China.date.desc()).all() | ||||||
|  |     return render_template("china.html",china = china) | ||||||
|  | 
 | ||||||
|  | @app.route("/province/") | ||||||
|  | def province(): | ||||||
|  |     date=request.args.get("date") | ||||||
|  |     pro=province_data.query.filter_by(date=date).order_by(province_data.total_confirmed.desc()).all() | ||||||
|  |     return render_template("province.html",pro = pro) | ||||||
|  | 
 | ||||||
|  | @app.route("/city/") | ||||||
|  | def city(): | ||||||
|  |     date = request.args.get("date") | ||||||
|  |     pro_name=request.args.get("pro_name") | ||||||
|  |     cit = city_data.query.filter_by(date=date,province_name=pro_name).order_by(city_data.total_confirmed.desc()).all() | ||||||
|  |     return render_template("city.html",cit = cit) | ||||||
|  | 
 | ||||||
|  | @app.route("/world/") | ||||||
|  | def world(): | ||||||
|  |     world =db.session.query(World.date, | ||||||
|  |                             func.sum(World.cumlative_confirmed), | ||||||
|  |                             func.sum(World.confirmed), | ||||||
|  |                             func.sum(World.cumulative_deaths), | ||||||
|  |                             func.sum(World.deaths),).group_by('date').order_by(World.date.desc()).all() | ||||||
|  |     return render_template("world.html",world=world) | ||||||
|  | 
 | ||||||
|  | @app.route("/region/") | ||||||
|  | def region(): | ||||||
|  |     date=request.args.get("date") | ||||||
|  |     reg =db.session.query(World.date, | ||||||
|  |                           World.region, | ||||||
|  |                           func.sum(World.cumlative_confirmed), | ||||||
|  |                           func.sum(World.confirmed), | ||||||
|  |                           func.sum(World.cumulative_deaths), | ||||||
|  |                           func.sum(World.deaths)).filter_by(date=date).group_by('region').all() | ||||||
|  |     return render_template("region.html",reg=reg) | ||||||
|  | 
 | ||||||
|  | @app.route("/country/") | ||||||
|  | def country(): | ||||||
|  |     date=request.args.get("date") | ||||||
|  |     region=request.args.get("region") | ||||||
|  |     coun =World.query.filter_by(date=date,region=region).order_by(World.cumlative_confirmed.desc()).all() | ||||||
|  |     return render_template("country.html",coun=coun) | ||||||
|  | @app.route("/hospitals/") | ||||||
|  | def hospitals(): | ||||||
|  |     hosp=hospitals_info.query.order_by(hospitals_info.capacity).all() | ||||||
|  |     return render_template("hospitals.html",hosp=hosp) | ||||||
|  | 
 | ||||||
|  | @app.route("/wuhan/") | ||||||
|  | def wuhan(): | ||||||
|  |     wu=wuhan_data.query.order_by(wuhan_data.date.desc()).all() | ||||||
|  |     return render_template("wuhan.html",wuhan=wu) | ||||||
|  | 
 | ||||||
|  | @app.route("/patients/") | ||||||
|  | def patients(): | ||||||
|  |     pat=db.session.query(patients_info.district, | ||||||
|  |                           patients_info.condition, | ||||||
|  |                           func.count(patients_info.id) | ||||||
|  |                          ).group_by('condition','district').order_by(patients_info.district.desc()).all() | ||||||
|  |     return render_template("patients.html",pat=pat) | ||||||
|  | 
 | ||||||
|  | @app.route("/patient_detail/") | ||||||
|  | def patient_detail(): | ||||||
|  |     district=request.args.get('district') | ||||||
|  |     condition=request.args.get('condition') | ||||||
|  |     pa = db.session.query(patients_info.date, | ||||||
|  |                           patients_info.district, | ||||||
|  |                            patients_info.condition, | ||||||
|  |                            func.count(patients_info.id) | ||||||
|  |                            ).filter_by(district=district,condition=condition)\ | ||||||
|  |         .group_by('date').order_by(patients_info.date.desc()).all() | ||||||
|  |     return render_template("patient_detail.html",pat=pa) | ||||||
|  | @app.route("/hospital_detail/") | ||||||
|  | def hospital_detail(): | ||||||
|  |     district=request.args.get('district') | ||||||
|  |     hosp = hospitals_info.query.filter_by(district_name=district).order_by(hospitals_info.district_name).all() | ||||||
|  |     return render_template("hospital_detail.html", hosp=hosp) | ||||||
|  | if __name__ == '__main__': | ||||||
|  |     app.run(debug=True) | ||||||
| After Width: | Height: | Size: 48 KiB | 
| After Width: | Height: | Size: 39 KiB | 
| After Width: | Height: | Size: 27 KiB | 
| After Width: | Height: | Size: 11 KiB | 
| After Width: | Height: | Size: 9.2 KiB | 
| After Width: | Height: | Size: 43 KiB | 
| After Width: | Height: | Size: 84 KiB | 
| @ -0,0 +1,35 @@ | |||||||
|  | <!DOCTYPE html> | ||||||
|  | <html lang="en"> | ||||||
|  | <head> | ||||||
|  |     <meta charset="UTF-8"> | ||||||
|  |     <title>疫情数据库大作业</title> | ||||||
|  |     <link rel="stylesheet" href="/static/layui/css/layui.css"> | ||||||
|  |     <style> | ||||||
|  |         a:link{ | ||||||
|  |             color: blue; | ||||||
|  |         } | ||||||
|  |         a:visited{ | ||||||
|  |             color: blue; | ||||||
|  |         } | ||||||
|  |         a:hover{ | ||||||
|  |             color: red; | ||||||
|  |         } | ||||||
|  |     </style> | ||||||
|  | </head> | ||||||
|  | <div align="center"> | ||||||
|  | <img src="../static/cover.jpg" width="640"height="230" alt="照片"/> | ||||||
|  | </div> | ||||||
|  | 
 | ||||||
|  | <body> | ||||||
|  | <div align="center"> | ||||||
|  |     <p><font size="5"> <a href="/china/">国内疫情</a></font></p> | ||||||
|  |     <p><font size="5"> <a href="/world/">国外疫情</a></font></p> | ||||||
|  |     <p><font size="5"> <a href="/wuhan/">武汉疫情</a></font></p> | ||||||
|  |     <div align="center"> | ||||||
|  |     <img src="../static/wuhan.jpg" width="640"height="200"alt="照片"/> | ||||||
|  |     </div> | ||||||
|  |     <p><font size="4"> <a href="hospitals">武汉医院信息</a></font></p> | ||||||
|  |     <p><font size="4"> <a href="patients">武汉病患信息</a></font></p> | ||||||
|  |     </div> | ||||||
|  | </body> | ||||||
|  | </html> | ||||||