View unanswered posts | View active topics It is currently 2018-08-20 9:23



This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
 subnetwork 显示当前子网中,有告警的设备总数 
Author Message
新手上路

Joined: 2015-07-09 11:26
Posts: 3
Post subnetwork 显示当前子网中,有告警的设备总数
目前,子网中有10个设备,有2个设备有告警,告警条数分别为4条、5条。想在子网上,直接显示有告警的设备数,也就是2。
我想到的解决办法就是统计子网下的设备数2个,然后根据设备数生成2条告警,再挂到子网上。
有没有其他方法实现?


2015-09-14 19:25
Profile
初级会员

Joined: 2015-04-07 9:27
Posts: 105
Post Re: subnetwork 显示当前子网中,有告警的设备总数
您好,您的需求就是子网向上传播告警的时候,换一种显示方式,而不是用原来默认的加边框的形式吧?这种新的显示方式需要能标注其告警子节点的数量?


2015-09-17 10:50
Profile
新手上路

Joined: 2015-07-09 11:26
Posts: 3
Post Re: subnetwork 显示当前子网中,有告警的设备总数
Chao wrote:
您好,您的需求就是子网向上传播告警的时候,换一种显示方式,而不是用原来默认的加边框的形式吧?这种新的显示方式需要能标注其告警子节点的数量?

嗯,就是这个效果。怎么方便实现


2015-09-22 9:38
Profile
TWaver开发组
User avatar

Joined: 2009-04-20 18:37
Posts: 3115
Post Re: subnetwork 显示当前子网中,有告警的设备总数
还有个疑问是如果父亲本身也有告警,那孩子累计的告警数和自己的告警数要叠加,还是怎么处理?
下面的实现是直接用孩子累计的告警覆盖了父亲的告警,通过重写twaver.AlarmStatePropagator.prototype.propagateToParent实现:
Code:
      twaver.AlarmStatePropagator.prototype.propagateToParent = function (child, parent) {
        var result = null,
          count = 0;
        if (parent.hasChildren()) {
          parent.getChildren().forEach(function (child) {
            if (child.getAlarmState().getHighestNativeAlarmSeverity() != null) {
              count ++;
            }
            var severity = child.getAlarmState().getHighestOverallAlarmSeverity();
            if (twaver.AlarmSeverity.compare(severity, result) > 0) {
              result = severity;
            }
          });
          parent.getAlarmState().clear();
          if (result != null) {
            parent.getAlarmState().setNewAlarmCount(result, count);
          }
        }
      }

Attachment:
Screen Shot 2015-09-22 at 10.34.47 AM.png
Screen Shot 2015-09-22 at 10.34.47 AM.png [ 19.1 KiB | Viewed 5656 times ]

完整代码:
Code:
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="pragma" content="no-cache">
  <meta charset="UTF-8">
  <title></title>
  <script type="text/javascript" src="../twaver.js"></script>
  <script type="text/javascript">
   
    var box = new twaver.ElementBox();
    var network = new twaver.vector.Network(box);
    var toolbar = document.createElement('div');
   
    function init () {
      twaver.Styles.setStyle('select.style', 'border');
      initToolbar();
      var pane = new twaver.controls.BorderPane(network, toolbar);
      pane.setTopHeight(25);
      var view = pane.getView();
      view.style.left = '0px';
      view.style.top = '0px';
      view.style.right = '0px';
      view.style.bottom = '0px';
      document.body.appendChild(view);
      window.onresize = function () {
        pane.invalidate();
      };
   
      twaver.AlarmStatePropagator.prototype.propagateToParent = function (child, parent) {
        var result = null,
          count = 0;
        if (parent.hasChildren()) {
          parent.getChildren().forEach(function (child) {
            if (child.getAlarmState().getHighestNativeAlarmSeverity() != null) {
              count ++;
            }
            var severity = child.getAlarmState().getHighestOverallAlarmSeverity();
            if (twaver.AlarmSeverity.compare(severity, result) > 0) {
              result = severity;
            }
          });
          parent.getAlarmState().clear();
          if (result != null) {
            parent.getAlarmState().setNewAlarmCount(result, count);
          }
        }
      }
      initBox();
    }
   
    function initBox () {
      var group = new twaver.Group();
      group.setExpanded(true);
      box.add(group);

      var from = new twaver.Node();
      from.setName('From');
      from.getAlarmState().increaseNewAlarm(twaver.AlarmSeverity.CRITICAL);
      from.setLocation(100, 100);
      group.addChild(from);
      box.add(from);
     
      var to = new twaver.Group();
      to.setName('To');
      to.getAlarmState().increaseNewAlarm(twaver.AlarmSeverity.MAJOR);
      to.setLocation(300, 300);
      group.addChild(to);
      box.add(to);
     
      var link = new twaver.Link(from, to);
      link.setName('Link');
      group.addChild(link);
      box.add(link);
    }
   
    function initToolbar() {
      addButton(toolbar, 'Zoom In', function () {
        network.zoomIn();
      });
      addButton(toolbar, 'Zoom Out', function () {
        network.zoomOut();
      });
      addButton(toolbar, 'Zoom Overview', function () {
        network.zoomOverview();
      });
      addButton(toolbar, 'Zoom Reset', function () {
        network.zoomReset();
      });
    }
   
    function addButton(toolbar, label, handler) {
      var button = document.createElement('input');
      button.type = 'button';
      button.value =  label;
      button.onclick = handler;
      toolbar.appendChild(button);
    }
   
  </script>
</head>
<body onload="init()">
</body>
</html>


2015-09-22 10:35
Profile
TWaver开发组
User avatar

Joined: 2009-04-20 18:37
Posts: 3115
Post Re: subnetwork 显示当前子网中,有告警的设备总数
抱歉,上面是HTML5的实现,.Net实现如下,替换demo中的PSTNDemo:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Demo;
using Demo.Topology.PSTN;
using TWaver;
using TWaver.Network;
using System.Windows.Threading;

namespace Demo.Topology
{
    public partial class PSTNDemo : UserControl, IDemo
    {
        private const string BLINK = "blink";

        private ElementBox box;
        private Network network;
        private Overview overview;

        public PSTNDemo()
        {
            InitializeComponent();
            InitBox();
            DemoUtils.InitToolbar(this.network, Toolbar);
            this.LayoutRoot.Children.Add(this.network);
            this.overview = DemoUtils.InitOverview(this.network, this.LayoutRoot);
        }

        private void InitBox()
        {
            this.network = new Network();
            this.box = this.network.ElementBox;

            box.AlarmStatePropagator.IsEnable = false;
            new CustomAlarmStatePropagator(box).IsEnable = true;

            var group = new Group();
            group.IsExpanded = true;
            box.Add(group);

            var from = new Node();
            from.Name = "From";
            from.AlarmState.IncreaseNewAlarm(AlarmSeverity.CRITICAL);
            from.SetLocation(100, 100);
            group.AddChild(from);
            box.Add(from);
     
            var to = new Group();
            to.Name = "To";
            to.AlarmState.IncreaseNewAlarm(AlarmSeverity.MAJOR);
            to.SetLocation(300, 300);
            group.AddChild(to);
            box.Add(to);
     
            var link = new Link(from, to);
            link.Name = "Link";
            group.AddChild(link);
            box.Add(link);
        }

        private void Tick()
        {
           
        }

        public Network Network
        {
            get { return this.network; }
        }

        public void OnShown()
        {
            this.overview.SetVisible(true);
        }

        public void OnHidden()
        {
            this.overview.SetVisible(false);
        }
    }

    public class CustomAlarmStatePropagator : AlarmStatePropagator
    {
        public CustomAlarmStatePropagator(ElementBox elementBox)
            :base(elementBox)
        {

        }

        protected override void PropagateToParent(IElement child, IElement parent)
        {
            AlarmSeverity result = null;
            uint count = 0;
            if (parent.HasChildren)
            {
                foreach (IData c in parent.Children)
                {
                    IElement element = (IElement)c;
                    if (element.AlarmState.HighestNativeAlarmSeverity != null)
                    {
                        count++;
                    }
                    var severity = element.AlarmState.HighestOverallAlarmSeverity;
                    if (AlarmSeverity.Compare(severity, result) > 0)
                    {
                        result = severity;
                    }
                }
                parent.AlarmState.Clear();
                if (result != null)
                {
                    parent.AlarmState.SetNewAlarmCount(result, count);
                }
            }
        }
    }
}


2015-09-22 10:54
Profile
新手上路

Joined: 2015-07-09 11:26
Posts: 3
Post Re: subnetwork 显示当前子网中,有告警的设备总数
paul wrote:
还有个疑问是如果父亲本身也有告警,那孩子累计的告警数和自己的告警数要叠加,还是怎么处理?
下面的实现是直接用孩子累计的告警覆盖了父亲的告警,通过重写twaver.AlarmStatePropagator.prototype.propagateToParent实现:
Code:
      twaver.AlarmStatePropagator.prototype.propagateToParent = function (child, parent) {
        var result = null,
          count = 0;
        if (parent.hasChildren()) {
          parent.getChildren().forEach(function (child) {
            if (child.getAlarmState().getHighestNativeAlarmSeverity() != null) {
              count ++;
            }
            var severity = child.getAlarmState().getHighestOverallAlarmSeverity();
            if (twaver.AlarmSeverity.compare(severity, result) > 0) {
              result = severity;
            }
          });
          parent.getAlarmState().clear();
          if (result != null) {
            parent.getAlarmState().setNewAlarmCount(result, count);
          }
        }
      }

Attachment:
The attachment Screen Shot 2015-09-22 at 10.34.47 AM.png is no longer available

完整代码:
Code:
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="pragma" content="no-cache">
  <meta charset="UTF-8">
  <title></title>
  <script type="text/javascript" src="../twaver.js"></script>
  <script type="text/javascript">
   
    var box = new twaver.ElementBox();
    var network = new twaver.vector.Network(box);
    var toolbar = document.createElement('div');
   
    function init () {
      twaver.Styles.setStyle('select.style', 'border');
      initToolbar();
      var pane = new twaver.controls.BorderPane(network, toolbar);
      pane.setTopHeight(25);
      var view = pane.getView();
      view.style.left = '0px';
      view.style.top = '0px';
      view.style.right = '0px';
      view.style.bottom = '0px';
      document.body.appendChild(view);
      window.onresize = function () {
        pane.invalidate();
      };
   
      twaver.AlarmStatePropagator.prototype.propagateToParent = function (child, parent) {
        var result = null,
          count = 0;
        if (parent.hasChildren()) {
          parent.getChildren().forEach(function (child) {
            if (child.getAlarmState().getHighestNativeAlarmSeverity() != null) {
              count ++;
            }
            var severity = child.getAlarmState().getHighestOverallAlarmSeverity();
            if (twaver.AlarmSeverity.compare(severity, result) > 0) {
              result = severity;
            }
          });
          parent.getAlarmState().clear();
          if (result != null) {
            parent.getAlarmState().setNewAlarmCount(result, count);
          }
        }
      }
      initBox();
    }
   
    function initBox () {
      var group = new twaver.Group();
      group.setExpanded(true);
      box.add(group);

      var from = new twaver.Node();
      from.setName('From');
      from.getAlarmState().increaseNewAlarm(twaver.AlarmSeverity.CRITICAL);
      from.setLocation(100, 100);
      group.addChild(from);
      box.add(from);
     
      var to = new twaver.Group();
      to.setName('To');
      to.getAlarmState().increaseNewAlarm(twaver.AlarmSeverity.MAJOR);
      to.setLocation(300, 300);
      group.addChild(to);
      box.add(to);
     
      var link = new twaver.Link(from, to);
      link.setName('Link');
      group.addChild(link);
      box.add(link);
    }
   
    function initToolbar() {
      addButton(toolbar, 'Zoom In', function () {
        network.zoomIn();
      });
      addButton(toolbar, 'Zoom Out', function () {
        network.zoomOut();
      });
      addButton(toolbar, 'Zoom Overview', function () {
        network.zoomOverview();
      });
      addButton(toolbar, 'Zoom Reset', function () {
        network.zoomReset();
      });
    }
   
    function addButton(toolbar, label, handler) {
      var button = document.createElement('input');
      button.type = 'button';
      button.value =  label;
      button.onclick = handler;
      toolbar.appendChild(button);
    }
   
  </script>
</head>
<body onload="init()">
</body>
</html>

感谢你的回答。最终要的效果已经实现。subnetwork(父)下有无限层的subnetwork(父),最终我需要的是node(子)类型的告警统计。


Attachments:
jietu.png
jietu.png [ 17.87 KiB | Viewed 5654 times ]
2015-09-22 14:53
Profile
TWaver开发组
User avatar

Joined: 2014-02-11 8:59
Posts: 575
Post Re: subnetwork 显示当前子网中,有告警的设备总数
:love:


2015-10-08 17:30
Profile
Display posts from previous:  Sort by  
This topic is locked, you cannot edit posts or make further replies.   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: