|
@@ -49,11 +49,11 @@ class GeneratorSpeedTorqueAnalyst(AnalystWithGoodPoint):
|
|
|
currDataFrameOfTurbines[Field_NameOfTurbine] = currDataFrameOfTurbines[Field_CodeOfTurbine].map(currTurbineInfos_dict).fillna("")
|
|
|
|
|
|
result2D = self.drawScatter2DMonthly(
|
|
|
- currDataFrameOfTurbines, outputAnalysisDir, conf)
|
|
|
+ currDataFrameOfTurbines, outputAnalysisDir, conf,currTurbineModeInfo)
|
|
|
returnDatas.extend(result2D)
|
|
|
|
|
|
result3D = self.drawScatterGraph(
|
|
|
- currDataFrameOfTurbines, outputAnalysisDir, conf)
|
|
|
+ currDataFrameOfTurbines, outputAnalysisDir, conf,currTurbineModeInfo)
|
|
|
returnDatas.extend(result3D)
|
|
|
|
|
|
resultTotal = self.drawScatterGraphForTurbines(
|
|
@@ -64,7 +64,7 @@ class GeneratorSpeedTorqueAnalyst(AnalystWithGoodPoint):
|
|
|
|
|
|
return returnDataFrame
|
|
|
|
|
|
- def drawScatter2DMonthlyOfTurbine(self, dataFrame: pd.DataFrame, outputAnalysisDir: str, conf: Contract, turbineName: str):
|
|
|
+ def drawScatter2DMonthlyOfTurbine(self, dataFrame: pd.DataFrame, turbineModelInfo: pd.Series, outputAnalysisDir: str, conf: Contract, name: str):
|
|
|
# 设置颜色条参数
|
|
|
dataFrame = dataFrame.sort_values(by=Field_YearMonth)
|
|
|
|
|
@@ -103,7 +103,7 @@ class GeneratorSpeedTorqueAnalyst(AnalystWithGoodPoint):
|
|
|
# 以下是以比例方式进行色彩的可视化处理
|
|
|
fig.update_layout(
|
|
|
title={
|
|
|
- "text": f'月度发电机转速扭矩散点图: {turbineName}',
|
|
|
+ "text": f'月度发电机转速扭矩散点图: {name[0]}',
|
|
|
# "x": 0.5
|
|
|
},
|
|
|
xaxis=dict(
|
|
@@ -134,37 +134,78 @@ class GeneratorSpeedTorqueAnalyst(AnalystWithGoodPoint):
|
|
|
# )
|
|
|
# )
|
|
|
)
|
|
|
+ # 确保从 Series 中提取的是具体的值
|
|
|
+ engineTypeCode = turbineModelInfo.get(Field_MillTypeCode, "")
|
|
|
+ if isinstance(engineTypeCode, pd.Series):
|
|
|
+ engineTypeCode = engineTypeCode.iloc[0]
|
|
|
+
|
|
|
+ engineTypeName = turbineModelInfo.get(Field_MachineTypeCode, "")
|
|
|
+ if isinstance(engineTypeName, pd.Series):
|
|
|
+ engineTypeName = engineTypeName.iloc[0]
|
|
|
+ # 构建最终的JSON对象
|
|
|
+ json_output = {
|
|
|
+ "analysisTypeCode": "发电机转速和转矩分析",
|
|
|
+ "engineCode": engineTypeCode,
|
|
|
+ "engineTypeName": engineTypeName,
|
|
|
+ "xaixs": "发电机转速(r/min)",
|
|
|
+ "yaixs": "扭矩(N·m)",
|
|
|
+ "data": [{
|
|
|
+ "engineName": name[0],
|
|
|
+ "engineCode": name[1],
|
|
|
+ "title":f' 发电机转速和转矩分析{name[0]}',
|
|
|
+ "xData": dataFrame[Field_GeneratorSpeed].tolist(),
|
|
|
+ "yData":dataFrame[Field_GeneratorTorque].tolist(),
|
|
|
+ "color": dataFrame['monthIntTime'].tolist(),
|
|
|
+ "colorbartitle": "时间",
|
|
|
+ "mode":'markers'
|
|
|
+
|
|
|
+ }]
|
|
|
+ }
|
|
|
|
|
|
# 保存图片
|
|
|
outputFilePathPNG = os.path.join(
|
|
|
- outputAnalysisDir, f"{turbineName}.png")
|
|
|
+ outputAnalysisDir, f"{name[0]}.png")
|
|
|
fig.write_image(outputFilePathPNG, width=800, height=600, scale=3)
|
|
|
|
|
|
- # 保存html
|
|
|
- outputFileHtml = os.path.join(outputAnalysisDir, f"{turbineName}.html")
|
|
|
- fig.write_html(outputFileHtml)
|
|
|
-
|
|
|
+ # # 保存html
|
|
|
+ # outputFileHtml = os.path.join(outputAnalysisDir, f"{name[0]}.html")
|
|
|
+ # fig.write_html(outputFileHtml)
|
|
|
+
|
|
|
+ # 将JSON对象保存到文件
|
|
|
+ output_json_path = os.path.join(outputAnalysisDir, f"speed_torque{name[0]}.json")
|
|
|
+ with open(output_json_path, 'w', encoding='utf-8') as f:
|
|
|
+ import json
|
|
|
+ json.dump(json_output, f, ensure_ascii=False, indent=4)
|
|
|
result = []
|
|
|
+ # 如果需要返回DataFrame,可以包含文件路径
|
|
|
result.append({
|
|
|
Field_Return_TypeAnalyst: self.typeAnalyst(),
|
|
|
Field_PowerFarmCode: conf.dataContract.dataFilter.powerFarmID,
|
|
|
Field_Return_BatchCode: conf.dataContract.dataFilter.dataBatchNum,
|
|
|
- Field_CodeOfTurbine: dataFrame[Field_CodeOfTurbine].iloc[0],
|
|
|
- Field_Return_FilePath: outputFilePathPNG,
|
|
|
- Field_Return_IsSaveDatabase: False
|
|
|
+ Field_CodeOfTurbine: name[1],
|
|
|
+ Field_Return_FilePath: output_json_path,
|
|
|
+ Field_Return_IsSaveDatabase: True
|
|
|
})
|
|
|
result.append({
|
|
|
Field_Return_TypeAnalyst: self.typeAnalyst(),
|
|
|
Field_PowerFarmCode: conf.dataContract.dataFilter.powerFarmID,
|
|
|
Field_Return_BatchCode: conf.dataContract.dataFilter.dataBatchNum,
|
|
|
Field_CodeOfTurbine: dataFrame[Field_CodeOfTurbine].iloc[0],
|
|
|
- Field_Return_FilePath: outputFileHtml,
|
|
|
- Field_Return_IsSaveDatabase: True
|
|
|
+ Field_Return_FilePath: outputFilePathPNG,
|
|
|
+ Field_Return_IsSaveDatabase: False
|
|
|
})
|
|
|
+ # result.append({
|
|
|
+ # Field_Return_TypeAnalyst: self.typeAnalyst(),
|
|
|
+ # Field_PowerFarmCode: conf.dataContract.dataFilter.powerFarmID,
|
|
|
+ # Field_Return_BatchCode: conf.dataContract.dataFilter.dataBatchNum,
|
|
|
+ # Field_CodeOfTurbine: dataFrame[Field_CodeOfTurbine].iloc[0],
|
|
|
+ # Field_Return_FilePath: outputFileHtml,
|
|
|
+ # Field_Return_IsSaveDatabase: True
|
|
|
+ # })
|
|
|
|
|
|
return result
|
|
|
|
|
|
- def drawScatterGraphOfTurbine(self, dataFrame: pd.DataFrame, outputAnalysisDir: str, conf: Contract, turbineName: str):
|
|
|
+ def drawScatterGraphOfTurbine(self, dataFrame: pd.DataFrame,turbineModelInfo: pd.Series,outputAnalysisDir: str, conf: Contract, name: str):
|
|
|
# 创建3D散点图
|
|
|
fig = px.scatter_3d(dataFrame,
|
|
|
x=Field_GeneratorSpeed,
|
|
@@ -181,7 +222,7 @@ class GeneratorSpeedTorqueAnalyst(AnalystWithGoodPoint):
|
|
|
# 更新图形的布局
|
|
|
fig.update_layout(
|
|
|
title={
|
|
|
- "text": f'月度发电机转速扭矩3D散点图: {turbineName}',
|
|
|
+ "text": f'月度发电机转速扭矩3D散点图: {name[0]}',
|
|
|
"x": 0.5
|
|
|
},
|
|
|
scene=dict(
|
|
@@ -219,37 +260,81 @@ class GeneratorSpeedTorqueAnalyst(AnalystWithGoodPoint):
|
|
|
itemwidth=80 # Set the width of legend items to 50 pixels
|
|
|
)
|
|
|
)
|
|
|
-
|
|
|
+ # 构建最终的JSON对象
|
|
|
+ # 确保从 Series 中提取的是具体的值
|
|
|
+ # 确保从 Series 中提取的是具体的值
|
|
|
+ engineTypeCode = turbineModelInfo.get(Field_MillTypeCode, "")
|
|
|
+ if isinstance(engineTypeCode, pd.Series):
|
|
|
+ engineTypeCode = engineTypeCode.iloc[0]
|
|
|
+
|
|
|
+ engineTypeName = turbineModelInfo.get(Field_MachineTypeCode, "")
|
|
|
+ if isinstance(engineTypeName, pd.Series):
|
|
|
+ engineTypeName = engineTypeName.iloc[0]
|
|
|
+ # 构建最终的JSON对象
|
|
|
+ json_output = {
|
|
|
+ "analysisTypeCode": "发电机转速和转矩分析",
|
|
|
+ "engineCode": engineTypeCode,
|
|
|
+ "engineTypeName": engineTypeName,
|
|
|
+ "xaixs": "发电机转速(r/min)",
|
|
|
+ "yaixs": "时间",
|
|
|
+ "zaixs": "扭矩(N·m)",
|
|
|
+ "data": [{
|
|
|
+ "engineName": name[0],
|
|
|
+ "engineCode": name[1],
|
|
|
+ "title":f' 发电机转速和转矩分析{name[0]}',
|
|
|
+ "xData": dataFrame[Field_GeneratorSpeed].tolist(),
|
|
|
+ "yData":dataFrame[Field_YearMonth].tolist(),
|
|
|
+ "zData":dataFrame[Field_GeneratorTorque].tolist(),
|
|
|
+ "color": dataFrame[Field_YearMonth].tolist(),
|
|
|
+ "mode":'markers'
|
|
|
+
|
|
|
+ }]
|
|
|
+ }
|
|
|
# 保存图像
|
|
|
- outputFileHtml = os.path.join(
|
|
|
- outputAnalysisDir, "{}_3D.html".format(turbineName))
|
|
|
+ # outputFileHtml = os.path.join(
|
|
|
+ # outputAnalysisDir, "{}_3D.html".format(name[0]))
|
|
|
|
|
|
- fig.write_html(outputFileHtml)
|
|
|
+ # fig.write_html(outputFileHtml)
|
|
|
|
|
|
result = []
|
|
|
-
|
|
|
+ # 将JSON对象保存到文件
|
|
|
+ output_json_path = os.path.join(outputAnalysisDir, f"3D_{name[0]}.json")
|
|
|
+ with open(output_json_path, 'w', encoding='utf-8') as f:
|
|
|
+ import json
|
|
|
+ json.dump(json_output, f, ensure_ascii=False, indent=4)
|
|
|
+ result = []
|
|
|
+ # 如果需要返回DataFrame,可以包含文件路径
|
|
|
result.append({
|
|
|
Field_Return_TypeAnalyst: self.typeAnalyst(),
|
|
|
Field_PowerFarmCode: conf.dataContract.dataFilter.powerFarmID,
|
|
|
Field_Return_BatchCode: conf.dataContract.dataFilter.dataBatchNum,
|
|
|
- Field_CodeOfTurbine: dataFrame[Field_CodeOfTurbine].iloc[0],
|
|
|
- Field_Return_FilePath: outputFileHtml,
|
|
|
+ Field_CodeOfTurbine: name[1],
|
|
|
+ Field_Return_FilePath: output_json_path,
|
|
|
Field_Return_IsSaveDatabase: True
|
|
|
})
|
|
|
+ # result.append({
|
|
|
+ # Field_Return_TypeAnalyst: self.typeAnalyst(),
|
|
|
+ # Field_PowerFarmCode: conf.dataContract.dataFilter.powerFarmID,
|
|
|
+ # Field_Return_BatchCode: conf.dataContract.dataFilter.dataBatchNum,
|
|
|
+ # Field_CodeOfTurbine: dataFrame[Field_CodeOfTurbine].iloc[0],
|
|
|
+ # Field_Return_FilePath: outputFileHtml,
|
|
|
+ # Field_Return_IsSaveDatabase: True
|
|
|
+ # })
|
|
|
|
|
|
return result
|
|
|
|
|
|
- def drawScatter2DMonthly(self, dataFrameMerge: pd.DataFrame, outputAnalysisDir, conf: Contract):
|
|
|
+ def drawScatter2DMonthly(self, dataFrameMerge: pd.DataFrame, outputAnalysisDir, conf: Contract,turbineModelInfo: pd.Series):
|
|
|
results = []
|
|
|
- grouped = dataFrameMerge.groupby(Field_NameOfTurbine)
|
|
|
+ grouped = dataFrameMerge.groupby(
|
|
|
+ [Field_NameOfTurbine, Field_CodeOfTurbine])
|
|
|
for name, group in grouped:
|
|
|
result = self.drawScatter2DMonthlyOfTurbine(
|
|
|
- group, outputAnalysisDir, conf, name)
|
|
|
+ group,turbineModelInfo, outputAnalysisDir, conf, name)
|
|
|
results.extend(result)
|
|
|
|
|
|
return results
|
|
|
|
|
|
- def drawScatterGraph(self, dataFrame: pd.DataFrame, outputAnalysisDir, conf: Contract):
|
|
|
+ def drawScatterGraph(self, dataFrame: pd.DataFrame, outputAnalysisDir, conf: Contract,turbineModelInfo: pd.Series):
|
|
|
"""
|
|
|
绘制风速-功率分布图并保存为文件。
|
|
|
|
|
@@ -262,13 +347,13 @@ class GeneratorSpeedTorqueAnalyst(AnalystWithGoodPoint):
|
|
|
dataFrame = dataFrame[(dataFrame[Field_GeneratorTorque] > 0)].sort_values(
|
|
|
by=Field_YearMonth)
|
|
|
|
|
|
- grouped = dataFrame.groupby(Field_NameOfTurbine)
|
|
|
-
|
|
|
+ grouped = dataFrame.groupby(
|
|
|
+ [Field_NameOfTurbine, Field_CodeOfTurbine])
|
|
|
# 遍历每个设备的数据
|
|
|
for name, group in grouped:
|
|
|
if len(group[Field_YearMonth].unique()) > 1:
|
|
|
result = self.drawScatterGraphOfTurbine(
|
|
|
- group, outputAnalysisDir, conf, name)
|
|
|
+ group,turbineModelInfo, outputAnalysisDir, conf, name)
|
|
|
results.extend(result)
|
|
|
|
|
|
return results
|
|
@@ -337,22 +422,61 @@ class GeneratorSpeedTorqueAnalyst(AnalystWithGoodPoint):
|
|
|
itemwidth=80 # Set the width of legend items to 50 pixels
|
|
|
)
|
|
|
)
|
|
|
-
|
|
|
- # 保存图像
|
|
|
- outputFileHtml = os.path.join(
|
|
|
- outputAnalysisDir, "{}-{}.html".format(self.typeAnalyst(),turbineModelInfo[Field_MillTypeCode]))
|
|
|
-
|
|
|
- fig.write_html(outputFileHtml)
|
|
|
+ # 确保从 Series 中提取的是具体的值
|
|
|
+ engineTypeCode = turbineModelInfo.get(Field_MillTypeCode, "")
|
|
|
+ if isinstance(engineTypeCode, pd.Series):
|
|
|
+ engineTypeCode = engineTypeCode.iloc[0]
|
|
|
+
|
|
|
+ engineTypeName = turbineModelInfo.get(Field_MachineTypeCode, "")
|
|
|
+ if isinstance(engineTypeName, pd.Series):
|
|
|
+ engineTypeName = engineTypeName.iloc[0]
|
|
|
+ # 构建最终的JSON对象
|
|
|
+ json_output = {
|
|
|
+ "analysisTypeCode": "发电机转速和转矩分析",
|
|
|
+ "engineCode": engineTypeCode,
|
|
|
+ "engineTypeName": engineTypeName,
|
|
|
+ "xaixs": "发电机转速(r/min)",
|
|
|
+ "yaixs": "机组",
|
|
|
+ "zaixs": "实际扭矩(N·m)",
|
|
|
+ "data": [{
|
|
|
+ "title":f' 发电机转速扭矩3D散点图-{turbineModelInfo[Field_MachineTypeCode]}',
|
|
|
+ "xData": dataFrame[Field_GeneratorSpeed].tolist(),
|
|
|
+ "yData":dataFrame[Field_NameOfTurbine].tolist(),
|
|
|
+ "zData":dataFrame[Field_GeneratorTorque].tolist(),
|
|
|
+ "color": dataFrame[Field_NameOfTurbine].tolist(),
|
|
|
+ "mode":'markers'
|
|
|
+
|
|
|
+ }]
|
|
|
+ }
|
|
|
+ # # 保存图像
|
|
|
+ # outputFileHtml = os.path.join(
|
|
|
+ # outputAnalysisDir, "{}-{}.html".format(self.typeAnalyst(),turbineModelInfo[Field_MillTypeCode]))
|
|
|
+
|
|
|
+ # fig.write_html(outputFileHtml)
|
|
|
|
|
|
result = []
|
|
|
-
|
|
|
+ # 将JSON对象保存到文件
|
|
|
+ output_json_path = os.path.join(outputAnalysisDir, f"total_3D_{turbineModelInfo[Field_MillTypeCode]}.json")
|
|
|
+ with open(output_json_path, 'w', encoding='utf-8') as f:
|
|
|
+ import json
|
|
|
+ json.dump(json_output, f, ensure_ascii=False, indent=4)
|
|
|
+ result = []
|
|
|
+ # 如果需要返回DataFrame,可以包含文件路径
|
|
|
result.append({
|
|
|
Field_Return_TypeAnalyst: self.typeAnalyst(),
|
|
|
Field_PowerFarmCode: conf.dataContract.dataFilter.powerFarmID,
|
|
|
Field_Return_BatchCode: conf.dataContract.dataFilter.dataBatchNum,
|
|
|
- Field_CodeOfTurbine: Const_Output_Total,
|
|
|
- Field_Return_FilePath: outputFileHtml,
|
|
|
+ Field_CodeOfTurbine:Const_Output_Total,
|
|
|
+ Field_Return_FilePath: output_json_path,
|
|
|
Field_Return_IsSaveDatabase: True
|
|
|
})
|
|
|
+ # result.append({
|
|
|
+ # Field_Return_TypeAnalyst: self.typeAnalyst(),
|
|
|
+ # Field_PowerFarmCode: conf.dataContract.dataFilter.powerFarmID,
|
|
|
+ # Field_Return_BatchCode: conf.dataContract.dataFilter.dataBatchNum,
|
|
|
+ # Field_CodeOfTurbine: Const_Output_Total,
|
|
|
+ # Field_Return_FilePath: outputFileHtml,
|
|
|
+ # Field_Return_IsSaveDatabase: True
|
|
|
+ # })
|
|
|
|
|
|
return result
|