def drawCorrect(): x0,y0=getXt1AndXt2.readCsv('../static/file/20180921185434冷却曲线.csv') x,y = getXt1AndXt2.correct('../static/file/20180921185434冷却曲线.csv') xx = [x[0], x[-1]] yy = [y[0], y[-1]] print(yy) temp1=[] for i in range(len(x0)): temp={'x':x0[i],'y':y0[i]} temp1.append(temp) temp2={ 'start':{ 'x':xx[0], 'y':yy[0] }, 'end':{ 'x':xx[1], 'y':yy[1] } } print(temp2) datas={ 'data1':temp1, 'data2':temp2 } content = json.dumps(datas) resp = Response_headers(content) return resp
def hotGraph(filename, str): htext = '原始升温曲线' xtext = 'Temperature(℃)' ytext = 'Heatflow(a.u.)' x, y = getXt1AndXt2.readCsv(filename) cpValue = 'red' ptext = '升温曲线' drawPlot(htext, xtext, ytext, x, y, cpValue, ptext, str)
def drawCorrectOriginHeat(): x1, y1 = getHmAndTm.correctHot(path3, **kwargs) # 这个显示的是纠正后的数据 xx = [x1[0], x1[len(x1) - 1]] yy = [y1[0], y1[len(x1) - 1]] x0, y0 = getXt1AndXt2.readCsv(path3) temp1 = [] for i in range(len(x0)): temp = {'x': x0[i], 'y': y0[i]} temp1.append(temp) temp2 = { 'start': { 'x': xx[0], 'y': yy[0] }, 'end': { 'x': xx[1], 'y': yy[1] } } datas = {'data1': temp1, 'data2': temp2} return Response(json.dumps(datas), content_type='application/json')
def echarts(): x,y = getXt1AndXt2.readCsv('../static/file/20180921185434冷却曲线.csv') temp1=[] for i in range(len(x)): temp={'x':x[i],'y':y[i]} temp1.append(temp) # with open('../static/file/20180921185434冷却曲线.csv', encoding="UTF-8") as f: # datas = f.readlines() # temps = [] # for data in datas: # x, y = data.split(',') # temp={'x':x,'y':y} # temps.append(temp) # datas = { # "data": temps # } # print(temps) datas = { "data": temp1 } content = json.dumps(datas) resp = Response_headers(content) return resp
def correctHot(filename, **kwargs): x0, y0 = getXt1AndXt2.readCsv(filename) miny = y0.index(min(y0)) # 最低温度点 x = [] y = [] for i in range(len(y0)): y.append(-y0[i] / y0[miny] * 100) x.append(x0[i]) # 用来寻找终点b count = 0 for i in range(len(x)): count = count + 1 # count为5℃所包含的数据点 if x[i] - x[0] >= 5: break # 剔除升温数据温度最后5℃包含的数据点 for i in range(miny, len(x) - count, 1): xx = [x[i], x[i + count]] yy = [y[i], y[i + count]] a, b = optimize.curve_fit(f, xx, yy)[0] angle = math.atan(a) * 180 / math.pi # 将斜率转换为角度 # print("%f-%f:%f" % (x[i], x[i+count], angle)) if angle < 5: # 如果角度小于5,取该点为终点 temp1 = i break # 用来寻找起点a ang = [] # 去掉升温数据温度开始5℃的数据点 for i in range(miny, count + 1, -1): xx = [x[i - count], x[i]] yy = [y[i - count], y[i]] a, b = optimize.curve_fit(f, xx, yy)[0] angle = math.atan(a) * 180 / math.pi ang.append(angle) # print("%f-%f:%f"%(x[i-count],x[i],angle)) maxAng = max(ang) for i in range(len(ang)): if ang[i] == maxAng: temp = miny - i # 两个数据之间的位置换算 break # 在ab之间的点,存入x,y中 # print('correct') # print(x[temp], y[temp]) # print(x[temp1], y[temp1]) x1 = [] y1 = [] if ('heatStart' not in kwargs and 'heatEnd' not in kwargs): for i in range(temp, temp1 + 1): x1.append(x0[i]) y1.append(y0[i]) elif ('heatStart' in kwargs and 'heatEnd' in kwargs): for i in range(len(x)): if (abs(x[i] - kwargs['heatStart']) < 0.001): flag1 = i break for i in range(len(x)): if (abs(x[i] - kwargs['heatEnd']) < 0.001): flag2 = i break for i in range(flag1, flag2 + 1): x1.append(x0[i]) y1.append(y0[i]) else: if ('heatStart' in kwargs): for i in range(len(x)): if (abs(x[i] - kwargs['heatStart']) < 0.01): flag = i break for i in range(flag, temp1 + 1): x1.append(x0[i]) y1.append(y0[i]) else: for i in range(len(x)): if (abs(x[i] - kwargs['heatEnd']) < 0.01): flag = i break for i in range(temp, flag + 1): x1.append(x0[i]) y1.append(y0[i]) print(x1[0], x1[-1]) return x1, y1