|
@@ -9,7 +9,7 @@ from sklearn.neighbors import BallTree
|
|
|
|
|
|
from app.config import dataBase
|
|
from app.config import dataBase
|
|
from app.database import get_engine
|
|
from app.database import get_engine
|
|
-
|
|
|
|
|
|
+from typing import Dict
|
|
|
|
|
|
class MSET_Temp:
|
|
class MSET_Temp:
|
|
"""
|
|
"""
|
|
@@ -184,3 +184,98 @@ class MSET_Temp:
|
|
metric=lambda a, b: 1.0 - inst.calcSimilarity(a, b)
|
|
metric=lambda a, b: 1.0 - inst.calcSimilarity(a, b)
|
|
)
|
|
)
|
|
return inst
|
|
return inst
|
|
|
|
+
|
|
|
|
+ def query_surrounding_data(self, timestamp: str, minutes_around: int = 250) -> Dict:
|
|
|
|
+ """
|
|
|
|
+ 查询指定时间点前后50个点的数据
|
|
|
|
+ 参数:
|
|
|
|
+ timestamp: 中心时间点,格式为 'yyyy-mm-dd HH:MM:SS'
|
|
|
|
+ minutes_around: 查询前后多少分钟的数据
|
|
|
|
+ 返回:
|
|
|
|
+ {
|
|
|
|
+ 'record_count': int,
|
|
|
|
+ 'records': List[Dict],
|
|
|
|
+ 'columns_mapping': Dict[str, str] # 字段中英文映射
|
|
|
|
+ }
|
|
|
|
+ """
|
|
|
|
+ # 中英文映射字典
|
|
|
|
+ cn_map = {
|
|
|
|
+ 'wind_turbine_name':'风机名称',
|
|
|
|
+ 'time_stamp': '时间',
|
|
|
|
+ 'active_power': '有功功率(kW)',
|
|
|
|
+ 'rotor_speed': '风轮转速(rpm)',
|
|
|
|
+ 'generator_speed':'发电机转速(rpm)',
|
|
|
|
+ 'wind_velocity': '风速(m/s)',
|
|
|
|
+ 'pitch_angle_blade_1':'桨距角1(°)',
|
|
|
|
+ 'pitch_angle_blade_2':'桨距角2(°)',
|
|
|
|
+ 'pitch_angle_blade_3':'桨距角3(°)',
|
|
|
|
+ 'cabin_position':'机舱位置(°)',
|
|
|
|
+ 'true_wind_direction':'绝对风向(°)',
|
|
|
|
+ 'yaw_error1':'对风角度(°)',
|
|
|
|
+ 'set_value_of_active_power':'有功功率设定值(kW)',
|
|
|
|
+ 'gearbox_oil_temperature':'齿轮箱油温(℃)',
|
|
|
|
+ 'generatordrive_end_bearing_temperature':'发电机驱动端轴承温度(℃)',
|
|
|
|
+ 'generatornon_drive_end_bearing_temperature':'发电机非驱动端轴承温度(℃)',
|
|
|
|
+ 'cabin_temperature':'机舱内温度(℃)',
|
|
|
|
+ 'twisted_cable_angle':'扭缆角度(°)',
|
|
|
|
+ 'outside_cabin_temperature':'环境温度(℃)',
|
|
|
|
+ 'main_bearing_temperature':'主轴承轴承温度(℃)',
|
|
|
|
+ 'main_bearing_temperature_2': '主轴承轴承温度2(℃)',
|
|
|
|
+ 'gearbox_high_speed_shaft_bearing_temperature':'齿轮箱高速轴轴承温度(℃)',
|
|
|
|
+ 'gearboxmedium_speed_shaftbearing_temperature':'齿轮箱中速轴轴承温度(℃)',
|
|
|
|
+ 'gearbox_low_speed_shaft_bearing_temperature':'齿轮箱低速轴轴承温度(℃)',
|
|
|
|
+ 'generator_winding1_temperature':'发电机绕组1温度(℃)',
|
|
|
|
+ 'generator_winding2_temperature':'发电机绕组2温度(℃)',
|
|
|
|
+ 'generator_winding3_temperature':'发电机绕组3温度(℃)',
|
|
|
|
+ 'grid_a_phase_current':'电网A相电流(A)',
|
|
|
|
+ 'grid_b_phase_current': '电网B相电流(A)',
|
|
|
|
+ 'grid_c_phase_current': '电网C相电流(A)'
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ table = f"{self.windCode}_minute"
|
|
|
|
+ engine = get_engine(dataBase.DATA_DB)
|
|
|
|
+
|
|
|
|
+ # 查询数据
|
|
|
|
+ sql = text(f"""
|
|
|
|
+ SELECT *
|
|
|
|
+ FROM {table}
|
|
|
|
+ WHERE wind_turbine_number IN ({','.join([f"'{t}'" for t in self.windTurbineNumberList])})
|
|
|
|
+ AND time_stamp BETWEEN
|
|
|
|
+ DATE_SUB(:timestamp, INTERVAL :minutes MINUTE)
|
|
|
|
+ AND DATE_ADD(:timestamp, INTERVAL :minutes MINUTE)
|
|
|
|
+ ORDER BY time_stamp ASC
|
|
|
|
+ """)
|
|
|
|
+
|
|
|
|
+ df = pd.read_sql(sql, engine, params={
|
|
|
|
+ "timestamp": timestamp,
|
|
|
|
+ "minutes": minutes_around
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ # 打印查询到的数据条数
|
|
|
|
+ record_count = len(df)
|
|
|
|
+ print(f"查询到 {record_count} 条数据")
|
|
|
|
+
|
|
|
|
+ if df.empty:
|
|
|
|
+ return {
|
|
|
|
+ 'record_count': 0,
|
|
|
|
+ 'records': [],
|
|
|
|
+ 'columns_mapping': {}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 删除空列和不需要的列
|
|
|
|
+ cols_to_drop = ['wind_turbine_number', 'reactive_power','lab', 'year', 'month','day','year_month','front_back_vibration_of_the_cabin','side_to_side_vibration_of_the_cabin',
|
|
|
|
+ 'actual_torque','given_torque','clockwise_yaw_count','counterclockwise_yaw_count','unusable','power_curve_available','required_gearbox_speed','inverter_speed_master_control',
|
|
|
|
+ 'wind_turbine_status','wind_turbine_status2','turbulence_intensity'
|
|
|
|
+ ]
|
|
|
|
+ cols_to_drop = [col for col in cols_to_drop if col in df.columns]
|
|
|
|
+ df = df.drop(columns=cols_to_drop)
|
|
|
|
+ df = df.dropna(axis=1, how='all')
|
|
|
|
+
|
|
|
|
+ # 转换字段名和格式
|
|
|
|
+ df['time_stamp'] = df['time_stamp'].astype(str)
|
|
|
|
+ records = df.rename(columns=cn_map).to_dict('records')
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ 'record_count': record_count,
|
|
|
|
+ 'records': records
|
|
|
|
+ }
|