fix:消息
This commit is contained in:
64
project/get_curve_params.py
Normal file
64
project/get_curve_params.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import json
|
||||
|
||||
# def is_number(str):
|
||||
# try:
|
||||
# float(str)
|
||||
# return True
|
||||
# except ValueError:
|
||||
# return False
|
||||
|
||||
def is_number(string):
|
||||
""" 判断字符串是否为数字类型 """
|
||||
pattern = re.compile(r'^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$')
|
||||
return bool(pattern.match(string))
|
||||
|
||||
def get_curve_unit(string):
|
||||
xUnit = ''
|
||||
yUnit = ''
|
||||
xPhysics = ''
|
||||
yPhysics = ''
|
||||
|
||||
try:
|
||||
unit_dict = json.loads(string)
|
||||
xUnit = unit_dict.get('xUnit')
|
||||
yUnit = unit_dict.get('yUnit')
|
||||
xPhysics = unit_dict.get('xPhysics')
|
||||
yPhysics = unit_dict.get('yPhysics')
|
||||
except:
|
||||
pass
|
||||
|
||||
return xUnit, yUnit, xPhysics, yPhysics
|
||||
|
||||
|
||||
def get_curve_params(curvePath, decimal):
|
||||
""" 获取曲线文件最大最小值 """
|
||||
valueList = []
|
||||
with open(curvePath, 'r+', encoding='utf-8') as fr:
|
||||
lines = fr.readlines()
|
||||
for line in lines:
|
||||
if line.__contains__(','):
|
||||
yValue = line.split(',')[1]
|
||||
if(is_number(yValue)):
|
||||
valueList.append(float(yValue))
|
||||
|
||||
maxValue = round(max(valueList), decimal)
|
||||
minValue = round(min(valueList), decimal)
|
||||
|
||||
xUnit, yUnit, xPhysics, yPhysics = get_curve_unit(lines[0])
|
||||
curve_params = {"max":maxValue, "min":minValue, "xUnit":xUnit, "yUnit":yUnit, "xPhysics":xPhysics, "yPhysics":yPhysics}
|
||||
print(json.dumps(curve_params, ensure_ascii=False))
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
# 曲线文件路径
|
||||
curvePath = sys.argv[1]
|
||||
# 保留小数点位数
|
||||
try:
|
||||
decimal = int(sys.argv[2])
|
||||
except:
|
||||
decimal = 3
|
||||
|
||||
get_curve_params(curvePath, decimal)
|
||||
@@ -21,7 +21,20 @@ public class CurveParamDto {
|
||||
@Schema(description = "最小值")
|
||||
private Double min;
|
||||
|
||||
@JsonProperty("unit")
|
||||
@Schema(description = "单位")
|
||||
private String unit;
|
||||
@JsonProperty("xUnit")
|
||||
@Schema(description = "x轴单位")
|
||||
private String xUnit;
|
||||
|
||||
@JsonProperty("xPhysics")
|
||||
@Schema(description = "x轴物理量")
|
||||
private String xPhysics;
|
||||
|
||||
@JsonProperty("yUnit")
|
||||
@Schema(description = "y轴单位")
|
||||
private String yUnit;
|
||||
|
||||
@JsonProperty("yPhysics")
|
||||
@Schema(description = "y轴物理量")
|
||||
private String yPhysics;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user