فهرست منبع

后续部分修改更新

wenjia Li 5 ماه پیش
والد
کامیت
b286984fec

+ 1 - 1
dataAnalysisBusiness/algorithm/cpAnalyst.py

@@ -56,7 +56,7 @@ class CpAnalyst(AnalystWithGoodPoint):
         upLimitOfPower = self.turbineInfo[Field_RatedPower].max() * 0.9
 
         grouped = dataFrameOfTurbines.groupby([Field_CodeOfTurbine, Field_PowerFloor]).agg(
-            cp=('cp', 'median'),
+            cp=('cp', 'mean'),
             cp_max=('cp', 'max'),
             cp_min=('cp', 'min'),
         ).reset_index()

+ 5 - 0
dataAnalysisBusiness/algorithm/generatorSpeedPowerAnalyst.py

@@ -137,6 +137,11 @@ class GeneratorSpeedPowerAnalyst(AnalystWithGoodPoint):
         engineTypeName = turbineModelInfo.get(Field_MachineTypeCode, "")
         if isinstance(engineTypeName, pd.Series):
             engineTypeName = engineTypeName.iloc[0]
+        
+        print(dataFrame[Field_UnixYearMonth].head())
+        print(dataFrame[Field_UnixYearMonth].dtype)    
+        # 使用 apply() 对每个元素调用 datetime.fromtimestamp
+        dataFrame[Field_UnixYearMonth]= dataFrame[Field_UnixYearMonth].apply(lambda x: datetime.fromtimestamp(x).strftime('%Y-%m'))
         # 构建最终的JSON对象
         json_output = {
             "analysisTypeCode": "发电机转速和有功功率分析",

+ 4 - 0
dataAnalysisBusiness/algorithm/generatorSpeedTorqueAnalyst.py

@@ -142,6 +142,10 @@ class GeneratorSpeedTorqueAnalyst(AnalystWithGoodPoint):
         engineTypeName = turbineModelInfo.get(Field_MachineTypeCode, "")
         if isinstance(engineTypeName, pd.Series):
             engineTypeName = engineTypeName.iloc[0]
+
+        # 使用 apply() 对每个元素调用 datetime.fromtimestamp
+        dataFrame['monthIntTime']=dataFrame['monthIntTime'].apply(lambda x: datetime.fromtimestamp(x).strftime('%Y-%m'))
+        
         # 构建最终的JSON对象
         json_output = {
             "analysisTypeCode": "发电机转速和转矩分析",

+ 14 - 10
dataAnalysisBusiness/algorithm/minPitchAnalyst.py

@@ -70,11 +70,15 @@ class MinPitchAnalyst(AnalystWithGoodBadPoint):
             # Convert the date column to datetime type
             group[Field_YearMonthDay] = pd.to_datetime(
                 group[Field_YearMonthDay])
+            # 创建筛选条件,桨距角小于10
+            condition = group[Field_PitchAngel1] < 10
+            # 生成筛选后的子数据集(避免修改原始 group)
+            group = group[condition].copy()
 
-            # Creating bins of 0.2 intervals for pitch angles
+            # Creating bins of 0.2 intervals for pitch angles(分仓步长从0.2改为0.1)
             bins = pd.interval_range(start=group[Field_PitchAngel1].min(),
                                      end=group[Field_PitchAngel1].max(
-            ) + 0.1, freq=0.2, closed='right')
+            ) + 0.1, freq=0.1, closed='right')
             group[fieldPitchAngleBin] = pd.cut(
                 group[Field_PitchAngel1], bins=bins)
             group[fieldPitchAngleBin] = group[fieldPitchAngleBin].apply(
@@ -126,7 +130,7 @@ class MinPitchAnalyst(AnalystWithGoodBadPoint):
             # Set marker size if fixed size is needed
             # Fixed size for all points
             fig.update_traces(marker=dict(size=3, opacity=0.9))
-                         # 确保从 Series 中提取的是具体的值
+            # 确保从 Series 中提取的是具体的值
             engineTypeCode = turbineModelInfo.get(Field_MillTypeCode, "")
             if isinstance(engineTypeCode, pd.Series):
                 engineTypeCode = engineTypeCode.iloc[0]
@@ -142,13 +146,13 @@ class MinPitchAnalyst(AnalystWithGoodBadPoint):
                 "xaixs": "时间",
                 "yaixs": "桨距角(度)",
                 "data": [{
-                "engineName": name[0],
-                "engineCode": name[1],
-                "title":f' {name[0]}的最小桨距角分布',
-                "xData": df[Field_YearMonthDay].dt.strftime('%Y-%m-%d').tolist(),
-                "yData": df[fieldPitchAngleBin].tolist(),
-                "colorbar": df[pitchAngleRate].tolist(),
-                "colorbartitle": "百分比(%)"
+                    "engineName": name[0],
+                    "engineCode": name[1],
+                    "title":f' {name[0]}的最小桨距角分布',
+                    "xData": df[Field_YearMonthDay].dt.strftime('%Y-%m-%d').tolist(),
+                    "yData": df[fieldPitchAngleBin].tolist(),
+                    "colorbar": df[pitchAngleRate].tolist(),
+                    "colorbartitle": "百分比(%)"
                 
             }]
             }

+ 5 - 3
dataAnalysisBusiness/algorithm/pitchGeneratorSpeedAnalyst.py

@@ -110,8 +110,11 @@ class PitchGeneratorSpeedAnalyst(AnalystWithGoodBadPoint):
             engineTypeName = turbineModelInfo.get(Field_MachineTypeCode, "")
             if isinstance(engineTypeName, pd.Series):
                 engineTypeName = engineTypeName.iloc[0]
+            
+            # 使用 apply() 对每个元素调用 datetime.fromtimestamp
+            group[Field_UnixYearMonth] = group[Field_UnixYearMonth].apply(lambda x: datetime.fromtimestamp(x).strftime('%Y-%m'))
+
             # 构建最终的JSON对象
-            group[Field_UnixYearMonth] = pd.to_datetime(group[Field_UnixYearMonth])
             json_output = {
                 "analysisTypeCode": "变桨和发电机转速协调性分析",
                 "engineCode": engineTypeCode,
@@ -124,11 +127,10 @@ class PitchGeneratorSpeedAnalyst(AnalystWithGoodBadPoint):
                     "title": f' 机组: {name[0]}',
                     "xData": groupNew[Field_GeneratorSpeed].tolist(),
                     "yData": groupNew[Field_PitchAngel1].tolist(),
-                    "colorbar": dataFrameMerge[Field_YearMonth].unique().tolist(),
+                    "colorbar":group[Field_UnixYearMonth] .tolist(),
 
                 }]
             }
-
             # Save plot
             filePathOfImage = os.path.join(outputAnalysisDir, f"{name[0]}.png")
             fig.write_image(filePathOfImage, scale=3)

+ 1 - 0
dataAnalysisBusiness/algorithm/pitchPowerAnalyst.py

@@ -349,6 +349,7 @@ class PitchPowerAnalyst(AnalystWithGoodBadPoint):
                         "xData": group[Field_PitchAngel1].tolist(),
                         "yData": group[Field_YearMonth].tolist(),
                         "zData": group[Field_ActiverPower].tolist(),
+                        "color":group[Field_YearMonth].tolist()
                     }]
                 }
                 # 保存图像

+ 2 - 1
dataAnalysisBusiness/algorithm/powerScatter2DAnalyst.py

@@ -187,7 +187,8 @@ class PowerScatter2DAnalyst(AnalystWithGoodBadPoint):
             engineTypeName = turbineModelInfo.get(Field_MachineTypeCode, "")
             if isinstance(engineTypeName, pd.Series):
                 engineTypeName = engineTypeName.iloc[0]
-
+              # 使用 apply() 对每个元素调用 datetime.fromtimestamp
+            group['monthIntTime'] = group['monthIntTime'].apply(lambda x: datetime.fromtimestamp(x).strftime('%Y-%m'))
             # 定义要替换的空值类型
             na_values = {pd.NA, float('nan')}
             # 构建最终的JSON对象

+ 2 - 1
dataAnalysisBusiness/algorithm/powerScatterAnalyst.py

@@ -163,7 +163,8 @@ class PowerScatterAnalyst(AnalystWithGoodBadPoint):
                         "xrange":[cut_in_ws, 25],
                         "yData":group[Field_YearMonth].tolist(),
                         "zData":group[Field_ActiverPower].tolist(),
-                        "zrange":[self.axisLowerLimitActivePower, self.axisUpperLimitActivePower]
+                        "zrange":[self.axisLowerLimitActivePower, self.axisUpperLimitActivePower],
+                        "color":group[Field_YearMonth].tolist()
                         }]
             }
             # # Save plot

+ 2 - 2
dataAnalysisBusiness/algorithm/tsrAnalyst.py

@@ -62,10 +62,10 @@ class TSRAnalyst(AnalystWithGoodPoint):
 
             # Group by 'power_floor' and calculate median, max, and min of TSR
             grouped = dataFrameMerge.groupby([Field_PowerFloor, Field_CodeOfTurbine, Field_NameOfTurbine]).agg({
-                Field_WindSpeed: 'median',
+                Field_WindSpeed: 'mean',
                 Field_RotorSpeed: 'median',
                 Field_GeneratorSpeed: 'median',
-                Field_TSR: ['median', 'max', 'min'],
+                Field_TSR: ['mean', 'max', 'min'],
                 Field_PowerFarmName: 'max'
             }).reset_index()
 

+ 43 - 4
dataAnalysisBusiness/algorithm/yawErrorDensityAnalyst.py

@@ -4,12 +4,13 @@ import numpy as np
 import plotly.graph_objects as go
 from algorithmContract.confBusiness import *
 from algorithmContract.contract import Contract
-from behavior.analystWithGoodPoint import AnalystWithGoodPoint
+from behavior.analystWithGoodBadLimitPoint import AnalystWithGoodBadLimitPoint
 from scipy.stats import binned_statistic_2d
 from scipy.stats import skew, kurtosis
 from utils.jsonUtil import JsonUtil
+from scipy.stats import norm, gaussian_kde
 
-class YawErrorDensityAnalyst(AnalystWithGoodPoint):
+class YawErrorDensityAnalyst(AnalystWithGoodBadLimitPoint):
     """
     风电机组动态偏航策略分析
     """
@@ -67,7 +68,9 @@ class YawErrorDensityAnalyst(AnalystWithGoodPoint):
         ]
         
         for name, group in grouped:
-        
+            dataFrame=group[Field_YawError].abs() <= 45
+            yawerror=np.mean(dataFrame[Field_YawError])
+            
             df = self.calculateYawError(group)
             df.dropna(inplace=True)
             counts = df['density'].value_counts()
@@ -145,7 +148,29 @@ class YawErrorDensityAnalyst(AnalystWithGoodPoint):
             }]
             }
 
-            
+            # 使用 gaussian_kde 估计数据的概率密度函数
+            kde = gaussian_kde(df["x"])
+            x = np.linspace(-30, 30, 1000)  # 生成 x 轴数据
+            pdf_data = kde(x)  # 数据的概率密度函数
+
+            # 构建最终的JSON对象2
+            json_output2 = {
+                "analysisTypeCode": "动态偏航误差",
+                "engineCode":  engineTypeCode,    
+                "engineTypeName": engineTypeName, 
+                "xaixs": "对风角度(度)",
+                "yaixs": "概率密度函数",
+                "data": [{
+                "engineName": name[0],
+                "engineCode": name[1],
+                "title":f'概率密度函数-{name[0]}',
+                "xData": x .tolist(),
+                "yData": pdf_data.tolist(),
+                "xrange":[-30,30]
+                
+            }]
+            }
+        
             # Save to file
             filePathOfImage = os.path.join(outputAnalysisDir, f"{name[0]}.png")
             fig.write_image(filePathOfImage, scale=3)
@@ -159,6 +184,12 @@ class YawErrorDensityAnalyst(AnalystWithGoodPoint):
                 import json
                 json.dump(json_output, f, ensure_ascii=False, indent=4)
 
+            # 将JSON对象2保存到文件
+            output_json_path2 = os.path.join(outputAnalysisDir, f"PDF-{name[0]}.json")
+            with open(output_json_path2, 'w', encoding='utf-8') as f:
+                import json
+                json.dump(json_output2, f, ensure_ascii=False, indent=4)
+
             # 如果需要返回DataFrame,可以包含文件路径
             result_rows.append({
                 Field_Return_TypeAnalyst: self.typeAnalyst(),
@@ -168,6 +199,14 @@ class YawErrorDensityAnalyst(AnalystWithGoodPoint):
                 Field_Return_FilePath: output_json_path,
                 Field_Return_IsSaveDatabase: True
             })
+            result_rows.append({
+                Field_Return_TypeAnalyst: self.typeAnalyst(),
+                Field_PowerFarmCode: conf.dataContract.dataFilter.powerFarmID,
+                Field_Return_BatchCode: conf.dataContract.dataFilter.dataBatchNum,
+                Field_CodeOfTurbine: name[1],
+                Field_Return_FilePath: output_json_path2,
+                Field_Return_IsSaveDatabase: True
+            })
 
             result_rows.append({
                 Field_Return_TypeAnalyst: self.typeAnalyst(),