|
@@ -147,6 +147,8 @@ class WindDirectionFrequencyAnalyst(AnalystNotFilter):
|
|
|
return result_df
|
|
return result_df
|
|
|
'''
|
|
'''
|
|
|
def windRoseAnalysis(self, dataFrameMerge: pd.DataFrame, outputAnalysisDir, conf: Contract):
|
|
def windRoseAnalysis(self, dataFrameMerge: pd.DataFrame, outputAnalysisDir, conf: Contract):
|
|
|
|
|
+ # 提前初始化,保证即使数据缺失提前返回,后续 outputJsonData 也能安全访问
|
|
|
|
|
+ self.frequency_data = {}
|
|
|
# 检查所需列是否存在
|
|
# 检查所需列是否存在
|
|
|
required_columns = {Field_WindDirection, Field_WindSpeed}
|
|
required_columns = {Field_WindDirection, Field_WindSpeed}
|
|
|
if not required_columns.issubset(dataFrameMerge.columns) or dataFrameMerge[Field_WindDirection].isna().all() or dataFrameMerge[Field_WindSpeed].isna().all():
|
|
if not required_columns.issubset(dataFrameMerge.columns) or dataFrameMerge[Field_WindDirection].isna().all() or dataFrameMerge[Field_WindSpeed].isna().all():
|
|
@@ -154,9 +156,6 @@ class WindDirectionFrequencyAnalyst(AnalystNotFilter):
|
|
|
self.logger.warning(msg)
|
|
self.logger.warning(msg)
|
|
|
return pd.DataFrame()
|
|
return pd.DataFrame()
|
|
|
|
|
|
|
|
- # 定义类属性 self.frequency_data
|
|
|
|
|
- self.frequency_data = {}
|
|
|
|
|
-
|
|
|
|
|
# 风速区间
|
|
# 风速区间
|
|
|
bins = [0, 3, 6, 9, np.inf]
|
|
bins = [0, 3, 6, 9, np.inf]
|
|
|
speed_labels = ['[0,3)', '[3,6)', '[6,9)', '>=9']
|
|
speed_labels = ['[0,3)', '[3,6)', '[6,9)', '>=9']
|
|
@@ -275,16 +274,23 @@ class WindDirectionFrequencyAnalyst(AnalystNotFilter):
|
|
|
# return returnDatas
|
|
# return returnDatas
|
|
|
|
|
|
|
|
def outputJsonData(self, conf: Contract, outputAnalysisDir: str, turbineModelInfo: pd.Series, dataFrameMerge: pd.DataFrame) -> pd.DataFrame:
|
|
def outputJsonData(self, conf: Contract, outputAnalysisDir: str, turbineModelInfo: pd.Series, dataFrameMerge: pd.DataFrame) -> pd.DataFrame:
|
|
|
|
|
+ # 兼容 windRoseAnalysis 因数据缺失提前返回的情况
|
|
|
|
|
+ if not hasattr(self, "frequency_data"):
|
|
|
|
|
+ self.frequency_data = {}
|
|
|
turbineCodes = dataFrameMerge[Field_CodeOfTurbine].unique()
|
|
turbineCodes = dataFrameMerge[Field_CodeOfTurbine].unique()
|
|
|
|
|
|
|
|
result_rows = []
|
|
result_rows = []
|
|
|
for turbineCode in turbineCodes:
|
|
for turbineCode in turbineCodes:
|
|
|
- if turbineCode in self.frequency_data:
|
|
|
|
|
- # 确保 enginName 是具体的值
|
|
|
|
|
- enginName = dataFrameMerge[dataFrameMerge[Field_CodeOfTurbine] == turbineCode][Field_NameOfTurbine].iloc[0]
|
|
|
|
|
- if isinstance(enginName, pd.Series):
|
|
|
|
|
- enginName = enginName.iloc[0]
|
|
|
|
|
|
|
+ if turbineCode not in self.frequency_data:
|
|
|
|
|
+ # 风向/风速数据缺失时 windRoseAnalysis 返回空,不生成空 JSON 文件
|
|
|
|
|
+ continue
|
|
|
|
|
+ # 确保 enginName 是具体的值
|
|
|
|
|
+ enginName = dataFrameMerge[dataFrameMerge[Field_CodeOfTurbine] == turbineCode][Field_NameOfTurbine].iloc[0]
|
|
|
|
|
+ if isinstance(enginName, pd.Series):
|
|
|
|
|
+ enginName = enginName.iloc[0]
|
|
|
jsonDictionary = self.convert2Json(turbineModelInfo, turbineCode, dataFrameMerge)
|
|
jsonDictionary = self.convert2Json(turbineModelInfo, turbineCode, dataFrameMerge)
|
|
|
|
|
+ if not jsonDictionary:
|
|
|
|
|
+ continue
|
|
|
jsonFileName = f"wind_direction_frequency{enginName}.json"
|
|
jsonFileName = f"wind_direction_frequency{enginName}.json"
|
|
|
jsonFilePath = os.path.join(outputAnalysisDir, jsonFileName)
|
|
jsonFilePath = os.path.join(outputAnalysisDir, jsonFileName)
|
|
|
JsonUtil.write_json(jsonDictionary, file_path=jsonFilePath)
|
|
JsonUtil.write_json(jsonDictionary, file_path=jsonFilePath)
|