-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
253 lines (169 loc) · 6.68 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
from flask import Flask,render_template,request
from flask import redirect
from flaskext.mysql import MySQL
from flask import json
from flask import jsonify, make_response
app = Flask(__name__)
mysql=MySQL()
app.config['MYSQL_DATABASE_HOST'] ='localhost'
app.config['MYSQL_DATABASE_PORT'] =3306
app.config['MYSQL_DATABASE_USER'] ='root'
app.config['MYSQL_DATABASE_PASSWORD'] =''
app.config['MYSQL_DATABASE_DB'] ='db_university'
mysql.init_app(app)
@app.route('/',methods=["GET"])
def index():
return render_template('index.html')
@app.route('/dashboard',methods=["GET"])
def dashboard():
return render_template('dashboard.html')
@app.route('/api/analyse',methods=["GET"])
def analyse():
return render_template('analyse.html')
@app.route('/api/analyse2019',methods=["GET"])
def analyse2019():
conn = mysql.connect()
cursor =conn.cursor()
cursor.execute("SELECT annee, matricule, nom ,prenom ,sexe,specialite,moyenne from resultats where annee=2019")
data = cursor.fetchall()
row_headers=[x[0] for x in cursor.description]
cursor.close()
json_data=[]
for result in data:
json_data.append(dict(zip(row_headers, result)))
return make_response(jsonify(json_data),200)
@app.route('/api/analyse2020',methods=["GET"])
def analyse2020():
conn = mysql.connect()
cursor =conn.cursor()
cursor.execute("SELECT annee, matricule, nom ,prenom ,sexe,specialite,moyenne from resultats where annee=2020")
data = cursor.fetchall()
row_headers=[x[0] for x in cursor.description]
cursor.close()
json_data=[]
for result in data:
json_data.append(dict(zip(row_headers, result)))
return make_response(jsonify(json_data),200)
@app.route('/api/analyse2021',methods=["GET"])
def analyse2021():
conn = mysql.connect()
cursor =conn.cursor()
cursor.execute("SELECT annee, matricule, nom ,prenom ,sexe,specialite,moyenne from resultats where annee=2021")
data = cursor.fetchall()
row_headers=[x[0] for x in cursor.description]
cursor.close()
json_data=[]
for result in data:
json_data.append(dict(zip(row_headers, result)))
return make_response(jsonify(json_data),200)
@app.route('/api/datacourbe')
def doGetDatacourbe():
data = {"years":[], "datasets":[]}
conn = mysql.connect()
cursor =conn.cursor()
cursor.execute("SELECT DISTINCT annee FROM resultats")
years_tuple = cursor.fetchall()
years_list = [item[0] for item in years_tuple]
data["years"]=years_list
cursor.execute("SELECT DISTINCT specialite FROM resultats")
specialite_tuple = cursor.fetchall()
specialite_list = [item[0] for item in specialite_tuple]
for specialite in specialite_list:
cursor.execute("SELECT COUNT(*) AS NBR FROM resultats WHERE specialite='"+specialite+"' GROUP BY annee")
nbr_tuple = cursor.fetchall()
nbr_list = [item[0] for item in nbr_tuple]
data["datasets"].append({"label":specialite, "data":nbr_list})
data_JSON = json.dumps(data)
return data_JSON
@app.route('/api/databar')
def doGetDatabar():
data =[]
conn = mysql.connect()
cursor =conn.cursor()
cursor.execute("SELECT DISTINCT annee FROM resultats")
years_tuple = cursor.fetchall()
years_list = [item[0] for item in years_tuple]
cursor.execute("SELECT COUNT(*) AS NBR FROM resultats GROUP BY annee ")
nbr_tuple = cursor.fetchall()
nbr_list = [item[0] for item in nbr_tuple]
data.append({"label":years_list, "nbr":nbr_list})
data_JSON = json.dumps(data)
return data_JSON
@app.route('/api/datapie')
def doGetDatapie():
data = []
conn = mysql.connect()
cursor =conn.cursor()
cursor.execute("SELECT DISTINCT sexe FROM resultats")
sexe_tuple = cursor.fetchall()
sexe_list = [item[0] for item in sexe_tuple]
for sexe in sexe_list:
cursor.execute("SELECT COUNT(*) AS NBR FROM resultats WHERE sexe='"+sexe+"' ")
nbr_tuple = cursor.fetchall()
nbr_list = [item[0] for item in nbr_tuple]
data.append({"label":sexe, "data":nbr_list})
data_JSON = json.dumps(data)
return data_JSON
@app.route('/api/datadoublebar')
def doGetdoublebar():
data = {"years":[], "datasets":[]}
conn = mysql.connect()
cursor =conn.cursor()
cursor.execute("SELECT DISTINCT annee FROM resultats")
years_tuple = cursor.fetchall()
years_list = [item[0] for item in years_tuple]
data["years"]=years_list
cursor.execute("SELECT COUNT(*) AS NBR FROM resultats WHERE moyenne BETWEEN '10.00' AND '20' GROUP BY annee ")
passants_tuple = cursor.fetchall()
passants_list = [item[0] for item in passants_tuple]
cursor.execute("SELECT COUNT(*) AS NBR FROM resultats WHERE moyenne BETWEEN '0' AND '9.99' GROUP BY annee")
doublants_tuple = cursor.fetchall()
doublants_list = [item[0] for item in doublants_tuple]
data["datasets"].append({"passants":passants_list, "doublants":doublants_list})
data_JSON = json.dumps(data)
return data_JSON
@app.route('/api/dataDoughnut')
def doGetDoughnut():
data = []
conn = mysql.connect()
cursor =conn.cursor()
cursor.execute("SELECT DISTINCT annee FROM resultats")
cursor.execute("SELECT DISTINCT specialite FROM resultats")
specialite_tuple = cursor.fetchall()
specialite_list = [item[0] for item in specialite_tuple]
cursor.execute("SELECT COUNT(*) AS NBR FROM resultats WHERE moyenne BETWEEN '10.00' AND '20' GROUP BY specialite")
passants_tuple = cursor.fetchall()
passants_list = [item[0] for item in passants_tuple]
data.append({"label":specialite_list, "data":passants_list})
data_JSON = json.dumps(data)
return data_JSON
@app.route('/api/datasexe')
def doGetsexe():
data = []
conn = mysql.connect()
cursor =conn.cursor()
cursor.execute("SELECT COUNT(*) AS NBR FROM resultats WHERE sexe='F' GROUP BY annee")
f_tuple = cursor.fetchall()
f_list = [item[0] for item in f_tuple]
cursor.execute("SELECT COUNT(*) AS NBR FROM resultats WHERE sexe='H' GROUP BY annee")
h_tuple = cursor.fetchall()
h_list = [item[0] for item in h_tuple]
data.append({"femme":f_list, "homme":h_list})
data_JSON = json.dumps(data)
return data_JSON
@app.route('/api/datamoy')
def doGetmoy():
data = []
conn = mysql.connect()
cursor =conn.cursor()
cursor.execute("SELECT DISTINCT annee FROM resultats")
years_tuple = cursor.fetchall()
years_list = [item[0] for item in years_tuple]
cursor.execute("SELECT MAX(moyenne) FROM resultats GROUP BY annee")
moy_tuple = cursor.fetchall()
moy_list = [item[0] for item in moy_tuple]
data.append({"year":years_list, "moyenne":moy_list})
data_JSON = json.dumps(data)
return data_JSON
if __name__ == '__main__':
app.run(debug=True, port=5000)