Esempio n. 1
0
        private void RefreshAllSeries()
        {
            GeneticAlgorithm?    algorithm       = null;
            Population?          population      = null;
            IEnumerable <Metric>?selectedMetrics = null;

            this.Dispatcher.Invoke(() =>
            {
                algorithm       = this.Algorithm;
                population      = this.Population;
                selectedMetrics = this.SelectedMetrics;
            });

            this.PlotModel.Series.Clear();

            if (algorithm != null && population != null)
            {
                IEnumerable <Metric> metrics = selectedMetrics ?? algorithm.Metrics;
                foreach (Metric metric in metrics)
                {
                    LineSeries series = new LineSeries
                    {
                        Title      = DisplayNameHelper.GetDisplayName(metric),
                        ToolTip    = DisplayNameHelper.GetDisplayNameWithTypeInfo(metric),
                        DataFieldX = nameof(MetricResult.GenerationIndex),
                        DataFieldY = nameof(MetricResult.ResultValue)
                    };

                    ObservableCollection <MetricResult> results = metric.GetResults(population.Index);
                    series.ItemsSource = results;

                    // Verify the results contain values of types that can be converted to double
                    // for the chart to plot.
                    MetricResult firstResult = results.FirstOrDefault();
                    if (firstResult != null)
                    {
                        bool exceptionThrown = false;
                        try
                        {
                            Convert.ToDouble(firstResult.ResultValue, CultureInfo.CurrentCulture);
                        }
                        catch (Exception)
                        {
                            exceptionThrown = true;
                        }

                        if (!exceptionThrown)
                        {
                            this.PlotModel.Series.Add(series);
                        }
                    }
                }
            }

            this.RefreshPlot();
        }
Esempio n. 2
0
        public void DisplayNameHelper_GetDisplayNameWithTypeInfo()
        {
            string result = DisplayNameHelper.GetDisplayNameWithTypeInfo(new TestClass());

            Assert.Equal(TestClassDisplayName + " [" + typeof(TestClass).FullName + "]", result);
        }