# -*- coding: utf-8 -*- # @Time : 2024/6/3 # @Author : 魏志亮 import copy import gradio as gr import yaml from service.plt_service import get_all_wind_company from service.trans_service import get_min_sec_conf_test # from utils.db.trans_mysql import * def test_click(wind_name, wind_full_name, type, is_vertical_table, merge_columns, vertical_read_cols, vertical_index_cols, vertical_col_key, vertical_col_value, resolve_col_prefix, wind_name_exec, wind_turbine_number, time_stamp, active_power, rotor_speed, generator_speed, wind_velocity, pitch_angle_blade_1, pitch_angle_blade_2, pitch_angle_blade_3, cabin_position, true_wind_direction, yaw_error1, set_value_of_active_power, gearbox_oil_temperature, generatordrive_end_bearing_temperature, generatornon_drive_end_bearing_temperature, wind_turbine_status, wind_turbine_status2, cabin_temperature, twisted_cable_angle, 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, outside_cabin_temperature, main_bearing_temperature, gearbox_high_speed_shaft_bearing_temperature, gearboxmedium_speed_shaftbearing_temperature, gearbox_low_speed_shaft_bearing_temperature, generator_winding1_temperature, generator_winding2_temperature, generator_winding3_temperature, turbulence_intensity, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10 ): params = copy.deepcopy(vars()) error_message = "" if wind_name is None or wind_name.strip() == '': error_message += "风机名称必选" gr.Warning(error_message) return error_message if wind_full_name is None or wind_full_name.strip() == '': error_message += "风机全称必选" gr.Warning(error_message) return error_message # save_to_trans_conf(params) return yaml.dump(vars(), allow_unicode=True, sort_keys=False) def fill_data(wind_name, type): select_cols = ['wind_full_name', 'is_vertical_table', 'merge_columns', 'vertical_read_cols', 'vertical_index_cols', 'vertical_col_key', 'vertical_col_value', 'resolve_col_prefix', 'wind_name_exec', 'wind_turbine_number', 'time_stamp', 'active_power', 'rotor_speed', 'generator_speed', 'wind_velocity', 'pitch_angle_blade_1', 'pitch_angle_blade_2', 'pitch_angle_blade_3', 'cabin_position', 'true_wind_direction', 'yaw_error1', 'set_value_of_active_power', 'gearbox_oil_temperature', 'generatordrive_end_bearing_temperature', 'generatornon_drive_end_bearing_temperature', 'wind_turbine_status', 'wind_turbine_status2', 'cabin_temperature', 'twisted_cable_angle', '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', 'outside_cabin_temperature', 'main_bearing_temperature', 'gearbox_high_speed_shaft_bearing_temperature', 'gearboxmedium_speed_shaftbearing_temperature', 'gearbox_low_speed_shaft_bearing_temperature', 'generator_winding1_temperature', 'generator_winding2_temperature', 'generator_winding3_temperature', 'turbulence_intensity', 'param1', 'param2', 'param3', 'param4', 'param5', 'param6', 'param7', 'param8', 'param9', 'param10'] print(wind_name, type) df = get_min_sec_conf_test(wind_name, type) print(df) if df.keys() == 0: return [''] * len(select_cols) result = [] for col in select_cols: result.append(df[col]) return result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7], \ result[8], result[9], \ result[10], result[11], result[12], result[13], result[14], result[15], result[16], result[17], result[18], \ result[19], result[20], result[21], result[22], result[23], result[24], result[25], result[26], result[27], \ result[28], result[29], result[30], result[31], result[32], result[33], result[34], result[35], result[36], \ result[37], result[38], result[39], result[40], result[41], result[42], result[43], result[44], result[45], \ result[46], result[47], result[48], result[49], result[50], result[51], result[52], result[53], result[54], \ result[55], result[56], result[57] with gr.Blocks(css=".container.svelte-1sk0pyu.svelte-1sk0pyu {width: 300px}", title='中能智能') as demo: wind_name = gr.Dropdown(label="电场名称", choices=get_all_wind_company()) types = { '分钟映射': 'minute', '秒映射': 'second' } for name in types.keys(): with gr.Tab(label=name): type = gr.Text(label="映射类型", value=types[name], visible=False) wind_full_name = gr.Textbox(label="完整的电场名称") merge_columns = gr.Checkbox(label="是否需合并(多个excel列合并成一个才需要选择)", value=False) is_vertical_table = gr.Checkbox(label="是否是竖表", value=False) vertical_read_cols = gr.Textbox(label="竖表--读取的字段", placeholder="逗号分隔") vertical_index_cols = gr.Textbox(label="竖表--分组的字段", placeholder="逗号分隔,一般都是时间,机组") vertical_col_key = gr.Textbox(label="竖表--数据点字段") vertical_col_value = gr.Textbox(label="竖表--数据点数值") resolve_col_prefix = gr.Textbox(label="处理列名", placeholder="比如重庆海装 25_#桨距角,只需要 桨距角 可以用 column[column.find('#')+1:]") wind_name_exec = gr.Textbox(label="风机编号代码处理", placeholder="比如 昌平001号风机,可以配置 wind_name.replace('昌平','').replace('号风机','')") wind_turbine_number = gr.Textbox(label="风机编号(wind_turbine_number)") time_stamp = gr.Textbox(label="时间戳(time_stamp)") active_power = gr.Textbox(label="有功功率(active_power)") rotor_speed = gr.Textbox(label="风轮转速(rotor_speed)") generator_speed = gr.Textbox(label="发电机转速(generator_speed)") wind_velocity = gr.Textbox(label="风速(wind_velocity)") pitch_angle_blade_1 = gr.Textbox(label="桨距角1(pitch_angle_blade_1)") pitch_angle_blade_2 = gr.Textbox(label="桨距角2(pitch_angle_blade_2)") pitch_angle_blade_3 = gr.Textbox(label="桨距角3(pitch_angle_blade_3)") cabin_position = gr.Textbox(label="机舱位置(cabin_position)") true_wind_direction = gr.Textbox(label="绝对风向(true_wind_direction)") yaw_error1 = gr.Textbox(label="对风角度(yaw_error1)") set_value_of_active_power = gr.Textbox(label="有功功率设定值(set_value_of_active_power)") gearbox_oil_temperature = gr.Textbox(label="齿轮箱油温(gearbox_oil_temperature)") generatordrive_end_bearing_temperature = gr.Textbox( label="发电机驱动端轴承温度(generatordrive_end_bearing_temperature)") generatornon_drive_end_bearing_temperature = gr.Textbox( label="发电机非驱动端轴承温度(generatornon_drive_end_bearing_temperature)") wind_turbine_status = gr.Textbox(label="风机状态1(wind_turbine_status)") wind_turbine_status2 = gr.Textbox(label="风机状态2(wind_turbine_status2)") cabin_temperature = gr.Textbox(label="机舱内温度(cabin_temperature)") twisted_cable_angle = gr.Textbox(label="扭缆角度(twisted_cable_angle)") front_back_vibration_of_the_cabin = gr.Textbox(label="机舱前后振动(front_back_vibration_of_the_cabin)") side_to_side_vibration_of_the_cabin = gr.Textbox(label="机舱左右振动(side_to_side_vibration_of_the_cabin)") actual_torque = gr.Textbox(label="实际力矩(actual_torque)") given_torque = gr.Textbox(label="给定力矩(given_torque)") clockwise_yaw_count = gr.Textbox(label="顺时针偏航次数(clockwise_yaw_count)") counterclockwise_yaw_count = gr.Textbox(label="逆时针偏航次数(counterclockwise_yaw_count)") unusable = gr.Textbox(label="不可利用(unusable)") power_curve_available = gr.Textbox(label="功率曲线可用(power_curve_available)") required_gearbox_speed = gr.Textbox(label="齿轮箱转速(required_gearbox_speed)") inverter_speed_master_control = gr.Textbox(label="变频器转速(主控)(inverter_speed_master_control)") outside_cabin_temperature = gr.Textbox(label="环境温度(outside_cabin_temperature)") main_bearing_temperature = gr.Textbox(label="主轴承轴承温度(main_bearing_temperature)") gearbox_high_speed_shaft_bearing_temperature = gr.Textbox( label="齿轮箱高速轴轴承温度(gearbox_high_speed_shaft_bearing_temperature)") gearboxmedium_speed_shaftbearing_temperature = gr.Textbox( label="齿轮箱中速轴轴承温度(gearboxmedium_speed_shaftbearing_temperature)") gearbox_low_speed_shaft_bearing_temperature = gr.Textbox( label="齿轮箱低速轴轴承温度(gearbox_low_speed_shaft_bearing_temperature)") generator_winding1_temperature = gr.Textbox(label="发电机绕组1温度(generator_winding1_temperature)") generator_winding2_temperature = gr.Textbox(label="发电机绕组2温度(generator_winding2_temperature)") generator_winding3_temperature = gr.Textbox(label="发电机绕组3温度(generator_winding3_temperature)") turbulence_intensity = gr.Textbox(label="湍流强度(turbulence_intensity)") param1 = gr.Textbox(label="齿轮箱油压(param1)") param2 = gr.Textbox(label="预留字段2(param2)") param3 = gr.Textbox(label="预留字段3(param3)") param4 = gr.Textbox(label="预留字段4(param4)") param5 = gr.Textbox(label="预留字段5(param5)") param6 = gr.Textbox(label="预留字段6(param6)") param7 = gr.Textbox(label="预留字段7(param7)") param8 = gr.Textbox(label="预留字段8(param8)") param9 = gr.Textbox(label="预留字段9(param9)") param10 = gr.Textbox(label="预留字段10(param10)") button = gr.Button(value="提交") result = gr.Textbox(label="结果") button.click(fn=test_click, inputs=[wind_name, wind_full_name, type, is_vertical_table, merge_columns, vertical_read_cols, vertical_index_cols, vertical_col_key, vertical_col_value, resolve_col_prefix, wind_name_exec, wind_turbine_number, time_stamp, active_power, rotor_speed, generator_speed, wind_velocity, pitch_angle_blade_1, pitch_angle_blade_2, pitch_angle_blade_3, cabin_position, true_wind_direction, yaw_error1, set_value_of_active_power, gearbox_oil_temperature, generatordrive_end_bearing_temperature, generatornon_drive_end_bearing_temperature, wind_turbine_status, wind_turbine_status2, cabin_temperature, twisted_cable_angle, 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, outside_cabin_temperature, main_bearing_temperature, gearbox_high_speed_shaft_bearing_temperature, gearboxmedium_speed_shaftbearing_temperature, gearbox_low_speed_shaft_bearing_temperature, generator_winding1_temperature, generator_winding2_temperature, generator_winding3_temperature, turbulence_intensity, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10 ], outputs=[result]) wind_name.change(fill_data, inputs=[wind_name, type], outputs=[wind_full_name, is_vertical_table, merge_columns, vertical_read_cols, vertical_index_cols, vertical_col_key, vertical_col_value, resolve_col_prefix, wind_name_exec, wind_turbine_number, time_stamp, active_power, rotor_speed, generator_speed, wind_velocity, pitch_angle_blade_1, pitch_angle_blade_2, pitch_angle_blade_3, cabin_position, true_wind_direction, yaw_error1, set_value_of_active_power, gearbox_oil_temperature, generatordrive_end_bearing_temperature, generatornon_drive_end_bearing_temperature, wind_turbine_status, wind_turbine_status2, cabin_temperature, twisted_cable_angle, 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, outside_cabin_temperature, main_bearing_temperature, gearbox_high_speed_shaft_bearing_temperature, gearboxmedium_speed_shaftbearing_temperature, gearbox_low_speed_shaft_bearing_temperature, generator_winding1_temperature, generator_winding2_temperature, generator_winding3_temperature, turbulence_intensity, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10]) if __name__ == "__main__": demo.launch(server_name='0.0.0.0', server_port=7860, auth=('znzn', "znzn123"))