|
@@ -141,7 +141,7 @@ def autoColumns(url):
|
|
|
# 频度分析函数 公用
|
|
|
def frequency_analysis(arr):
|
|
|
qua_2 = arr.quantile(0.02)
|
|
|
- print(1.55)
|
|
|
+
|
|
|
qua_5 = arr.quantile(0.05)
|
|
|
qua_10 = arr.quantile(0.1)
|
|
|
qua_20 = arr.quantile(0.2)
|
|
@@ -152,10 +152,10 @@ def frequency_analysis(arr):
|
|
|
qua_98 = arr.quantile(0.98)
|
|
|
min_value = arr.min()
|
|
|
max_value = arr.max()
|
|
|
- print(1.6)
|
|
|
+
|
|
|
median_value = arr.median() # 中位数
|
|
|
jc_value = arr.max() - arr.min() # 极差
|
|
|
- print(1.7)
|
|
|
+
|
|
|
std_value = arr.std() # 标准差
|
|
|
mean_value = arr.mean() # 平均数
|
|
|
variation_value = std_value / mean_value # 变异系数 = 标准差/均值
|
|
@@ -167,7 +167,7 @@ def frequency_analysis(arr):
|
|
|
# 汇总数据
|
|
|
data.index = index_value
|
|
|
data_res = round(data, 2)
|
|
|
- print('data_res', data_res)
|
|
|
+
|
|
|
return data_res
|
|
|
|
|
|
# 绘图函数
|
|
@@ -280,7 +280,7 @@ def checkData(fileUrl):
|
|
|
global checkType
|
|
|
checkType = type
|
|
|
data = pd.read_excel(fileUrl,converters={'原样品编号': str})
|
|
|
- print('fileUrl', data['总砷'])
|
|
|
+
|
|
|
if type == 'OVER_LINE':
|
|
|
show_error('试用已结束,使用更多请点击下方获取申请码按钮联系管理员!')
|
|
|
elif type == 'HUNDRED_DATA' or type == 'ALL':
|
|
@@ -296,7 +296,7 @@ def checkData(fileUrl):
|
|
|
simpleData = data.dropna(subset=['原样品编号'])
|
|
|
global originData
|
|
|
originData = pd.read_excel(fileUrl, dtype='str')
|
|
|
- print('originData---', originData)
|
|
|
+
|
|
|
simpleData = simpleData[~simpleData['原样品编号'].str.contains('ZK')]
|
|
|
simpleData = simpleData.replace(r'[^.\w]+', '', regex=True)
|
|
|
# print('simpleData',simpleData)
|
|
@@ -307,7 +307,7 @@ def checkData(fileUrl):
|
|
|
if i not in strList:
|
|
|
simpleData[i] = pd.to_numeric(simpleData[i], errors='coerce')
|
|
|
# 处理重复样品
|
|
|
- print('to--num', simpleData)
|
|
|
+
|
|
|
res = getRepeat(simpleData)
|
|
|
simpleData = simpleData._append(res).drop_duplicates(subset=['原样品编号'], keep='last')
|
|
|
jCData = simpleData[['土壤容重1(g/cm³)', '土壤容重2(g/cm³)', '土壤容重3(g/cm³)', '土壤容重4(g/cm³)']]
|
|
@@ -324,6 +324,7 @@ def checkData(fileUrl):
|
|
|
# ---------------表1----------数据汇总
|
|
|
resData = pd.DataFrame({
|
|
|
'编号': simpleData['原样品编号'],
|
|
|
+ '样品编号': simpleData['样品编号'],
|
|
|
'地理位置': simpleData['地理位置'],
|
|
|
'土壤类型': simpleData['土壤类型'],
|
|
|
'土地利用类型': simpleData['土地利用类型'],
|
|
@@ -345,6 +346,7 @@ def checkData(fileUrl):
|
|
|
'加和%': plusData,
|
|
|
'pH': simpleData['pH']
|
|
|
})
|
|
|
+
|
|
|
# 调用审核函数 得到审核结果
|
|
|
table_1_res = pb.soil_bulk_density(resData)
|
|
|
resData = resData.reset_index(drop=True)
|
|
@@ -361,8 +363,8 @@ def checkData(fileUrl):
|
|
|
# '指标': table_1_res['异常指标'],
|
|
|
# '原因': table_1_res['审核结果']
|
|
|
# })
|
|
|
- table_1_index['原样品编号'] = simpleData['原样品编号']
|
|
|
- table_1_index['样品编号'] = simpleData['样品编号']
|
|
|
+ table_1_index['原样品编号'] = resData['编号']
|
|
|
+ table_1_index['样品编号'] = resData['样品编号']
|
|
|
table_1_index['土地利用类型'] = resData['土地利用类型']
|
|
|
table_1_index['指标'] = table_1_res['异常指标']
|
|
|
table_1_index['原因'] = table_1_res['审核结果']
|
|
@@ -383,9 +385,7 @@ def checkData(fileUrl):
|
|
|
'0.002mm以下颗粒含量%': simpleData['0.002mm以下颗粒含量']
|
|
|
})
|
|
|
global resData_2
|
|
|
- print(1.5)
|
|
|
resData_2 = frequency_analysis(data_2)
|
|
|
- print(2)
|
|
|
# 表3--------------------------表3水稳性大团聚体数据汇总----------------------------------------
|
|
|
# 数据计算 这里数据暂时还没有 数据获取到以后再进行测试
|
|
|
resData_3 = pd.DataFrame({
|
|
@@ -416,16 +416,17 @@ def checkData(fileUrl):
|
|
|
# '指标': res_3_v['异常指标'],
|
|
|
# '原因': res_3_v['审核结果']
|
|
|
# })
|
|
|
- table_3_index['样品编号'] = simpleData['样品编号']
|
|
|
+
|
|
|
+ # table_3_index['样品编号'] = simpleData['样品编号']
|
|
|
table_3_index['指标'] = res_3_v['异常指标']
|
|
|
table_3_index['原因'] = res_3_v['审核结果']
|
|
|
resData_3_Style = resData_3.style.apply(highlight_condition, axis=1)
|
|
|
# 表4--------------------------表4 水稳性大团聚体频度分析-----------------------
|
|
|
- print(3)
|
|
|
+
|
|
|
resData_4_need = resData_3[['总和(%)','>5mm%','3-5mm%','2-3mm%','1-2mm%','0.5-1mm%','0.25-0.5mm%']]
|
|
|
global resData_4
|
|
|
resData_4 = frequency_analysis(resData_4_need)
|
|
|
- print(3.1)
|
|
|
+
|
|
|
# 表5--------------------------表5pH、阳离子交换量、交换性盐基基础数据收集----------------------------------------
|
|
|
forPlus = simpleData['交换性钙'] + simpleData['交换性镁'] + simpleData['交换性钾'] + simpleData['交换性钠']
|
|
|
resData_5 = pd.DataFrame({
|
|
@@ -443,28 +444,29 @@ def checkData(fileUrl):
|
|
|
'阳交量与交盐量差': simpleData['阳离子交换量'] - simpleData['交换性盐基总量'],
|
|
|
'盐基饱和度%': simpleData['交换性盐基总量'] / simpleData['阳离子交换量'] # 交换性盐基/阳离子交换量
|
|
|
})
|
|
|
- print(3.2)
|
|
|
+
|
|
|
resData_5 = resData_5.reset_index(drop=True)
|
|
|
res_5_v = pb.cation_value(resData_5)
|
|
|
- print(3.3)
|
|
|
- print('res_5_v', res_5_v)
|
|
|
+
|
|
|
+
|
|
|
resData_5['审核结果'] = res_5_v['审核结果']
|
|
|
global resData_5_Style
|
|
|
global table_5_data
|
|
|
table_5_data = resData_5
|
|
|
# 提取异常数据
|
|
|
- print(3.5)
|
|
|
+
|
|
|
global table_5_index
|
|
|
# table_5_index = pd.DataFrame({
|
|
|
# '样品编号': simpleData['样品编号'],
|
|
|
# '指标': res_5_v['异常指标'],
|
|
|
# '原因': res_5_v['审核结果']
|
|
|
# })
|
|
|
- table_5_index['样品编号'] = simpleData['样品编号']
|
|
|
+ # table_5_index['样品编号'] = simpleData['样品编号']
|
|
|
table_5_index['指标'] = res_5_v['异常指标']
|
|
|
table_5_index['原因'] = res_5_v['审核结果']
|
|
|
+
|
|
|
resData_5_Style = resData_5.style.apply(highlight_condition, axis=1)
|
|
|
- print(4)
|
|
|
+
|
|
|
# 表6--------------------------表6----------------------------------------
|
|
|
global resData_6
|
|
|
resData_6 = frequency_analysis(resData_5[['pH']])
|
|
@@ -526,11 +528,11 @@ def checkData(fileUrl):
|
|
|
# '指标': res_value_8['异常指标'],
|
|
|
# '原因': res_value_8['审核结果']
|
|
|
# })
|
|
|
- table_8_index['样品编号'] = simpleData['样品编号']
|
|
|
+ # table_8_index['样品编号'] = simpleData['样品编号']
|
|
|
table_8_index['指标'] = res_value_8['异常指标']
|
|
|
table_8_index['原因'] = res_value_8['审核结果']
|
|
|
resData_8_Style = resData_8.style.apply(highlight_condition, axis=1)
|
|
|
- print(5)
|
|
|
+
|
|
|
# 表7--------------------------表7 数据频度分析----------------------------------------
|
|
|
global resData_7
|
|
|
resData_7 = frequency_analysis(resData_8[['水溶性全盐量g/kg', '电导率ms/cm']])
|
|
@@ -555,7 +557,7 @@ def checkData(fileUrl):
|
|
|
res_value_10 = pb.nutrient_data(resData_10)
|
|
|
resData_10 = resData_10.reset_index(drop=True)
|
|
|
resData_10['审核结果'] = res_value_10['审核结果']
|
|
|
- print(6)
|
|
|
+
|
|
|
# 写入表格
|
|
|
global resData_10_Style
|
|
|
global table_10_data
|
|
@@ -567,7 +569,7 @@ def checkData(fileUrl):
|
|
|
# '指标': res_value_10['异常指标'],
|
|
|
# '原因': res_value_10['审核结果']
|
|
|
# })
|
|
|
- table_10_index['样品编号'] = simpleData['样品编号']
|
|
|
+ # table_10_index['样品编号'] = simpleData['样品编号']
|
|
|
table_10_index['指标'] = res_value_10['异常指标']
|
|
|
table_10_index['原因'] = res_value_10['审核结果']
|
|
|
resData_10_Style = resData_10.style.apply(highlight_condition, axis=1)
|
|
@@ -613,11 +615,11 @@ def checkData(fileUrl):
|
|
|
# '指标': res_value_12['异常指标'],
|
|
|
# '原因': res_value_12['审核结果']
|
|
|
# })
|
|
|
- table_12_index['样品编号'] = simpleData['样品编号']
|
|
|
+ # table_12_index['样品编号'] = simpleData['样品编号']
|
|
|
table_12_index['指标'] = res_value_12['异常指标']
|
|
|
table_12_index['原因'] = res_value_12['审核结果']
|
|
|
resData_12_Style = resData_12.style.apply(highlight_condition, axis=1)
|
|
|
- print(7)
|
|
|
+
|
|
|
# 写入表格
|
|
|
# 表11--------------------------表11 土壤指标频度分析----------------------------------------
|
|
|
global resData_11
|
|
@@ -651,17 +653,17 @@ def checkData(fileUrl):
|
|
|
# '指标': res_value_14['异常指标'],
|
|
|
# '原因': res_value_14['审核结果']
|
|
|
# })
|
|
|
- table_14_index['样品编号'] = simpleData['样品编号']
|
|
|
+ # table_14_index['样品编号'] = simpleData['样品编号']
|
|
|
table_14_index['指标'] = res_value_14['异常指标']
|
|
|
table_14_index['原因'] = res_value_14['审核结果']
|
|
|
resData_14_Style = resData_14.style.apply(highlight_condition, axis=1)
|
|
|
# 写入表格
|
|
|
# 表13--------------------------表13 土壤重金属频度分析----------------------------------------
|
|
|
global resData_13
|
|
|
- print('resData_13---1', resData_13)
|
|
|
+
|
|
|
resData_13 = frequency_analysis(
|
|
|
resData_14[['镉mg/kg', '汞mg/kg', '砷mg/kg', '铅mg/kg', '铬mg/kg', '镍mg/kg']])
|
|
|
- print('resData_13--', resData_13)
|
|
|
+
|
|
|
show_info('文件审核完成,请点击保存按钮保存文件!')
|
|
|
else:
|
|
|
#提示文件为空 重新选择
|
|
@@ -676,6 +678,7 @@ def makeNormalWord(url):
|
|
|
length = len(table_1_index)
|
|
|
emptyArr = [np.nan for i in range(length)]
|
|
|
indexArr = pd.RangeIndex(start=1, stop=length+1)
|
|
|
+
|
|
|
newData = pd.DataFrame({
|
|
|
'序号': indexArr,
|
|
|
'原样品编号': table_1_index['原样品编号'],
|
|
@@ -687,7 +690,7 @@ def makeNormalWord(url):
|
|
|
'数据判定': emptyArr
|
|
|
})
|
|
|
newData = newData.replace(np.nan, '')
|
|
|
- print(newData)
|
|
|
+ print('newData----', newData)
|
|
|
name = os.path.basename(changeFileUrl)
|
|
|
n = name.split('.')
|
|
|
areaName = n[0].replace('数据', '')
|
|
@@ -872,7 +875,7 @@ def getReport(originData,data,changeFileUrl, saveFileUrl, check_1_data,
|
|
|
# 附表: 频度分析图
|
|
|
report.getFrequencyImage(data, mkdir_path)
|
|
|
table_f_2_data = report.getFrequencyInformation(data, mkdir_path)
|
|
|
- print('table_f_2_data---', table_f_2_data)
|
|
|
+
|
|
|
# 新建一个文档
|
|
|
doc = Document()
|
|
|
# 添加标题
|
|
@@ -1404,8 +1407,7 @@ def getReport(originData,data,changeFileUrl, saveFileUrl, check_1_data,
|
|
|
paragraph.add_run('')
|
|
|
elif len(columnsList) >= 10 and i > columnsList[9] and i <= 60:
|
|
|
if len(dataList[9].columns) > j:
|
|
|
- print(dataList[9].columns)
|
|
|
- print(str(dataList[9].iloc[i - 55, j]))
|
|
|
+
|
|
|
r = paragraph.add_run(str(dataList[9].iloc[i - 55, j]))
|
|
|
r.font.size = Pt(10.5)
|
|
|
r.font.name = 'Times New Roman'
|
|
@@ -1569,7 +1571,6 @@ def dealData(data):
|
|
|
simpleData = data.dropna(subset=['原样品编号'])
|
|
|
simpleData = simpleData[~simpleData['原样品编号'].str.contains('ZK')]
|
|
|
simpleData = simpleData.replace(r'[^.\w]+', '', regex=True)
|
|
|
- # print('simpleData',simpleData)
|
|
|
simpleData = simpleData.replace('未检测', np.nan)
|
|
|
simpleData = simpleData.replace('', np.nan)
|
|
|
# simpleData.iloc[:, 3:] = simpleData.iloc[:, 3:].apply(pd.to_numeric, errors='ignore')
|