200 lines
11 KiB
Python
200 lines
11 KiB
Python
import numpy as np
|
|
import pandas as pd
|
|
import pdfplumber
|
|
import warnings
|
|
import sys
|
|
|
|
pdf = pdfplumber.open('军事体育五项标准.pdf', password='456456')
|
|
|
|
|
|
class Military:
|
|
# globalVar input
|
|
manBodyShape_Page_list = [0, 1]
|
|
womanBodyShape_Page_list = [2, 3]
|
|
|
|
manBodyShape_comparisonTable_list = [list(filter(None, _i)) for item in manBodyShape_Page_list for _i in
|
|
pdf.pages[item].extract_table()]
|
|
manBodyShape_columnName_list = manBodyShape_comparisonTable_list[0][2:]
|
|
manBodyShape_columnName_list[0] = '0~24岁'
|
|
manBodyShape_comparisonTable_ar = np.array([item for item in manBodyShape_comparisonTable_list if
|
|
'公式' not in item and '说明' not in item and r'24岁以下' not in item])
|
|
manBodyShape_rowName_ar = np.array(
|
|
[item.replace(' ', '') for item in manBodyShape_comparisonTable_ar[:, 0]]).astype(
|
|
float)
|
|
manBodyShape_data_ar = np.array([[[float(_j) for _j in _i.replace(' ', '').split("~")] for _i in item] for item in
|
|
manBodyShape_comparisonTable_ar[:, 1:]])
|
|
manBodyShape_df = pd.DataFrame(columns=manBodyShape_columnName_list, index=manBodyShape_rowName_ar)
|
|
for index, col in enumerate(manBodyShape_columnName_list):
|
|
manBodyShape_df[col] = list(manBodyShape_data_ar[:, index])
|
|
|
|
womanBodyShape_comparisonTable_list = [list(filter(None, _i)) for item in womanBodyShape_Page_list for _i in
|
|
pdf.pages[item].extract_table()]
|
|
womanBodyShape_columnName_list = womanBodyShape_comparisonTable_list[0][2:]
|
|
womanBodyShape_columnName_list[0] = '0~24岁'
|
|
womanBodyShape_comparisonTable_ar = np.array([item for item in womanBodyShape_comparisonTable_list if
|
|
'公式' not in item and '说明' not in item and r'24岁以下' not in item])
|
|
womanBodyShape_rowName_ar = np.array(
|
|
[item.replace(' ', '') for item in womanBodyShape_comparisonTable_ar[:, 0]]).astype(
|
|
float)
|
|
womanBodyShape_data_ar = np.array([[[float(_j) for _j in _i.replace(' ', '').split("~")] for _i in item] for item in
|
|
womanBodyShape_comparisonTable_ar[:, 1:]])
|
|
womanBodyShape_df = pd.DataFrame(columns=womanBodyShape_columnName_list, index=womanBodyShape_rowName_ar)
|
|
for index, col in enumerate(womanBodyShape_columnName_list):
|
|
womanBodyShape_df[col] = list(womanBodyShape_data_ar[:, index])
|
|
|
|
man60mSerpentineRun_df = pd.read_excel('man60mSerpentineRun.xlsx', index_col=0)
|
|
man3000mRun_df = pd.read_excel('man3000mRun.xlsx', index_col=0)
|
|
manBodyChinUpsPushUps_df = pd.read_excel('manBodyChinUpsPushUps.xlsx', index_col=0)
|
|
manSitUps_df = pd.read_excel('manSitUps.xlsx', index_col=0)
|
|
woman60mSerpentineRun_df = pd.read_excel('woman60mSerpentineRun.xlsx', index_col=0)
|
|
woman3000mRun_df = pd.read_excel('woman3000mRun.xlsx', index_col=0)
|
|
womanBodyArmDrapePushUps_df = pd.read_excel('womanBodyArmDrapePushUps.xlsx', index_col=0)
|
|
womanSitUps_df = pd.read_excel('womanSitUps.xlsx', index_col=0)
|
|
|
|
shapeAgeRange_ar = np.array(
|
|
[[int(item.split('~')[0]), int(item.split('~')[1][:-1])] for item in list(manBodyShape_df.columns)])
|
|
projectAgeRange_ar = np.array([[int(_i) for _i in item.split('~')] for item in list(man3000mRun_df.columns)])
|
|
|
|
sexCompare_dict = {'man': {'BodyShape': manBodyShape_df, 'SitUps': manSitUps_df,
|
|
'integratedProject': manBodyChinUpsPushUps_df, '3000mRun': man3000mRun_df,
|
|
'60mSerpentineRun': man60mSerpentineRun_df},
|
|
'woman': {'SitUps': womanSitUps_df, 'BodyShape': womanBodyShape_df,
|
|
'integratedProject': womanBodyArmDrapePushUps_df,
|
|
'3000mRun': woman3000mRun_df,
|
|
'60mSerpentineRun': woman60mSerpentineRun_df}}
|
|
|
|
shapeAgeIndex_dict = {index: item for index, item in enumerate(manBodyShape_df.columns)}
|
|
projectAgeIndex_dict = {index: item for index, item in enumerate(man3000mRun_df.columns)}
|
|
|
|
projectScore_dict = {0: 100, 1: 95, 2: 90, 3: 85, 4: 80, 5: 75, 6: 70, 7: 65, 8: 60, 9: 55}
|
|
|
|
def __init__(self, sex, age, high=None, weight=None, integratedProjectResult=None, sitUpsResult=None,
|
|
serpentine60RunResult=None, longDistance3000mRunResult=None):
|
|
'''
|
|
初始化参数
|
|
:param sex: 性别
|
|
:param testResults_list: 定义为测试结果, [身高(m), 体重(kg), 综合项目, 仰卧起坐, 30m*2蛇形跑(s), 3000m跑(s)]
|
|
'''
|
|
self.sex = sex
|
|
self.age = age
|
|
if self.sex != 'woman' and self.sex != 'man':
|
|
warnings.warn('性别错误')
|
|
sys.exit()
|
|
self.high = high
|
|
self.weight = weight
|
|
self.integratedProjectResult = integratedProjectResult
|
|
self.sitUpsResult = sitUpsResult
|
|
self.serpentine60RunResult = serpentine60RunResult
|
|
self.longDistance3000mRunResult = longDistance3000mRunResult
|
|
|
|
# 分数评估用
|
|
self.shapeAgeIndex = [True if self.age >= item[0] and self.age <= item[1] else False for item in
|
|
Military.shapeAgeRange_ar].index(True)
|
|
self.projectAgeIndex = [True if self.age >= item[0] and self.age <= item[1] else False for item in
|
|
Military.projectAgeRange_ar].index(True)
|
|
self.shapeAge = Military.shapeAgeIndex_dict[self.shapeAgeIndex]
|
|
self.projectAge = Military.projectAgeIndex_dict[self.projectAgeIndex]
|
|
|
|
def ShapeScoreEvaluation(self):
|
|
'''
|
|
评估体重是否超标
|
|
:return: weightScore
|
|
'''
|
|
# 评估体重是否合格
|
|
if Military.sexCompare_dict[self.sex]['BodyShape'].loc[self.high, self.shapeAge][0] > self.weight:
|
|
weightScore = '偏小'
|
|
elif Military.sexCompare_dict[self.sex]['BodyShape'].loc[self.high, self.shapeAge][1] < self.weight:
|
|
weightScore = '偏大'
|
|
else:
|
|
weightScore = '合格'
|
|
return weightScore
|
|
|
|
def IntegratedProjectScoreEvaluation(self):
|
|
'''
|
|
评估综合项目得分
|
|
:return: integratedProjectScore
|
|
'''
|
|
# 评估综合项目分数
|
|
if self.integratedProjectResult > Military.sexCompare_dict[self.sex]['integratedProject'].loc[100,
|
|
self.projectAge]:
|
|
if self.projectAgeIndex > 5:
|
|
integratedProjectScore = 100 + int((self.integratedProjectResult -
|
|
Military.sexCompare_dict[self.sex]['integratedProject'].loc[
|
|
100, self.projectAge]) / 2)
|
|
else:
|
|
if self.sex == 'man':
|
|
integratedProjectScore = 100 + self.integratedProjectResult - \
|
|
Military.sexCompare_dict[self.sex]['integratedProject'].loc[
|
|
100, self.projectAge]
|
|
else:
|
|
integratedProjectScore = 100 + int((self.integratedProjectResult -
|
|
Military.sexCompare_dict[self.sex]['integratedProject'].loc[
|
|
100, self.projectAge]) / 5)
|
|
elif self.integratedProjectResult < Military.sexCompare_dict[self.sex]['integratedProject'].loc[
|
|
55, self.projectAge]:
|
|
integratedProjectScore = '不合格'
|
|
else:
|
|
integratedProjectResult_ar = np.array(Military.sexCompare_dict[self.sex]['integratedProject'].loc[:,
|
|
self.projectAge]) <= self.integratedProjectResult
|
|
integratedProjectScore = Military.projectScore_dict[np.where(integratedProjectResult_ar == 1)[0][0]]
|
|
return integratedProjectScore
|
|
|
|
def SitUpsScoreEvaluation(self):
|
|
'''
|
|
评估仰卧起坐项目得分
|
|
:return: sitUpsScore
|
|
'''
|
|
# 评估仰卧起坐分数
|
|
if self.sitUpsResult > Military.sexCompare_dict[self.sex]['SitUps'].loc[100, self.projectAge]:
|
|
sitUpsScore = 100 + int(
|
|
(self.sitUpsResult - Military.sexCompare_dict[self.sex]['SitUps'].loc[100, self.projectAge]) / 2)
|
|
elif self.sitUpsResult < Military.sexCompare_dict[self.sex]['SitUps'].loc[55, self.projectAge]:
|
|
sitUpsScore = '不合格'
|
|
else:
|
|
sitUpsResult_ar = np.array(
|
|
Military.sexCompare_dict[self.sex]['SitUps'].loc[:, self.projectAge]) <= self.sitUpsResult
|
|
sitUpsScore = Military.projectScore_dict[np.where(sitUpsResult_ar == 1)[0][0]]
|
|
return sitUpsScore
|
|
|
|
def Serpentine60RunScoreEvaluation(self):
|
|
'''
|
|
评估30m*2蛇形跑项目得分
|
|
:return: serpentine60RunScore
|
|
'''
|
|
# 评估蛇形跑分数
|
|
if self.serpentine60RunResult < Military.sexCompare_dict[self.sex]['60mSerpentineRun'].loc[
|
|
100, self.projectAge]:
|
|
serpentine60RunScore = 100 + int((Military.sexCompare_dict[self.sex]['60mSerpentineRun'].loc[
|
|
100, self.projectAge] - self.serpentine60RunResult) / 0.1)
|
|
elif self.serpentine60RunResult > Military.sexCompare_dict[self.sex]['60mSerpentineRun'].loc[
|
|
55, self.projectAge]:
|
|
serpentine60RunScore = '不合格'
|
|
else:
|
|
serpentine60RunResult_ar = np.array(Military.sexCompare_dict[self.sex]['60mSerpentineRun'].loc[:,
|
|
self.projectAge]) >= self.serpentine60RunResult
|
|
serpentine60RunScore = Military.projectScore_dict[np.where(serpentine60RunResult_ar == 1)[0][0]]
|
|
return serpentine60RunScore
|
|
|
|
def longDistance3000mScoreEvaluation(self):
|
|
'''
|
|
评估3000m长跑项目得分
|
|
:return: longDistance3000mScore
|
|
'''
|
|
# 评估3000m跑分数
|
|
if self.longDistance3000mRunResult < Military.sexCompare_dict[self.sex]['3000mRun'].loc[100, self.projectAge]:
|
|
longDistance3000mScore = 100 + int((Military.sexCompare_dict[self.sex]['3000mRun'].loc[
|
|
100, self.projectAge] - self.longDistance3000mRunResult) / 5)
|
|
elif self.longDistance3000mRunResult > Military.sexCompare_dict[self.sex]['3000mRun'].loc[55, self.projectAge]:
|
|
longDistance3000mScore = '不合格'
|
|
else:
|
|
longDistance3000mRunResult_ar = np.array(Military.sexCompare_dict[self.sex]['3000mRun'].loc[:,
|
|
self.projectAge]) >= self.longDistance3000mRunResult
|
|
longDistance3000mScore = Military.projectScore_dict[np.where(longDistance3000mRunResult_ar == 1)[0][0]]
|
|
return longDistance3000mScore
|
|
|
|
|
|
if __name__ == '__main__':
|
|
test = Military('man', 8, serpentine60RunResult=19.6)
|
|
# print(test.Serpentine60RunScoreEvaluation())
|
|
tes1t = Military('man', 25, longDistance3000mRunResult=690).longDistance3000mScoreEvaluation()
|
|
print(tes1t) |