質問編集履歴
2
flaskの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,6 +16,7 @@
|
|
16
16
|
### 該当のソースコード
|
17
17
|
|
18
18
|
```html
|
19
|
+
index.html
|
19
20
|
<!DOCTYPE html>
|
20
21
|
<html lang="ja">
|
21
22
|
<head>
|
@@ -81,4 +82,61 @@
|
|
81
82
|
});
|
82
83
|
</script>
|
83
84
|
</body>
|
85
|
+
```
|
86
|
+
```python
|
87
|
+
app.py
|
88
|
+
import os
|
89
|
+
from flask import Flask, render_template,request
|
90
|
+
import base_ball
|
91
|
+
app = Flask(__name__)
|
92
|
+
|
93
|
+
@app.route('/',methods=["GET","POST"])
|
94
|
+
def index():
|
95
|
+
if request.method == 'POST':
|
96
|
+
year = request.form.get('year','')
|
97
|
+
team = request.form.get('team','')
|
98
|
+
print(year,team)
|
99
|
+
if year == '2019' and team == 'bs':
|
100
|
+
players = base_ball.data_load(year,'b')
|
101
|
+
else:
|
102
|
+
players = base_ball.data_load(year,team)
|
103
|
+
if int(year) >= 2011 and team == 'db':
|
104
|
+
players = base_ball.data_load(year,'yb')
|
105
|
+
else:
|
106
|
+
players = base_ball.data_load(year,team)
|
107
|
+
#players = base_ball.data_load(year,team)
|
108
|
+
players_values = players.values.tolist()
|
109
|
+
players_columns = players.columns.tolist()
|
110
|
+
players_index = players.index.tolist()
|
111
|
+
return render_template('index.html', \
|
112
|
+
players_values = players_values, \
|
113
|
+
players_columns = players_columns, \
|
114
|
+
players_index = players_index)
|
115
|
+
return render_template('index.html')
|
116
|
+
|
117
|
+
if __name__ == '__main__':
|
118
|
+
app.run(debug=True, host='127.0.0.1',port=5000,threaded=True)
|
119
|
+
```
|
120
|
+
```python
|
121
|
+
base_ball.py
|
122
|
+
from IPython import get_ipython
|
123
|
+
import random
|
124
|
+
import matplotlib.pyplot as plt
|
125
|
+
import numpy as np
|
126
|
+
import pandas as pd
|
127
|
+
import sys
|
128
|
+
#野手データ取得
|
129
|
+
def data_load(year,team):
|
130
|
+
BASE_URL = ("http://npb.jp/bis/{}/stats/idb1_{}.html".format(year,team))
|
131
|
+
dfs = pd.io.html.read_html(BASE_URL)
|
132
|
+
#カラムの再設定
|
133
|
+
df = dfs[0][1:]; df.columns=dfs[0].loc[0,:]
|
134
|
+
new_header = df.iloc[0]
|
135
|
+
df = df[1:]
|
136
|
+
df.columns = new_header
|
137
|
+
df2 = df.rename(columns=lambda s: str(s).replace(" ",""))
|
138
|
+
df_i = df2.rename(columns=lambda s: str(s).replace(" ",""))
|
139
|
+
del df_i['nan']
|
140
|
+
df3 = df_i.set_index('選手')
|
141
|
+
return df3
|
84
142
|
```
|
1
jQueryの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,8 +22,7 @@
|
|
22
22
|
<meta charset="UTF-8">
|
23
23
|
<title>Baseball Date_game</title>
|
24
24
|
<mata name="description" content="野球データを使ったシミュレーションゲームです">
|
25
|
-
<link rel="stylesheet" href="https://cdn.datatables.net/
|
25
|
+
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.css">
|
26
|
-
<script src="https://cdn.datatables.net/t/bs-3.3.6/jqc-1.12.0,dt-1.10.11/datatables.min.js"></script>
|
27
26
|
</head>
|
28
27
|
<body>
|
29
28
|
<fieldset>
|
@@ -72,8 +71,12 @@
|
|
72
71
|
{%- endfor %}
|
73
72
|
</tbody>
|
74
73
|
</table>
|
74
|
+
<script src="https://code.jquery.com/jquery-3.5.1.slim.js"
|
75
|
+
integrity="sha256-DrT5NfxfbHvMHux31Lkhxg42LY6of8TaYyK50jnxRnM="
|
76
|
+
crossorigin="anonymous"></script>
|
77
|
+
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.js"></script>
|
75
78
|
<script>
|
76
|
-
|
79
|
+
$(document).ready( function () {
|
77
80
|
$("#base-table").DataTable();
|
78
81
|
});
|
79
82
|
</script>
|