把c#代码转为python c#代码private void CalculatePartial_AvgVelocity_Width() { int index = -1; List<Result_Line> vLines = ResultLineList.Where(line => line.VLineOrder != null).ToList(); for (int i = 0; i < vLines.Count; i++) { index = ResultLineList.IndexOf(vLines[i]); if (vLines[i].VLineOrder == -9999) { continue; } else if (vLines[i - 1].VLineOrder == -9999) { //float leftAlpha = GetInshoreCoefficient(-9999, vLines[i].WaterLvl); float leftAlpha = NumValid.PrecisionConvert_Coefficient(GetInshoreCoefficient(-9999, vLines[i - 1].InitPointDistance)); vLines[i].PartialAvgVelocity = NumValid.PrecisionConvert_Velocity((float)(leftAlpha * vLines[i].AvgVelocity)); } else if (vLines[i].VLineOrder == 9999) { //float rightAlpha = GetInshoreCoefficient(9999, vLines[i].WaterLvl); float rightAlpha = NumValid.PrecisionConvert_Coefficient(GetInshoreCoefficient(9999, vLines[i].InitPointDistance)); vLines[i].PartialAvgVelocity = NumValid.PrecisionConvert_Velocity((float)(rightAlpha * vLines[i - 1].AvgVelocity)); } else { var temp = (vLines[i - 1].AvgVelocity + vLines[i].AvgVelocity) / 2f; vLines[i].PartialAvgVelocity = NumValid.PrecisionConvert_Velocity((float)temp); } ResultLineList[index] = vLines[i]; ResultLineList[index].WidthBetweenVLine = NumValid.PrecisionConvert_Width(vLines[i].InitPointDistance - vLines[i - 1].InitPointDistance); } }
时间: 2024-04-23 07:24:08 浏览: 75
将C#代码转换为Python代码如下:
def CalculatePartial_AvgVelocity_Width():
index = -1
vLines = list(filter(lambda line: line.VLineOrder != None, ResultLineList))
for i in range(len(vLines)):
index = ResultLineList.index(vLines[i])
if vLines[i].VLineOrder == -9999:
continue
elif vLines[i - 1].VLineOrder == -9999:
leftAlpha = NumValid.PrecisionConvert_Coefficient(GetInshoreCoefficient(-9999, vLines[i - 1].InitPointDistance))
vLines[i].PartialAvgVelocity = NumValid.PrecisionConvert_Velocity(float(leftAlpha * vLines[i].AvgVelocity))
elif vLines[i].VLineOrder == 9999:
rightAlpha = NumValid.PrecisionConvert_Coefficient(GetInshoreCoefficient(9999, vLines[i].InitPointDistance))
vLines[i].PartialAvgVelocity = NumValid.PrecisionConvert_Velocity(float(rightAlpha * vLines[i - 1].AvgVelocity))
else:
temp = (vLines[i - 1].AvgVelocity + vLines[i].AvgVelocity) / 2.0
vLines[i].PartialAvgVelocity = NumValid.PrecisionConvert_Velocity(float(temp))
ResultLineList[index] = vLines[i]
ResultLineList[index].WidthBetweenVLine = NumValid.PrecisionConvert_Width(vLines[i].InitPointDistance - vLines[i - 1].InitPointDistance)
阅读全文