質問編集履歴

2

flaskの追加

2020/06/29 12:14

投稿

HaTea
HaTea

スコア16

test CHANGED
File without changes
test CHANGED
@@ -34,6 +34,8 @@
34
34
 
35
35
  ```html
36
36
 
37
+ index.html
38
+
37
39
  <!DOCTYPE html>
38
40
 
39
41
  <html lang="ja">
@@ -165,3 +167,117 @@
165
167
  </body>
166
168
 
167
169
  ```
170
+
171
+ ```python
172
+
173
+ app.py
174
+
175
+ import os
176
+
177
+ from flask import Flask, render_template,request
178
+
179
+ import base_ball
180
+
181
+ app = Flask(__name__)
182
+
183
+
184
+
185
+ @app.route('/',methods=["GET","POST"])
186
+
187
+ def index():
188
+
189
+ if request.method == 'POST':
190
+
191
+ year = request.form.get('year','')
192
+
193
+ team = request.form.get('team','')
194
+
195
+ print(year,team)
196
+
197
+ if year == '2019' and team == 'bs':
198
+
199
+ players = base_ball.data_load(year,'b')
200
+
201
+ else:
202
+
203
+ players = base_ball.data_load(year,team)
204
+
205
+ if int(year) >= 2011 and team == 'db':
206
+
207
+ players = base_ball.data_load(year,'yb')
208
+
209
+ else:
210
+
211
+ players = base_ball.data_load(year,team)
212
+
213
+ #players = base_ball.data_load(year,team)
214
+
215
+ players_values = players.values.tolist()
216
+
217
+ players_columns = players.columns.tolist()
218
+
219
+ players_index = players.index.tolist()
220
+
221
+ return render_template('index.html', \
222
+
223
+ players_values = players_values, \
224
+
225
+ players_columns = players_columns, \
226
+
227
+ players_index = players_index)
228
+
229
+ return render_template('index.html')
230
+
231
+
232
+
233
+ if __name__ == '__main__':
234
+
235
+ app.run(debug=True, host='127.0.0.1',port=5000,threaded=True)
236
+
237
+ ```
238
+
239
+ ```python
240
+
241
+ base_ball.py
242
+
243
+ from IPython import get_ipython
244
+
245
+ import random
246
+
247
+ import matplotlib.pyplot as plt
248
+
249
+ import numpy as np
250
+
251
+ import pandas as pd
252
+
253
+ import sys
254
+
255
+ #野手データ取得
256
+
257
+ def data_load(year,team):
258
+
259
+ BASE_URL = ("http://npb.jp/bis/{}/stats/idb1_{}.html".format(year,team))
260
+
261
+ dfs = pd.io.html.read_html(BASE_URL)
262
+
263
+ #カラムの再設定
264
+
265
+ df = dfs[0][1:]; df.columns=dfs[0].loc[0,:]
266
+
267
+ new_header = df.iloc[0]
268
+
269
+ df = df[1:]
270
+
271
+ df.columns = new_header
272
+
273
+ df2 = df.rename(columns=lambda s: str(s).replace(" ",""))
274
+
275
+ df_i = df2.rename(columns=lambda s: str(s).replace(" ",""))
276
+
277
+ del df_i['nan']
278
+
279
+ df3 = df_i.set_index('選手')
280
+
281
+ return df3
282
+
283
+ ```

1

jQueryの追加

2020/06/29 12:14

投稿

HaTea
HaTea

スコア16

test CHANGED
File without changes
test CHANGED
@@ -46,9 +46,7 @@
46
46
 
47
47
  <mata name="description" content="野球データを使ったシミュレーションゲームです">
48
48
 
49
- <link rel="stylesheet" href="https://cdn.datatables.net/t/bs-3.3.6/jqc-1.12.0,dt-1.10.11/datatables.min.css"/>
49
+ <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.css">
50
-
51
- <script src="https://cdn.datatables.net/t/bs-3.3.6/jqc-1.12.0,dt-1.10.11/datatables.min.js"></script>
52
50
 
53
51
  </head>
54
52
 
@@ -146,9 +144,17 @@
146
144
 
147
145
  </table>
148
146
 
147
+ <script src="https://code.jquery.com/jquery-3.5.1.slim.js"
148
+
149
+ integrity="sha256-DrT5NfxfbHvMHux31Lkhxg42LY6of8TaYyK50jnxRnM="
150
+
151
+ crossorigin="anonymous"></script>
152
+
153
+ <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.js"></script>
154
+
149
155
  <script>
150
156
 
151
- jQuery(function($){
157
+ $(document).ready( function () {
152
158
 
153
159
  $("#base-table").DataTable();
154
160