示例#1
0
        public void StartListening()
        {
            _runInformations  = RunInformations.GetOrNewInstance();
            _customStatistics = CustomStatistics.GetOrNewInstance();

            Task.Run(() =>
            {
                while (_runInformations.runStatus == RunInformations.RunStatus.Running)
                {
                    if (Console.KeyAvailable)
                    {
                        ConsoleKeyInfo pressed = Console.ReadKey(true);

                        switch (pressed.Key)
                        {
                        case ConsoleKey.S:
                            {
                                _customStatistics.DisplayCustomStatistics();

                                break;
                            }
                        }
                    }

                    Thread.Sleep(100);
                }
            });
        }
示例#2
0
        public MilkyManager()
        {
            KeyboardListener = KeyboardListener.GetOrNewInstance();

            ConsoleLoops    = ConsoleLoops.GetOrNewInstance();
            LoopsManager    = LoopsManager.GetOrNewInstance();
            StatisticsLoops = StatisticsLoops.GetOrNewInstance();

            OutputSettings = OutputSettings.GetOrNewInstance();

            ProgramInformations = ProgramInformations.GetOrNewInstance();
            ProgramManager      = ProgramManager.GetOrNewInstance();

            RunInformations = RunInformations.GetOrNewInstance();
            RunLists        = RunLists.GetOrNewInstance();
            RunManager      = RunManager.GetOrNewInstance();

            ConsoleSettings = ConsoleSettings.GetOrNewInstance();
            RunSettings     = RunSettings.GetOrNewInstance();

            CustomStatistics = CustomStatistics.GetOrNewInstance();
            RunStatistics    = RunStatistics.GetOrNewInstance();

            ConsoleUtils  = ConsoleUtils.GetOrNewInstance();
            DateTimeUtils = DateTimeUtils.GetOrNewInstance();
            FileUtils     = FileUtils.GetOrNewInstance();
            FormatUtils   = FormatUtils.GetOrNewInstance();
            HashUtils     = HashUtils.GetOrNewInstance();
            ListUtils     = ListUtils.GetOrNewInstance();
            RequestUtils  = RequestUtils.GetOrNewInstance();
            StringUtils   = StringUtils.GetOrNewInstance();
            UserUtils     = UserUtils.GetOrNewInstance();
        }
示例#3
0
        private List <double> GetValueBasedOnCalculationSelection(CustomStatistics customStatisticsRelatedToKPI)
        {
            List <double> valuesFromChoosenClients = new List <double>();
            List <int>    mappedClientID           = _StoredProcedure.GetClientMapByStatisticsFavoriteID(customStatisticsRelatedToKPI.ID);
            List <Client> tempClients = new List <Client>();

            foreach (int clientID in mappedClientID)
            {
                tempClients.Add(_StoredProcedure.GetClientByID(clientID));
            }

            customStatisticsRelatedToKPI.ChoosenClients = tempClients;

            foreach (Client client in customStatisticsRelatedToKPI.ChoosenClients)
            {
                switch (customStatisticsRelatedToKPI.ChoosenStatisticsCalculationID)
                {
                case 1:
                    foreach (double totalHoursValue in _StoredProcedure.GetTotalHoursByClientID(client.ClientID))
                    {
                        valuesFromChoosenClients.Add(totalHoursValue);
                    }
                    break;

                case 2:
                    foreach (double salesAmountValue in _StoredProcedure.GetSalesAmountByClientID(client.ClientID))
                    {
                        valuesFromChoosenClients.Add(salesAmountValue);
                    }
                    break;

                case 3:
                    foreach (double totalConsumptionValue in _StoredProcedure.GetTotalConsumptionByClientID(client.ClientID))
                    {
                        valuesFromChoosenClients.Add(totalConsumptionValue);
                    }
                    break;

                case 4:
                    foreach (double balanceValue in _StoredProcedure.GetNegativeBalanceByClientID(client.ClientID))
                    {
                        valuesFromChoosenClients.Add(balanceValue);
                    }
                    break;

                case 5:
                    foreach (double balanceValue in _StoredProcedure.GetPositiveBalanceByClientID(client.ClientID))
                    {
                        valuesFromChoosenClients.Add(balanceValue);
                    }
                    break;

                default:
                    break;
                }
            }

            return(valuesFromChoosenClients);
        }
示例#4
0
        public void Should_ReturnZeroAverage_When_EmptyListProvided()
        {
            List <double> listOfData = new List <double>()
            {
            };

            Assert.AreEqual(0, CustomStatistics.Average(listOfData));
        }
示例#5
0
        public void Should_ComputeSum_When_DecimalListProvided()
        {
            List <double> listOfData = new List <double>()
            {
                10.2, 5, 3.6, 6.0, 4.5
            };

            Assert.AreEqual(29.3, CustomStatistics.Sum(listOfData));
        }
示例#6
0
        public void Should_Count_When_ListProvided()
        {
            List <double> listOfData = new List <double>()
            {
                10, 5, 3, 6
            };

            Assert.AreEqual(4, CustomStatistics.Count(listOfData));
        }
示例#7
0
        public void Should_ComputeAverage_When_PositiveListProvided()
        {
            List <double> listOfData = new List <double>()
            {
                10, 5, 3, 6
            };

            Assert.AreEqual(6, CustomStatistics.Average(listOfData));
        }
示例#8
0
        public void Should_ComputeHighest_When_PositiveListProvided()
        {
            List <double> listOfData = new List <double>()
            {
                10, 5, 3, 6
            };

            Assert.AreEqual(10, CustomStatistics.Highest(listOfData));
        }
示例#9
0
        public void Should_ComputeHighest_When_NegativeListProvided()
        {
            List <double> listOfData = new List <double>()
            {
                -10, -5, -3, -6
            };

            Assert.AreEqual(-3, CustomStatistics.Highest(listOfData));
        }
示例#10
0
        public void Should_ComputeAverage_When_OverTwoDecimalListProvided()
        {
            List <double> listOfData = new List <double>()
            {
                10.0, 5, 3, 6.78, 4.5
            };

            Assert.AreEqual(5.86, CustomStatistics.Average(listOfData));
        }
示例#11
0
        public void Should_ComputeHighest_When_DecimalListProvided()
        {
            List <double> listOfData = new List <double>()
            {
                10.2, 5, 3, 6.0, 4.5
            };

            Assert.AreEqual(10.2, CustomStatistics.Highest(listOfData));
        }
示例#12
0
        public IActionResult PostCustomStatistics([FromBody] CustomStatistics customStatistics)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var currentUser = _context.Users.First(u => u.Id == User.Identity.GetUserId());

            customStatistics.ApplicationUser = currentUser;
            _customStatisticsRepository.AddNewStatistic(customStatistics);
            return(Ok());
        }
示例#13
0
        public CustomStatistics GetStatisticsFavoriteByID(int requestedStatisticsFavoriteID)
        {
            CustomStatistics statisticsFavorites = new CustomStatistics();

            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                try
                {
                    con.Open();

                    SqlCommand sqlCmd = new SqlCommand("sp_GetStatisticsFavoriteByID", con)
                    {
                        CommandType = CommandType.StoredProcedure
                    };

                    sqlCmd.Parameters.Add(new SqlParameter("@StatisticsFavoriteID", requestedStatisticsFavoriteID));

                    SqlDataReader reader = sqlCmd.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            string statisticsFavoriteID = reader["StatisticsFavoriteID"].ToString();
                            string name                    = reader["Name"].ToString();
                            string statisticsTypeID        = reader["FK_StatisticsTypeID"].ToString();
                            string statisticsCalculationID = reader["FK_StatisticsCalculationID"].ToString();

                            Int32.TryParse(statisticsFavoriteID, out int convertedStatisticsFavoriteID);
                            Int32.TryParse(statisticsTypeID, out int convertedStatisticsTypeID);
                            Int32.TryParse(statisticsCalculationID, out int convertedStatisticsCalculationID);

                            statisticsFavorites = new CustomStatistics()
                            {
                                ID   = convertedStatisticsFavoriteID,
                                Name = name,
                                ChoosenStatisticsTypeID        = convertedStatisticsTypeID,
                                ChoosenStatisticsCalculationID = convertedStatisticsCalculationID
                            };
                        }
                    }
                }
                catch (SqlException e)
                {
                    MessageBox.Show(e.Message, "Fejl ved forbindelse til database", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            return(statisticsFavorites);
        }
示例#14
0
        public void FinishRun()
        {
            _runInformations  = RunInformations.GetOrNewInstance();
            _customStatistics = CustomStatistics.GetOrNewInstance();
            _consoleUtils     = ConsoleUtils.GetOrNewInstance();

            _runInformations.runStatus = RunInformations.RunStatus.Finished;

            _consoleUtils.WriteLine(null);
            _customStatistics.DisplayCustomStatistics();

            _consoleUtils.UpdateTitle();
            _consoleUtils.Write($"{Environment.NewLine}Finished ");
        }
示例#15
0
        public string FormatTitle(string text)
        {
            _programInformations = ProgramInformations.GetOrNewInstance();
            _runInformations     = RunInformations.GetOrNewInstance();
            _runLists            = RunLists.GetOrNewInstance();
            _runStatistics       = RunStatistics.GetOrNewInstance();
            _customStatistics    = CustomStatistics.GetOrNewInstance();
            _outputSettings      = OutputSettings.GetOrNewInstance();

            text = text
                   .Replace("%program.name%", _programInformations._name)
                   .Replace("%program.version%", _programInformations._version)
                   .Replace("%program.author%", _programInformations._author)

                   .Replace("%lists.combos%", _runLists.combos.Count.ToString())
                   .Replace("%lists.proxies%", _runLists.combos.Count.ToString())

                   .Replace("%run.ran%", _runInformations.ran.ToString())
                   .Replace("%run.remaining%", (_runLists.combos.Count - _runInformations.ran).ToString())
                   .Replace("%run.hits%", _runInformations.hits.ToString())
                   .Replace("%run.free%", _runInformations.free.ToString())

                   .Replace("%run.ran.percentage%", _runLists.combos.Count == 0 ? "0,00%" : ((double)_runInformations.ran / (double)_runLists.combos.Count).ToString("0.00%"))
                   .Replace("%run.hits.percentage%", _runInformations.ran == 0 ? "0,00%" : ((double)_runInformations.hits / (double)_runInformations.ran).ToString("0.00%"))
                   .Replace("%run.free.percentage%", _runInformations.hits == 0 ? "0,00%" : ((double)_runInformations.free / (double)_runInformations.hits).ToString("0.00%"))

                   .Replace("%statistics.rpm%", _runStatistics.ranPerMinute.ToString())
                   .Replace("%statistics.elapsed%", _runStatistics.GetElapsedTime())
                   .Replace("%statistics.estimated%", _runStatistics.GetEstimatedTime());

            lock (_customStatistics.customStatisticsLocker)
                foreach (var customStatistic in _customStatistics.customStatistics)
                {
                    text = text
                           .Replace($"%custom.{customStatistic.Key.Replace(" ", "_")}%", customStatistic.Value.ToString())
                           .Replace($"%custom.{customStatistic.Key.Replace(" ", "_")}.percentage%", customStatistic.Value == 0 ? "0,00%" : ((double)customStatistic.Value / (double)_runInformations.hits).ToString("0.00%"));
                }

            return(text);
        }
示例#16
0
        private double GetValueBasedOnTypeSelection(List <double> kpiRawValue, int statisticsTypeID)
        {
            switch (statisticsTypeID)
            {
            case 1:
                return(CustomStatistics.Average(kpiRawValue));

            case 2:
                return(CustomStatistics.Highest(kpiRawValue));

            case 3:
                return(CustomStatistics.Lowest(kpiRawValue));

            case 4:
                return(CustomStatistics.Count(kpiRawValue));

            case 5:
                return(CustomStatistics.Sum(kpiRawValue));

            default:
                return(0);
            }
        }
示例#17
0
        public void CreateKpiElements(Grid KpiGrid)
        {
            List <KPI> activeKPI = _StoredProcedure.GetActiveKPI();

            int numberOfActiveKPI = activeKPI.Count;
            int kpiDisplacement   = 15;

            if (numberOfActiveKPI != 0)
            {
                HideDefaultKpiGrid(KpiGrid);

                for (int i = 0; i < numberOfActiveKPI; i++)
                {
                    CustomStatistics customStatisticsRelatedToKPI = _StoredProcedure.GetStatisticsFavoriteByID(activeKPI[i].DataID);
                    List <double>    kpiRawValue = GetValueBasedOnCalculationSelection(customStatisticsRelatedToKPI);

                    activeKPI[i].Value = GetValueBasedOnTypeSelection(kpiRawValue, customStatisticsRelatedToKPI.ChoosenStatisticsTypeID);

                    Grid KpiContentGrid = new Grid
                    {
                        Name   = "KpiContentGrid" + (i + 1),
                        Height = 160,
                        Width  = 200,
                        HorizontalAlignment = HorizontalAlignment.Left,
                        Margin     = new Thickness(kpiDisplacement, 0, 0, 0),
                        Background = (SolidColorBrush) new BrushConverter().ConvertFromString(activeKPI[i].Color),
                        ToolTip    = activeKPI[i].Title
                    };

                    TextBlock KpiTitle = new TextBlock
                    {
                        Name                = "KpiTitleTextBlock",
                        Text                = activeKPI[i].Title,
                        Foreground          = Brushes.White,
                        Margin              = new Thickness(10, 10, 0, 0),
                        FontSize            = 17,
                        HorizontalAlignment = HorizontalAlignment.Left,
                        TextWrapping        = TextWrapping.NoWrap,
                        TextTrimming        = TextTrimming.CharacterEllipsis
                    };

                    Label KpiValueLabel = new Label
                    {
                        Name                = "KpiValueLabel",
                        Content             = String.Format("{0:0,0.##}", activeKPI[i].Value),
                        Foreground          = Brushes.White,
                        FontSize            = 40,
                        Margin              = new Thickness(4, 47, 0, 0),
                        HorizontalAlignment = HorizontalAlignment.Left,
                    };

                    TextBlock KpiUnitTextBlock = new TextBlock
                    {
                        Name                = "KpiUnitTextBlock",
                        Text                = activeKPI[i].Unit,
                        Foreground          = Brushes.White,
                        Margin              = new Thickness(10, 132, 0, 0),
                        FontSize            = 15,
                        HorizontalAlignment = HorizontalAlignment.Left,
                        TextWrapping        = TextWrapping.NoWrap,
                        TextTrimming        = TextTrimming.CharacterEllipsis
                    };

                    KpiContentGrid.Children.Add(KpiTitle);
                    KpiContentGrid.Children.Add(KpiValueLabel);
                    KpiContentGrid.Children.Add(KpiUnitTextBlock);
                    KpiGrid.Children.Add(KpiContentGrid);

                    kpiDisplacement = kpiDisplacement + 226;
                }
            }
        }
示例#18
0
 public void AddNewStatistic(CustomStatistics statistic)
 {
     _context.CustomStatistics.Add(statistic);
     _context.SaveChanges();
 }
示例#19
0
 private StatisticsController()
 {
     _StoredProcedure  = new StoredProcedure();
     _CustomStatistics = new CustomStatistics();
 }