# имя: 'Smart zone 1' # описание: рассчитывание состояния зоны # тип триггера: 'EgsObjectUpdated' # создан: 2019.05.07 14.28.41, Сельченков Н.Ю. # изменен: '2019.05.17 12.48.29', Сельченков Н.Ю. # подробности: https://redmine.integra-s.com:11000/projects/eilyacuario/wiki/Smart_zone_1 use acuario2.types.Zone from acuario2.types use acuario2.types.ZoneLink from acuario2.types use acuario2.types.ZoneInputPin from acuario2.types use typedef ` ` as Settings const settings = Settings(trigger.settings) const process_state(zone as Zone) = let items = from zone.zoneOutputPin.GetOppositeItems() select it to array let states = from items group by State bind Key to (from it count all) let threshold = if items.Length > 1 then 1 else 0 let has_alarm = ("alarm" in states) and (states["alarm"] > threshold) let has_error = ("error" in states) or ("none" in states) or ("DEFAULT" in states) let all_ok = ("ok" in states) and ((zone.State isnt "alarm") or (states["ok"] is items.Length)) if items is empty then zone.state = "none_unknown" else if has_alarm then zone.state = "alarm_alarm" else if has_error then zone.state = "error_defective" else if all_ok then zone.state = "ok_normal" end let process_command(zone as Zone, item as Item) = let source = zone["command"].Old ?? zone["command"] let target = item["command"] if source.Text in target.EnumNames then target.Set(source.Text, source.Status, source.DateTime) else target.Set("DEFAULT", Status.invalid, source.DateTime) end eval (from graph.Values of type Zone do process_state(it) now) if "state" in changes then if @object is Item item then from item.GetItemsLinkedTo(ZoneInputPin) of type Zone do process_state(it) now if @object is Zone zone then process_state(zone) end if "command" in changes then if @object is Zone zone then from zone.zoneOutputPin.GetOppositeItems() do process_command(zone, it) now end