Рефактор.
This commit is contained in:
@@ -13,9 +13,9 @@ enum DEVICE_STATUS {
|
||||
}
|
||||
|
||||
const STATUS_CONFIG := {
|
||||
DEVICE_STATE.NONE: {"text": "Нет связи", "color": Color.WHITE, "font_color": Color.BLACK},
|
||||
DEVICE_STATE.GOOD: {"text": "Исправно", "color": Color.GREEN, "font_color": Color.BLACK},
|
||||
DEVICE_STATE.ERR: {"text": "Отказ", "color": Color.RED, "font_color": Color.WHITE}
|
||||
DEVICE_STATE.NONE: {'text': 'Нет связи', 'color': Color.WHITE, 'font_color': Color.BLACK},
|
||||
DEVICE_STATE.GOOD: {'text': 'Исправно', 'color': Color.GREEN, 'font_color': Color.BLACK},
|
||||
DEVICE_STATE.ERR: {'text': 'Отказ', 'color': Color.RED, 'font_color': Color.WHITE}
|
||||
}
|
||||
|
||||
class DeviceObserver:
|
||||
@@ -161,15 +161,15 @@ func _recalculate_overall_state() -> void:
|
||||
|
||||
|
||||
func _update_display() -> void:
|
||||
var config: Dictionary
|
||||
var config: Dictionary = STATUS_CONFIG[overall_prd_state]
|
||||
text = config.text
|
||||
modulate = config.color
|
||||
add_theme_color_override("font_color", config.font_color)
|
||||
add_theme_color_override('font_color', config.font_color)
|
||||
tooltip_text = _get_tooltip_text()
|
||||
|
||||
|
||||
func _get_tooltip_text() -> String:
|
||||
var tooltip := ""
|
||||
var tooltip := ''
|
||||
|
||||
# Получаем статистику по ПРД
|
||||
var prd_summary = _get_prd_summary()
|
||||
@@ -177,17 +177,17 @@ func _get_tooltip_text() -> String:
|
||||
|
||||
match overall_prd_state:
|
||||
DEVICE_STATE.NONE:
|
||||
tooltip = "Нет исправных систем в комплексе"
|
||||
tooltip = 'Нет исправных систем в комплексе'
|
||||
DEVICE_STATE.GOOD:
|
||||
tooltip = "Комплекс исправен"
|
||||
tooltip = 'Комплекс исправен'
|
||||
DEVICE_STATE.ERR:
|
||||
tooltip = "Обнаружены неисправности в комплексе"
|
||||
tooltip = 'Обнаружены неисправности в комплексе'
|
||||
|
||||
tooltip += "\n\nСтатус ПРД систем: " + prd_summary
|
||||
tooltip += "\nСтатус УФ: " + uf_status_str
|
||||
tooltip += '\n\nСтатус ПРД систем: ' + prd_summary
|
||||
tooltip += '\nСтатус УФ: ' + uf_status_str
|
||||
|
||||
# Детализация по источникам статуса
|
||||
tooltip += "\n\nСостояние систем:"
|
||||
tooltip += '\n\nСостояние систем:'
|
||||
|
||||
# ПРД системы
|
||||
var prd_ok_count = 0
|
||||
@@ -198,10 +198,10 @@ func _get_tooltip_text() -> String:
|
||||
if observer.status[DEVICE_STATUS.STATUS]:
|
||||
prd_ok_count += 1
|
||||
|
||||
tooltip += "\nПРД: %d/%d исправно" % [prd_ok_count, prd_total]
|
||||
tooltip += '\nПРД: %d/%d исправно' % [prd_ok_count, prd_total]
|
||||
|
||||
# УФ система
|
||||
tooltip += "\nУФ: " + _get_uf_status_text()
|
||||
tooltip += '\nУФ: ' + _get_uf_status_text()
|
||||
|
||||
return tooltip
|
||||
|
||||
@@ -217,21 +217,21 @@ func _get_prd_summary() -> String:
|
||||
operational_count += 1
|
||||
|
||||
if online_count == 0:
|
||||
return "Нет связи"
|
||||
return 'Нет связи'
|
||||
else:
|
||||
return "%d/%d исправно" % [operational_count, online_count]
|
||||
return '%d/%d исправно' % [operational_count, online_count]
|
||||
|
||||
|
||||
func _get_uf_status_text() -> String:
|
||||
match status_uf:
|
||||
DEVICE_STATE.NONE:
|
||||
return "Нет данных"
|
||||
return 'Нет данных'
|
||||
DEVICE_STATE.GOOD:
|
||||
return "Исправен"
|
||||
return 'Исправен'
|
||||
DEVICE_STATE.ERR:
|
||||
return "Неисправен"
|
||||
return 'Неисправен'
|
||||
_:
|
||||
return "Неизвестно"
|
||||
return 'Неизвестно'
|
||||
|
||||
|
||||
func _has_prd_errors() -> bool:
|
||||
@@ -253,11 +253,11 @@ func get_device_status(device_name: String) -> Dictionary:
|
||||
var observer: DeviceObserver = device_observers.get(device_name)
|
||||
if observer:
|
||||
return {
|
||||
"online": observer.status[DEVICE_STATUS.ONLINE],
|
||||
"operational": observer.status[DEVICE_STATUS.STATUS],
|
||||
"control_complete": observer.status[DEVICE_STATUS.CONTROL],
|
||||
"last_results": observer.last_results,
|
||||
"status_uf": status_uf
|
||||
'online': observer.status[DEVICE_STATUS.ONLINE],
|
||||
'operational': observer.status[DEVICE_STATUS.STATUS],
|
||||
'control_complete': observer.status[DEVICE_STATUS.CONTROL],
|
||||
'last_results': observer.last_results,
|
||||
'status_uf': status_uf
|
||||
}
|
||||
return {}
|
||||
|
||||
@@ -276,10 +276,10 @@ func get_overall_status() -> Dictionary:
|
||||
control_complete_count += 1
|
||||
|
||||
return {
|
||||
"overall_state": overall_prd_state,
|
||||
"online_devices": online_count,
|
||||
"operational_devices": operational_count,
|
||||
"total_devices": device_observers.size(),
|
||||
"control_complete_devices": control_complete_count,
|
||||
"uf_status": status_uf
|
||||
'overall_state': overall_prd_state,
|
||||
'online_devices': online_count,
|
||||
'operational_devices': operational_count,
|
||||
'total_devices': device_observers.size(),
|
||||
'control_complete_devices': control_complete_count,
|
||||
'uf_status': status_uf
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
[ext_resource type="PackedScene" uid="uid://dab6loryocc73" path="res://scenes/эмс/эмс.tscn" id="5_u71bh"]
|
||||
[ext_resource type="PackedScene" uid="uid://musb21x2u0xs" path="res://scenes/эмс2/эмс2.tscn" id="6_41d34"]
|
||||
[ext_resource type="PackedScene" uid="uid://bnptm4rlp60dq" path="res://scenes/настройки/настройки.tscn" id="6_i8iv3"]
|
||||
[ext_resource type="Script" uid="uid://b5ykwyk5vpi6" path="res://scenes/tabs-switch/lbl_ready.gd" id="8_tidwt"]
|
||||
[ext_resource type="Script" uid="uid://b5ykwyk5vpi6" path="res://scenes/tabs-switch/lbl-ready.gd" id="8_tidwt"]
|
||||
[ext_resource type="Script" uid="uid://roajn6c6wvc1" path="res://scenes/tabs-switch/тренаж_режим.gd" id="9_41d34"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_tidwt"]
|
||||
|
||||
@@ -208,7 +208,7 @@ func _initialize_default_states() -> void:
|
||||
'ems_g_sock_dic': ems_g_sock_dic.duplicate(true),
|
||||
|
||||
# Структуры данных (глубокое копирование)
|
||||
'power_for_litera': _deep_copy_power_structure(),
|
||||
'power_for_litera': power_for_litera.duplicate(true),
|
||||
'control_results': control_results.duplicate(true),
|
||||
'power_result': power_result.duplicate(true),
|
||||
'temperature_um': temperature_um.duplicate(true),
|
||||
@@ -1140,16 +1140,15 @@ static func _create_fs_mapping(s_name: String) -> Dictionary:
|
||||
|
||||
## Получение статуса ФС
|
||||
static func on_fs_state(packet_type_7: Dictionary, fs_mapping: Dictionary, fs_results: Dictionary, fs_rules_config: Array) -> Dictionary:
|
||||
var updated_results := fs_results
|
||||
for fs_num in packet_type_7:
|
||||
if not (fs_num in fs_mapping and fs_mapping[fs_num]['condition']):
|
||||
continue
|
||||
var fs_data = packet_type_7[fs_num]
|
||||
for rule in fs_rules_config:
|
||||
if _should_apply_rule(fs_num, rule, updated_results):
|
||||
updated_results[rule.key] = fs_data.isg
|
||||
if _should_apply_rule(fs_num, rule, fs_results):
|
||||
fs_results[rule.key] = fs_data.isg
|
||||
break
|
||||
return updated_results
|
||||
return fs_results
|
||||
|
||||
|
||||
## Вспомогательная функция для проверки применения правила
|
||||
@@ -1288,7 +1287,7 @@ static func check_dou_result(control_dic: Dictionary, power_dic: Dictionary, pri
|
||||
|
||||
var ray_dic: Dictionary = power_dic[litera]
|
||||
# Проверка наличия данных
|
||||
if ray_dic[RAY_m5].size() == 0 or \
|
||||
if ray_dic[RAY_m5].size() == 0 or \
|
||||
ray_dic[RAY_5 ].size() == 0 or \
|
||||
ray_dic[RAY_15].size() == 0 or \
|
||||
ray_dic[RAY_25].size() == 0 or \
|
||||
@@ -1301,7 +1300,7 @@ static func check_dou_result(control_dic: Dictionary, power_dic: Dictionary, pri
|
||||
var low_power_by_position: Array = [0, 0, 0, 0, 0, 0] # Счетчики для 6 позиций
|
||||
for ray_key in [RAY_m5, RAY_5, RAY_15, RAY_25, RAY_35, RAY_45]:
|
||||
var power_array: Array = ray_dic[ray_key]
|
||||
for i in range(power_array.size()):
|
||||
for i in power_array.size():
|
||||
if power_array[i] < cnst.POWER_THRESHOLD:
|
||||
low_power_by_position[i] += 1
|
||||
|
||||
@@ -1316,14 +1315,7 @@ static func check_dou_result(control_dic: Dictionary, power_dic: Dictionary, pri
|
||||
#endregion
|
||||
|
||||
#region DEFAULT_STATES
|
||||
## Глубокое копирование структуры мощностей
|
||||
func _deep_copy_power_structure() -> Dictionary:
|
||||
var copy = {}
|
||||
for litera in power_for_litera:
|
||||
copy[litera] = {}
|
||||
for ray_type in power_for_litera[litera]:
|
||||
copy[litera][ray_type] = power_for_litera[litera][ray_type]
|
||||
return copy
|
||||
|
||||
|
||||
## Восстановление состояний по умолчанию
|
||||
func restore_default_states() -> void:
|
||||
@@ -1358,6 +1350,7 @@ func restore_default_states() -> void:
|
||||
|
||||
_set_status('Состояния сброшены к значениям по умолчанию')
|
||||
|
||||
|
||||
## Получение текущих состояний для отладки
|
||||
func get_current_states() -> Dictionary:
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user