Ejemplo n.º 1
0
        private void timerCharts_Tick(object sender, EventArgs e)
        {
            if (connection_selected.is_connected_to_plant == true)
            {
                // add the correct number of reference series
                Charting.ManageReferenceSeries(this);

                // update charts
                UpdateChart(connection_selected.references, setting: DataPointSetting.ADD_LATEST);       // reference
                UpdateChart(connection_selected.received_packets, setting: DataPointSetting.ADD_LATEST); // states
                UpdateChart(connection_selected.estimates, setting: DataPointSetting.ADD_LATEST);        // kalman filter estimates

                // update time axis minimum and maximum
                Charting.UpdateChartAxes(dataChart, time_chart_window);
                Charting.UpdateChartAxes(residualChart, time_chart_window);
                Charting.UpdateChartAxes(securityChart, time_chart_window);
            }

            // update time labels
            Helpers.UpdateTimeLabels(this, connection_selected, Constants.FMT);

            // draw simulation (currently only supporing double watertank)
            if (plant_visualization == PlantVisualization.DOUBLE_WATERTANK)
            {
                Animation.DrawTanks(this, connection_selected);
            }
        }
Ejemplo n.º 2
0
 public void updateThresholdStripLines()
 {
     Charting.ClearThresholdStripLines(residualChart);
     Charting.AddThresholdStripLine(residualChart, offset: 0, color: Color.Red);
     Charting.AddThresholdStripLine(residualChart, offset: connection_selected.kalman_filter.getDelta(), color: Color.Red);
     Charting.AddThresholdStripLine(residualChart, offset: -connection_selected.kalman_filter.getDelta(), color: Color.Red);
 }
Ejemplo n.º 3
0
        private void InitialSettings()
        {
            // application directory
            file_path           = Directory.GetCurrentDirectory();
            toolStripLabel.Text = "Dir: " + file_path;

            // chart settings
            Charting.ClearThresholdStripLines(residualChart);
            Charting.AddThresholdStripLine(residualChart, offset: 0, color: Color.Red);
            Charting.AddThresholdStripLine(residualChart, offset: config.anomalyDetector.cusumDelta, color: Color.Red);
            Charting.AddThresholdStripLine(residualChart, offset: -config.anomalyDetector.cusumDelta, color: Color.Red);

            Charting.InitializeChartSettings(dataChart, title: "");
            Charting.InitializeChartSettings(residualChart, title: "");
            Charting.InitializeChartSettings(securityChart, title: "Magnitude");
        }
Ejemplo n.º 4
0
        private void timerUpdateGUI_Tick(object sender, EventArgs e)
        {
            // update tree information
            Helpers.UpdateTree(this, connection_selected);

            // enable or disable reference track bars
            Helpers.ManageTrackbars(this);

            // scale y-axis for the charts
            Charting.ChangeYScale(dataChart, treshold_interval: "one", grid_interval: "adaptive");
            Charting.ChangeYScale(residualChart, treshold_interval: "one", grid_interval: "adaptive");
            Charting.ChangeYScale(securityChart, treshold_interval: "one", grid_interval: "adaptive");

            labelSecurity.Text = "Security metric: " + Math.Round(connection_selected.kalman_filter.security_metric, 1) + Environment.NewLine +
                                 "Status: " + connection_selected.kalman_filter.security_status;
        }
Ejemplo n.º 5
0
        private void listBoxControllers_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                // specify the new connection as the currently selected one
                connection_selected = connections[listBoxModules.SelectedIndex];

                // enable or disable reference track bars
                Helpers.ManageTrackbars(this);

                // update GUI values according to the connected controller
                Helpers.UpdateGuiControls(this, connection_selected);

                // clear charts
                dataChart.Series.Clear();
                residualChart.Series.Clear();
                securityChart.Series.Clear();

                // clear checkbox series
                clbSeries.Items.Clear();

                // refresh the chart, load all data points
                UpdateChart(connection_selected.references, setting: DataPointSetting.LOAD_ALL);       // reference
                UpdateChart(connection_selected.received_packets, setting: DataPointSetting.LOAD_ALL); // states
                UpdateChart(connection_selected.estimates, setting: DataPointSetting.LOAD_ALL);        // kalman filter estimates

                // scale y-axis for the charts
                Charting.ChangeYScale(dataChart, treshold_interval: "one", grid_interval: "one");
                Charting.ChangeYScale(residualChart, treshold_interval: "one", grid_interval: "one");
                Charting.ChangeYScale(securityChart, treshold_interval: "one", grid_interval: "one");

                // update treshold strip lines
                updateThresholdStripLines();

                // select the corresponding item in the treeview
                treeViewControllers.SelectedNode = treeViewControllers.Nodes[connection_selected.name];
            }
            catch { }
        }
Ejemplo n.º 6
0
 private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
 {
     Charting.ManageChartSize(this);
 }
Ejemplo n.º 7
0
 private void FrameGUI_Resize(object sender, EventArgs e)
 {
     Charting.ManageChartSize(this);
 }
Ejemplo n.º 8
0
        private void UpdateChart(Dictionary <string, DataContainer> dict, string setting)
        {
            // get all keys from the current dictionary
            var keys = dict.Keys.ToList();

            // update the graphs for each key
            foreach (string key in keys)
            {
                // if series does not exist, add it
                if (dataChart.Series.IndexOf(key) == -1)
                {
                    Charting.AddChartSeries(this, key, dataChart);
                }

                // data load setting
                int index_start;

                if (setting == DataPointSetting.LOAD_ALL)
                {
                    index_start = 0;                                // draw all data points
                }
                else if (setting == DataPointSetting.ADD_LATEST)
                {
                    index_start = dict[key].time.Length - 1;        // draw the last data point
                }
                else
                {
                    index_start = dict[key].time.Length - 1;        // draw the last data point
                }
                // add data point(s)
                for (int i = index_start; i < dict[key].time.Length; i++)
                {
                    if (dict[key].time[i] != null)
                    {
                        DateTime time = DateTime.ParseExact(dict[key].time[i], Constants.FMT, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
                        dataChart.Series[key].Points.AddXY(time.ToOADate(), Convert.ToDouble(dict[key].value[i]));

                        // plot residuals for flagged states
                        if (dict[key].has_residual == true)
                        {
                            // if residual series does not exist, add it
                            if (residualChart.Series.IndexOf("Res_" + key) == -1)
                            {
                                Charting.AddChartSeries(this, "Res_" + key, residualChart);
                            }
                            residualChart.Series["Res_" + key].Points.AddXY(time.ToOADate(), Convert.ToDouble(dict[key].residual[i]));

                            // if security metric series does not exist, add it
                            if (securityChart.Series.IndexOf("Sec_" + key) == -1)
                            {
                                Charting.AddChartSeries(this, "Sec_" + key, securityChart);
                            }
                            securityChart.Series["Sec_" + key].Points.AddXY(time.ToOADate(), Convert.ToDouble(dict[key].security_metric[i]));
                        }
                    }
                }

                // remove old data points
                if (dataChart.Series[key].Points.Count > Constants.n_datapoints_max)
                {
                    dataChart.Series[key].Points.RemoveAt(0);
                    if (dict[key].has_residual)
                    {
                        residualChart.Series["Res_" + key].Points.RemoveAt(0);
                        securityChart.Series["Sec_" + key].Points.RemoveAt(0);
                    }
                }
            }
        }