这一章我们实现男子和女子3000米跑成绩的计算,原始数据是时间,多少分多少秒,全年龄段考核内容都是3公里,但是海拔不同标准不同,是所有科目中最复杂的计算。
通过分析3000米跑“成绩计算标准表”,发现标准表也只是参照标准表,不是连续的全覆盖。比如平原3000米标准中24岁以下男子,只规定了11分30秒的成绩为100分,11分55秒的成绩为95分,那么中间的情况多少分呢?
男子3000米成绩计算标准表
女子3000米成绩计算标准表
高原男子3000米成绩计算标准表
高原女子3000米成绩计算标准表
还是只能是我们根据公平原则去补充,在11分30秒、11分55秒的成绩之间去取平均分,但手工补充的数据量太大,我们编程解决。
所以录入Excel表中的标准和规定的相同,没有增加手工计算的标准:
男女平原3000米标准
男子高原3000米标准
女子高原3000米标准
同样,通过Python的openpyxl模块读取标准表中的数据,制成 {原始3公里跑时长:分数} 格式的字典,以供主程序查询出换算成绩,再写入成绩表的对应位置中。
这里要使用海拔数据,后期等级评定还需要人员类别的信息,所以设计了一个工作簿来输入这些参数信息。
人员参数设置
在B2位置输入人员类别,在B3位置输入海拔。
原始成绩登记表
1.我把计算高原男子和女子3000米的文件分开,同时海拔3000以下与3000米以上标准又不同,这里我以男子2001米~3000米的计算为例讲解,文件命名为highland2001up_3km_male.py。这个模块类的构造方法“__init__()” 有一个参数,ele,传递海拔数据。
另外将 {原始3公里跑时长:分数} 格式的字典的键全部取出来,转换成列表,如24岁以下的时间键,age24_keys=[datetime.time(0, 11, 42), datetime.time(0, 12, 7), datetime.time(0, 12, 22), datetime.time(0, 12, 37), datetime.time(0, 12, 52), datetime.time(0, 13, 7), datetime.time(0, 13, 22), datetime.time(0, 13, 42), datetime.time(0, 13, 47), datetime.time(0, 13, 52)]。目的是计算标准中未给出的中间值要用到,比如计算11分45秒的成绩,就需要与标准中有的11分42秒和12分7秒做计算。
还要根据海拔,计算出每增加100米高度标准递增8秒后的标准时间列表,因为2201米的标准比2000米~2100米的标准多了16秒。
# 男子海拔2001~3000米,3000米跑的成绩计算
# 从工作表“男子高原3000米标准”中读取数据
import openpyxl
import datetime as dt
from run_standard_add import standard_add
from score_computing import score_computing
class Highland2001up3kmMaleStandardData:
def __init__(self, ele):
elevation = ele # 海拔高度
multiple = (elevation - 2001) // 100 # 整数除法返回向下取整后的结果
addition = multiple * 8 # 每增加100米高度,标准递增8秒
wb = openpyxl.load_workbook('通用训练课目考核成绩计算.xlsx')
ws_long_run_male = wb['男子高原3000米标准']
self.age24 = {} # 24岁以下,{原始男子3000米分秒数:分数}
self.age25_27 = {} # 25~27岁,{原始男子3000米分秒数:分数}
self.age28_30 = {}
self.age31_33 = {}
self.age34_36 = {}
self.age37_39 = {}
self.age40_42 = {} # 40岁以上,{原始男子3000米分秒数:分数}
self.age43_45 = {} # 43~45岁,{原始男子3000米分秒数:分数}
self.age46_48 = {}
self.age49_51 = {}
self.age52_54 = {}
self.age55_57 = {}
self.age58_59 = {}
rngs2000 = ws_long_run_male.iter_rows(min_row=3,max_row=12,min_col=2,max_col=15)
# 生成{原始男子3000米分秒数:分数}的字典
for row in rngs2000:
# print([c.value for c in row])
self.age24[row[1].value] = row[0].value
self.age25_27[row[2].value] = row[0].value
self.age28_30[row[3].value] = row[0].value
self. age31_33[row[4].value] = row[0].value
self.age34_36[row[5].value] = row[0].value
self.age37_39[row[6].value] = row[0].value
self.age40_42[row[7].value] = row[0].value
self.age43_45[row[8].value] = row[0].value
self.age46_48[row[9].value] = row[0].value
self.age49_51[row[10].value] = row[0].value
self.age52_54[row[11].value] = row[0].value
self.age55_57[row[12].value] = row[0].value
self.age58_59[row[13].value] = row[0].value
# print('-----age24-----') # 打印数据以便检查
# for m in self.age24.items():
# print(m)
# print('-----age25_27-----')
# for m in self.age25_27.items():
# print(m)
# print('-----age28_30-----')
# for m in self.age28_30.items():
# print(m)
# print('-----age31_33-----')
# for m in self.age31_33.items():
# print(m)
# print('-----age34_36-----')
# for m in self.age34_36.items():
# print(m)
# print('-----age37_39-----')
# for m in self.age37_39.items():
# print(m)
#
# print('-----age40_42-----') # 打印数据以便检查
# for m in self.age40_42.items():
# print(m)
# print('-----age43_45-----')
# for m in self.age43_45.items():
# print(m)
# print('-----age46_48-----')
# for m in self.age46_48.items():
# print(m)
# print('-----age49_51-----')
# for m in self.age49_51.items():
# print(m)
# print('-----age52_54-----')
# for m in self.age52_54.items():
# print(m)
# print('-----age55_57-----')
# for m in self.age55_57.items():
# print(m)
# print('-----age58_59-----')
# for m in self.age58_59.items():
# print(m)
# 将字典中的时间键取出来,转换成列表
self.age24_keys = list(self.age24.keys())
#print(self.age24_keys)
self.age25_27_keys = list(self.age25_27.keys())
self.age28_30_keys = list(self.age28_30.keys())
self.age31_33_keys = list(self.age31_33.keys())
self.age34_36_keys = list(self.age34_36.keys())
self.age37_39_keys = list(self.age37_39.keys())
self.age40_42_keys = list(self.age40_42.keys())
self.age43_45_keys = list(self.age43_45.keys())
self.age46_48_keys = list(self.age46_48.keys())
self.age49_51_keys = list(self.age49_51.keys())
self.age52_54_keys = list(self.age52_54.keys())
self.age55_57_keys = list(self.age55_57.keys())
self.age58_59_keys = list(self.age58_59.keys())
# 每增加100米高度标准递增8秒
self.age24_time_list = standard_add(self.age24_keys.copy(),addition)
#print(self.age24_time_list)
self.age25_27_time_list = standard_add(self.age25_27_keys.copy(),addition)
self.age28_30_time_list = standard_add(self.age28_30_keys.copy(),addition)
self.age31_33_time_list = standard_add(self.age31_33_keys.copy(),addition)
self.age34_36_time_list = standard_add(self.age34_36_keys.copy(),addition)
self.age37_39_time_list = standard_add(self.age37_39_keys.copy(),addition)
self.age40_42_time_list = standard_add(self.age40_42_keys.copy(),addition)
self.age43_45_time_list = standard_add(self.age43_45_keys.copy(),addition)
self.age46_48_time_list = standard_add(self.age46_48_keys.copy(),addition)
self.age49_51_time_list = standard_add(self.age49_51_keys.copy(),addition)
self.age52_54_time_list = standard_add(self.age52_54_keys.copy(),addition)
self.age55_57_time_list = standard_add(self.age55_57_keys.copy(),addition)
self.age58_59_time_list = standard_add(self.age58_59_keys.copy(),addition)
2.上面使用到的增加标准函数standard_add(),我写入在另一个模块run_standard_add.py中:
# 每增加100米高度标准递增8秒
def standard_add(list, addition):
'''每增加100米高度,标准递增8秒,这里将增加的秒数加到每个列表元素中'''
for x in range(0, len(list)):
seconds = list[x].second + addition
minutes_add = seconds // 60 # 整数除法返回向下取整后的结果为分数的增值
seconds_add = seconds % 60 # 取余数为秒数
#print(minutes_add, seconds_add)
list[x] = list[x].replace(minute=minutes_add + list[x].minute, second=seconds_add)
return list
3.设计计算分数的方法,同样是先根据年龄进行判定,这里把计算方式再做了打包,做成了score_computing()函数,有4个参数,原始成绩,字典,时间键列表,每增加100米高度标准递增8秒后的时间键列表。
def longrun_score_computing(self,age,original_amount):
'''根据年龄,实际3000米分秒数,计算所得分数'''
if type(original_amount) is dt.time: # 核查是否是日期格式
if age <= 24:
return score_computing(original_amount,self.age24,self.age24_keys,self.age24_time_list)
elif 25 <= age <= 27:
return score_computing(original_amount, self.age25_27, self.age25_27_keys, self.age25_27_time_list)
elif 28 <= age <= 30:
return score_computing(original_amount, self.age28_30, self.age28_30_keys, self.age28_30_time_list)
elif 31 <= age <= 33:
return score_computing(original_amount, self.age31_33, self.age31_33_keys, self.age31_33_time_list)
elif 34 <= age <= 36:
return score_computing(original_amount, self.age34_36, self.age34_36_keys, self.age34_36_time_list)
elif 37 <= age <= 39:
return score_computing(original_amount, self.age37_39, self.age37_39_keys, self.age37_39_time_list)
# 40~59
elif 40 <= age <= 42:
return score_computing(original_amount, self.age40_42, self.age40_42_keys, self.age40_42_time_list)
elif 43 <= age <= 45:
return score_computing(original_amount, self.age43_45, self.age43_45_keys, self.age43_45_time_list)
elif 46 <= age <= 48:
return score_computing(original_amount, self.age46_48, self.age46_48_keys, self.age46_48_time_list)
elif 49 <= age <= 51:
return score_computing(original_amount, self.age49_51, self.age49_51_keys, self.age49_51_time_list)
elif 52 <= age <= 54:
return score_computing(original_amount, self.age52_54, self.age52_54_keys, self.age52_54_time_list)
elif 55 <= age <= 57:
return score_computing(original_amount, self.age55_57, self.age55_57_keys, self.age55_57_time_list)
elif 58 <= age <= 59:
return score_computing(original_amount, self.age58_59, self.age58_59_keys, self.age58_59_time_list)
else:
print('ERROR:男子3000米跑,原始成绩的数据类型须为时间(datetime.time)类型')
if __name__ == "__main__": # 测试本模块
hl2001_3km_male_std = Highland2001up3kmMaleStandardData(2901)
result = hl2001_3km_male_std.longrun_score_computing(24,dt.time(0,13,4))
print(result)
4.上面使用到的计算函数score_computing(),我写入在另一个模块score_computing.py中。小于55分和大于100分的情况很简单,之间的先判定是否刚好是标准中规定的时长,是的话,通过相同序号联系,直接查字典;不是的话,添加进每100米海拔增加时间后的列表中排序,得到序号,序号减1,和序号加1,就得到相邻的,两个标准表中有的时长。然后,计算上下两个标准时长的间隔秒数,以及与相邻较差标准时长的间隔秒数,最后算出最终成绩。
# 通过原始的3000米跑成绩,分年龄段计算成绩
def score_computing(original_amount,age_n,age_n_keys,age_n_time_list):
#print(age_n_keys)
#print(age_n_time_list)
if original_amount > age_n_time_list[9]: # 大于55分的时长时,为0分
return 0
elif original_amount < age_n_time_list[0]: #小于100分的时长时,加分
return 100 + ((age_n_time_list[0].minute - original_amount.minute) * 60 +
age_n_time_list[0].second - original_amount.second) / 5
elif age_n_time_list[0] <= original_amount <= age_n_time_list[9]:
if original_amount in age_n_time_list:
index_1 = age_n_time_list.index(original_amount) # 原始成绩在列表中的序号
return age_n[age_n_keys[index_1]]
else:
l1 = age_n_time_list.copy() # l1为临时表
l1.append(original_amount); l1.sort() # 添加原始成绩进列表,再排序
index_2 = l1.index(original_amount) # 原始成绩在列表中的序号
better_time = l1[index_2 - 1] # 比原始成绩优秀的最临近的标准成绩
worse_time = l1[index_2 + 1] # 比原始成绩差的最临近的标准成绩
time_interval = (worse_time.minute - better_time.minute)*60 + (
worse_time.second - better_time.second) # 上下两个标准成绩的间隔秒数
seconds_dif = (worse_time.minute - original_amount.minute)*60 + (
worse_time.second - original_amount.second) # 与相邻较差标准成绩的间隔秒数
#print(time_interval, seconds_dif)
return round(5*seconds_dif/time_interval+age_n[age_n_keys[index_2]],1) #5是相邻两个标准时长的分数相差5分
5.女子2001米~3000米的计算文件命名为highland2001up_3km_female.py,除了读取的工作簿不同,其它内容与男子大体相同。
6.男子3001米~4000米的计算文件命名为highland3001up_3km_male.py,女子3001米~4000米的计算文件命名为highland3001up_3km_female.py。
7.平原男子和女子3000米写成了一个带性别参数的类,文件名为flatland_3km.py,根据性别参数,读取工作簿上不同区域的标准数据,制成不同的标准字典。因为没有每增加海拔100米增加时长的要求,在调用score_computing()函数时,第3/4参数使用同一个列表即可。
# 男子女子平原3000米跑的成绩计算
# 从工作表“男女平原3000米标准”中读取数据
import openpyxl
import datetime as dt
from score_computing import score_computing
class Flatland3kmStandardData:
def __init__(self, gender):
self.gender = gender # 性别
wb = openpyxl.load_workbook('通用训练课目考核成绩计算.xlsx')
ws_long_run = wb['男女平原3000米标准']
self.age24 = {} # 24岁以下,{原始男女平原3000米分秒数:分数}
self.age25_27 = {} # 25~27岁,{原始男女平原3000米分秒数:分数}
self.age28_30 = {}
self.age31_33 = {}
self.age34_36 = {}
self.age37_39 = {}
self.age40_42 = {} # 40岁以上,{原始男女平原3000米分秒数:分数}
self.age43_45 = {} # 43~45岁,{原始男女平原3000米分秒数:分数}
self.age46_48 = {}
self.age49_51 = {}
self.age52_54 = {}
self.age55_57 = {}
self.age58_59 = {}
if self.gender == '男':
rngs = ws_long_run.iter_rows(min_row=3, max_row=12, min_col=1, max_col=14)
elif self.gender == '女':
rngs = ws_long_run.iter_rows(min_row=16,max_row=25,min_col=1,max_col=14)
# 生成{原始男女平原3000米分秒数:分数}的字典
for row in rngs:
# print([c.value for c in row])
self.age24[row[1].value] = row[0].value
self.age25_27[row[2].value] = row[0].value
self.age28_30[row[3].value] = row[0].value
self. age31_33[row[4].value] = row[0].value
self.age34_36[row[5].value] = row[0].value
self.age37_39[row[6].value] = row[0].value
self.age40_42[row[7].value] = row[0].value
self.age43_45[row[8].value] = row[0].value
self.age46_48[row[9].value] = row[0].value
self.age49_51[row[10].value] = row[0].value
self.age52_54[row[11].value] = row[0].value
self.age55_57[row[12].value] = row[0].value
self.age58_59[row[13].value] = row[0].value
# print('-----age24-----') # 打印数据以便检查
# for m in self.age24.items():
# print(m)
# print('-----age25_27-----')
# for m in self.age25_27.items():
# print(m)
# print('-----age28_30-----')
# for m in self.age28_30.items():
# print(m)
# print('-----age31_33-----')
# for m in self.age31_33.items():
# print(m)
# print('-----age34_36-----')
# for m in self.age34_36.items():
# print(m)
# print('-----age37_39-----')
# for m in self.age37_39.items():
# print(m)
#
# print('-----age40_42-----') # 打印数据以便检查
# for m in self.age40_42.items():
# print(m)
# print('-----age43_45-----')
# for m in self.age43_45.items():
# print(m)
# print('-----age46_48-----')
# for m in self.age46_48.items():
# print(m)
# print('-----age49_51-----')
# for m in self.age49_51.items():
# print(m)
# print('-----age52_54-----')
# for m in self.age52_54.items():
# print(m)
# print('-----age55_57-----')
# for m in self.age55_57.items():
# print(m)
# print('-----age58_59-----')
# for m in self.age58_59.items():
# print(m)
# 将字典中的时间键取出来,转换成列表
self.age24_keys = list(self.age24.keys())
#print(self.age24_keys)
self.age25_27_keys = list(self.age25_27.keys())
self.age28_30_keys = list(self.age28_30.keys())
self.age31_33_keys = list(self.age31_33.keys())
self.age34_36_keys = list(self.age34_36.keys())
self.age37_39_keys = list(self.age37_39.keys())
self.age40_42_keys = list(self.age40_42.keys())
self.age43_45_keys = list(self.age43_45.keys())
self.age46_48_keys = list(self.age46_48.keys())
self.age49_51_keys = list(self.age49_51.keys())
self.age52_54_keys = list(self.age52_54.keys())
self.age55_57_keys = list(self.age55_57.keys())
self.age58_59_keys = list(self.age58_59.keys())
def longrun_score_computing(self,age,original_amount):
'''根据年龄,实际3000米分秒数,计算所得分数'''
if type(original_amount) is dt.time: # 核查是否是日期格式
if age <= 24:
# 这里不需要根据海拔改变评分标准,但便于重用score_computing()函数,self.age24_keys用作参数两次
return score_computing(original_amount,self.age24,self.age24_keys,self.age24_keys)
elif 25 <= age <= 27:
return score_computing(original_amount, self.age25_27, self.age25_27_keys, self.age25_27_keys)
elif 28 <= age <= 30:
return score_computing(original_amount, self.age28_30, self.age28_30_keys, self.age28_30_keys)
elif 31 <= age <= 33:
return score_computing(original_amount, self.age31_33, self.age31_33_keys, self.age31_33_keys)
elif 34 <= age <= 36:
return score_computing(original_amount, self.age34_36, self.age34_36_keys, self.age34_36_keys)
elif 37 <= age <= 39:
return score_computing(original_amount, self.age37_39, self.age37_39_keys, self.age37_39_keys)
# 40~59
elif 40 <= age <= 42:
return score_computing(original_amount, self.age40_42, self.age40_42_keys, self.age40_42_keys)
elif 43 <= age <= 45:
return score_computing(original_amount, self.age43_45, self.age43_45_keys, self.age43_45_keys)
elif 46 <= age <= 48:
return score_computing(original_amount, self.age46_48, self.age46_48_keys, self.age46_48_keys)
elif 49 <= age <= 51:
return score_computing(original_amount, self.age49_51, self.age49_51_keys, self.age49_51_keys)
elif 52 <= age <= 54:
return score_computing(original_amount, self.age52_54, self.age52_54_keys, self.age52_54_keys)
elif 55 <= age <= 57:
return score_computing(original_amount, self.age55_57, self.age55_57_keys, self.age55_57_keys)
elif 58 <= age <= 59:
return score_computing(original_amount, self.age58_59, self.age58_59_keys, self.age58_59_keys)
else:
print('ERROR:男女平原3000米跑,原始成绩的数据类型须为时间(datetime.time)类型')
if __name__ == "__main__": # 测试本模块
flatland_3km_female_std = Flatland3kmStandardData('女')
result = flatland_3km_female_std.longrun_score_computing(25,dt.time(0,16,13))
print(result)
8.对主程序training_performance.py进行修改。读取工作簿“人员参数设置”,分人员类别设置最低分数,如一类人员的最低分是65,低于65分即不及格,实际记0分;根据海拔参数,进行不同的实例化;判断性别后,先计算单杠成绩,接着计算仰卧起坐成绩,再计算蛇形跑成绩,最后计算3公里成绩,分别写入表中换算成绩的相应位置。
import openpyxl
import datetime as dt
from age_computing import age_computing # 导入年龄计算模块
from pullup_male import Pullup_standard_data # 导入男子引体向上成绩计算模块
from flex_arm_hang_female import Flex_arm_hang_standard_data # 导入女子单杠曲臂悬垂的成绩计算模块
from situp_male import Situp_male_standard_data # 导入男子仰卧起坐成绩计算模块
from situp_female import Situp_female_standard_data # 导入女子仰卧起坐成绩计算模块
from serpentine_run_male import Serpentine_run_male_standard_data # 导入男子蛇形跑成绩计算模块
from serpentine_run_female import Serpentine_run_female_standard_data # 导入女子蛇形跑成绩计算模块
from highland2001up_3km_male import Highland2001up3kmMaleStandardData # 导入男子高原2001~3000,3000米成绩计算模块
from highland3001up_3km_male import Highland3001up3kmMaleStandardData # 导入男子高原3001~4000,3000米成绩计算模块
from highland2001up_3km_female import Highland2001up3kmFemaleStandardData # 导入女子高原2001~3000,3000米成绩计算模块
from highland3001up_3km_female import Highland3001up3kmFemaleStandardData # 导入女子高原2001~3000,3000米成绩计算模块
from flatland_3km import Flatland3kmStandardData # 导入男女平原3000米成绩计算模块
wb=openpyxl.load_workbook('通用训练课目考核成绩计算.xlsx')
ws_training_score = wb['体能考核成绩']
ws_personnel_parameters = wb['人员参数设置']
col_parameters = [c.value for c in list(ws_personnel_parameters.columns)[1][1:]]
staff_type = col_parameters[0] #人员类别
elevation = col_parameters[1] #地区海拔
if staff_type == '三类':
lowest_score = 55
if staff_type == '二类':
lowest_score = 60
if staff_type == '一类':
lowest_score = 65
pullup_sd = Pullup_standard_data() # 实例化男子引体向上成绩计算
flexarmhang_sd = Flex_arm_hang_standard_data() # 实例化女子单杠曲臂悬垂成绩计算
situp_male = Situp_male_standard_data() # 实例化男子仰卧起坐成绩计算
situp_female = Situp_female_standard_data() # 实例化男子仰卧起坐成绩计算
serpentine_run_male = Serpentine_run_male_standard_data() # 实例化男子蛇形跑成绩计算
serpentine_run_female = Serpentine_run_female_standard_data() # 实例化女子蛇形跑成绩计算
if elevation in range(0,2001):
long_distance_run_male = Flatland3kmStandardData('男') # 实例化男子平原3Km米跑计算模块
long_distance_run_female = Flatland3kmStandardData('女') # 实例化女子平原3Km米跑计算模块
elif elevation in range(2001,3001):
long_distance_run_male = Highland2001up3kmMaleStandardData(elevation) # 实例化男子高原海拔2001~3000米,3Km米跑计算模块
long_distance_run_female = Highland2001up3kmFemaleStandardData(elevation) # 实例化女子高原海拔2001~3000米,3Km米跑计算模块
elif elevation in range(3001,4001):
long_distance_run_male = Highland3001up3kmMaleStandardData(elevation) # 实例化男子高原海拔3001~4000米,3Km米跑计算模块
long_distance_run_female = Highland3001up3kmFemaleStandardData(elevation) # 实例化女子高原海拔3001~4000米,3Km米跑计算模块
rngs = ws_training_score.iter_rows(min_row=6)
for row in rngs:
gender = row[4].value # 性别
pullup = row[11].value # 单杠原始数量
situp = row[7].value # 仰卧起坐原始数量
serpentine_run = row[9].value # 蛇形跑原始数量
long_distance_run = row[13].value # 3Km跑原始时长
if row[5].value:
#print(row[5].value)
age = age_computing(row[5].value) #由出生日期计算年龄,精确到天
row[6].value = age
if gender == '男':
if row[6].value != None: # 年龄不能为空
if pullup != None: # 单杆原始数不能为空
score_pullup = pullup_sd.pullup_score_computing(age, pullup) # 计算男子单杠或俯卧撑成绩
#print(row[0].value,pullup,row[12].value) # 测试
if not score_pullup < lowest_score:
row[12].value = score_pullup
else:
row[12].value = 0
if situp != None: # 仰卧起坐原始数不能为空
score_situp = situp_male.situp_male_score_computing(age, situp) # 计算男子仰卧起坐成绩
#print(row[0].value, situp, row[8].value)
if not score_situp < lowest_score:
row[8].value = score_situp
else:
row[8].value = 0
if serpentine_run != None: # 蛇形跑原始数不能为空
score_serpentine_run = serpentine_run_male.serpentine_run_male_score_computing(age, serpentine_run) # 计算男子蛇形跑成绩
#print(row[0].value, serpentine_run, row[10].value)
if not score_serpentine_run < lowest_score:
row[10].value = score_serpentine_run
else:
row[10].value = 0
if long_distance_run != None: # 3Km跑原始时长不能为空
score_long_run = long_distance_run_male.longrun_score_computing(age, long_distance_run) # 计算男子3Km跑成绩
#print(row[0].value, long_distance_run, row[14].value)
if not score_long_run < lowest_score:
row[14].value = score_long_run
else:
row[14].value = 0
elif gender == '女':
if row[6].value != None:
if pullup != None: # 单杆原始数不能为空
score_pullup = flexarmhang_sd.flex_arm_hang_score_computing(age, pullup) # 女子曲臂悬垂或俯卧撑成绩计算
#print(row[0].value,pullup, row[12].value)
if not score_pullup < lowest_score:
row[12].value = score_pullup
else:
row[12].value = 0
if situp != None: # 仰卧起坐原始数不能为空
score_situp = situp_female.situp_female_score_computing(age, situp) # 计算女子仰卧起坐成绩
#print(row[0].value, situp, row[8].value)
if not score_situp < lowest_score:
row[8].value = score_situp
else:
row[8].value = 0
if serpentine_run != None: # 蛇形跑原始数不能为空
score_serpentine_run = serpentine_run_female.serpentine_run_female_score_computing(age, serpentine_run) # 计算女子蛇形跑成绩
#print(row[0].value, serpentine_run, row[10].value)
if not score_serpentine_run < lowest_score:
row[10].value = score_serpentine_run
else:
row[10].value = 0
if long_distance_run != None: # 3Km跑原始时长不能为空
score_long_run = long_distance_run_female.longrun_score_computing(age, long_distance_run) # 计算女子3Km跑成绩
#print(row[0].value, long_distance_run, row[14].value)
if not score_long_run < lowest_score:
row[14].value = score_long_run
else:
row[14].value = 0
else: # 性别输入有误
print('序号%d %s 的性别填写错误'%(row[0].value,row[1].value))
wb.save('计算结果.xlsx')
print('计算已完成!')
运行后,生成文件“计算结果.xlsx”如下:
海拔3701米3公里的计算结果
到此,我们成功实现了最复杂的3公里成绩计算的功能。