aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/RestartingSystemView.xaml
blob: 996b1788df8ad6cce896f2d183d5ea4a84a73637 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<UserControl x:Class="Tango.PPC.UI.Views.RestartingSystemView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:global="clr-namespace:Tango.PPC.UI"
             xmlns:vm="clr-namespace:Tango.PPC.UI.ViewModels"
             xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Tango.PPC.UI.Views"
             mc:Ignorable="d" 
             d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:RestartingSystemViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.RestartingSystemViewVM}" Background="{StaticResource TangoPrimaryBackgroundBrush}">
    <Grid>

        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
            <touch:TouchBusyIndicator Width="350" Height="350" IsIndeterminate="{Binding IsVisible}" Foreground="{StaticResource TangoGrayBrush}" />
            <TextBlock Margin="0 40 0 0" TextAlignment="Center" HorizontalAlignment="Center" FontSize="{StaticResource TangoTitleFontSize}" Foreground="{StaticResource TangoGrayTextBrush}">
                <Run>
                    Setup completed.
                </Run>
                <LineBreak/>
                <Run>
                    Restarting the system for the last time...
                </Run>                
            </TextBlock>
        </StackPanel>
    </Grid>
</UserControl>
0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.CSV;
using Tango.DispenserAnalyzer.UI.Analysis;
using Tango.DispenserAnalyzer.UI.Models;

namespace Tango.DispenserAnalyzer.UI.Analyzers
{
    [Analyzer("process")]
    public class ProcessAnalyser : IProcessAnalyzer
    {
        private IReader<ProcessSample> _reader;
        public IReader<ProcessSample> Reader {
            get { return _reader; }
            set { _reader = value;  }
        }

        public ProcessAnalyser()
        {
            Reader = new ProcessReader();
        }

        public Task<List<IAnalyzerResult>> Process(List<ProcessSample> csvRows, bool backgroundMode)
        {
            return Task.Factory.StartNew<List<IAnalyzerResult>>(() =>
            {
                List<IAnalyzerResult> results = new List<IAnalyzerResult>();
                ProcessAnalyzerResult result = new ProcessAnalyzerResult();
                result.BackgroundMode = backgroundMode;
                double delta = Settings.GetValueByName(AnalyzerSettingsEnum.TimeInterval);
                int startPoint = delta == 0? 0 : (int)(Settings.GetValueByName(AnalyzerSettingsEnum.StartCalculation) / delta);
                int endPoint = delta == 0 ? (csvRows.Count -1) : (int)(Settings.GetValueByName(AnalyzerSettingsEnum.EndCalculation) / delta);
                int takePoints = endPoint > startPoint ? (endPoint - startPoint) : (csvRows.Count - 1 - startPoint);
                
                List<ProcessSample> rangeValues = csvRows.Skip(startPoint).Take(takePoints).ToList();

                result.MinValue = rangeValues.Min(x => x.Value);
                result.MaxValue = rangeValues.Max(x => x.Value);
                result.AverageValue = rangeValues.Average(x => x.Value);
                result.StandardDeviation = ProcessAnalyser.StdDev(rangeValues.Select(x => x.Value));

                result.Result = AnalyzerResultValue.Passed;

                //Move Average data
                List<Task> tasks = new List<Task>();
                int calc_count = (int)csvRows.Count() / 4;
                int start_index = 0;
                while (start_index < csvRows.Count())
                {
                    int calc_amount = (start_index + calc_count) >= (csvRows.Count() - 4) ? csvRows.Count() - start_index : calc_count;
                    var source_filter = csvRows.Skip(start_index).Take(calc_amount).ToList();
                    tasks.Add(Task.Run(() =>
                    {
                        ProcessAnalyser.Filtering(source_filter);
                    }));
                    start_index += calc_amount;
                }
                Task.WaitAll(tasks.ToArray());

                result.CreateMovingAvgGraph(csvRows);
                results.Add(result);
                return results;
            });
        }

        public static double StdDev(IEnumerable<double> values)
        {
            double avg = values.Average();
            double sum = values.Sum(v => (v - avg) * (v - avg));
            double denominator = values.Count() - 1;
            return denominator > 0.0 ? Math.Sqrt(sum / denominator) : -1;
        }
        public static void Filtering(List<ProcessSample> source)
        {
            int periodAverage = (int)Settings.GetValueByName(AnalyzerSettingsEnum.MovingAvg);
            int count = (source.Count < periodAverage) ? source.Count : source.Count - periodAverage;
            for (int i = 0; i < count; i++)
            {
                source[i].Value = source.Skip(i).Take(periodAverage).Average(x => x.Value);
            }
        }

        public void GetPoints(List<ProcessSample> samples, IList<OxyPlot.DataPoint> points)
        {
            samples.ForEach(x =>
            {
                points.Add(new OxyPlot.DataPoint(x.TimeIntervalSec, x.Value));
            });
        }

    }

    public class ProcessAnalyzerResult : AnalyzerResultBase
    {
        [Description("Selected Area")]
        public string Header { get; set; }

        [Description("Average Value")]
        public double AverageValue { get; set; }
        [Description("Max value")]
        public double MaxValue { get; set; }
        [Description("Min value")]
        public double MinValue { get; set; }
        [Description("Standard deviation value")]
        public double StandardDeviation { get; set; }


        public ProcessAnalyzerResult()
        {
            double from = Settings.GetValueByName(AnalyzerSettingsEnum.StartCalculation);
            double to = Settings.GetValueByName(AnalyzerSettingsEnum.EndCalculation);
            Header = $"from {from} to {to} seconds";
            AverageValue = MaxValue = MinValue = 0.0;
            Result = AnalyzerResultValue.Undetermined;
            IsShowLineChartResult = true;
        }

        public void CreateMovingAvgGraph(List<ProcessSample> avgValues)
        {
            if (!BackgroundMode)
            {
                var points = LineChart.Points;
                points.Clear();
                avgValues.ForEach(x =>
                {
                    points.Add(new OxyPlot.DataPoint(x.TimeIntervalSec, x.Value));
                });
                
                LineChart.Title = $"Moving Average Values";
                LineChart.UpdateData();
            }
        }

    }
}