-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
55 lines (42 loc) · 1.8 KB
/
app.py
File metadata and controls
55 lines (42 loc) · 1.8 KB
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
from flask import Flask, render_template, request
import os
app = Flask(__name__)
match_history = []
image_dir = 'static/images/'
def get_image_list(directory):
image_list = []
for filename in os.listdir(directory):
if filename.endswith('.jpg') or filename.endswith('.png'):
image_list.append(filename)
return image_list
from datetime import datetime
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
user_profile = request.form['user_profile']
opponent_profile = request.form['opponent_profile']
choice = request.form['choice']
result = request.form['result']
current_datetime = datetime.now()
match_history.append({
'datetime': current_datetime, # 日時を記録(datetimeオブジェクト)
'user_profile': user_profile,
'opponent_profile': opponent_profile,
'choice': choice,
'result': result
})
user_profiles = get_image_list(image_dir)
opponent_profiles = get_image_list(image_dir)
return render_template('index.html', user_profiles=user_profiles, opponent_profiles=opponent_profiles, match_history=match_history)
@app.route('/history')
def history():
total_matches = len(match_history)
wins = sum(1 for match in match_history if match['result'] == '勝')
losses = total_matches - wins
win_rate = (wins / total_matches) * 100 if total_matches > 0 else 0
return render_template('history.html', match_history=match_history, total_matches=total_matches, wins=wins, losses=losses, win_rate=win_rate)
@app.template_filter('percent')
def percent_filter(value):
return f"{value:.2f}%"
if __name__ == '__main__':
app.run(debug=True)