-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.py
100 lines (80 loc) · 3.29 KB
/
util.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
from flask import render_template as flask_render_template
import datetime
from locale import setlocale, LC_TIME
from honomara_members_site import app, db
try:
setlocale(LC_TIME, 'ja_JP.UTF-8') # for get_wday
except Exception as e:
pass
def render(template, **args):
args['template'] = template
return flask_render_template('flame.html', **args)
def year_to_grade(year, current_school_year):
return current_school_year + 1 - year
def get_school_year(date):
if date.month < 4:
return date.year - 1
else:
return date.year
def str_to_date(str):
return datetime.datetime.strptime(str, '%Y-%m-%d').date()
def get_wday(date):
return datetime.date.strftime('%a')
def validate_course_and_set_name(form=None):
if form is None:
msg = 'generate_course_name needs form'
app.logger.warning(msg)
return msg
if form.type.data in ['road', 'track', 'trail']:
if form.distance.data is None or form.distance.data <= 0:
msg = 'type {} need distance'.format(form.type.data)
app.logger.warning(msg)
return msg
elif form.type.data == 'road':
if form.distance.data == 42.195:
form.show_name.data = 'フルマラソン'
elif form.distance.data == 42.195 / 2:
form.show_name.data = 'ハーフマラソン'
elif form.show_name.data is None:
form.show_name.data = '{:f}km'.format(form.distance.data)
elif form.type.data == 'track':
if form.show_name.data is None:
form.show_name.data = '{:f}m走'.format(
int(form.distance.data * 1000))
elif form.type.trail == 'trail':
if form.show_name.data is None:
form.show_name.data = '{:f}kmコース'.format(form.distance.data)
elif form.type.data in ['time', 'relay']:
if form.time.data is None or form.time.data <= 0:
msg = 'type {} need time'.format(form.type.data)
app.logger.warning(msg)
return msg
if form.type.data == 'time':
form.show_name.data = '{:f}時間走'.format(
form.time.data / 3600 // 1000)
if form.type.data == 'relay':
form.show_name.data = '{:f}時間リレー'.format(
form.time.data / 3600 // 1000)
else: # other
if form.show_name.data is None:
form.show_name.data = '{}km, {}時間'.format(
form.distance.data, form.time.data / 3600 / 1000)
# generate_course_name(None)
return None
def form_set_time(form=None):
if form is None:
return
elif form.time.data is None:
form.time_h.data = form.time_h.data or 0
form.time_m.data = form.time_m.data or 0
form.time_s.data = form.time_s.data or 0
form.time_ms.data = form.time_ms.data or 0
form.time.data = ((form.time_h.data * 60 + form.time_m.data)
* 60 + form.time_s.data) * 1000 + form.time_ms.data
else:
tmp = form.time.data
form.time_ms.data, tmp = tmp % 1000, tmp // 1000
form.time_s.data, tmp = tmp % 60, tmp // 60
form.time_m.data, tmp = tmp % 60, tmp // 60
form.time_h.data = tmp
current_school_year = get_school_year(datetime.date.today())