Example #1
0
        public HandModifiedDataState loadData()
        {
            HandModifiedDataState state = new HandModifiedDataState();
            //Получение уникальных имен лицензий
            DataConverter <DataSet, string[]> unucNamesConverter =
                new DistinctSoftwareNamesConverter();
            DataSet ds = configProxyForLoadDataFromBDAndExecute(
                MsSqlServersQueryConfigurator.getUnicLicensesName());

            state.unicSoftwareNames = unucNamesConverter.convert(ds);

            //Число закупленных лицензий читается из таблицы PurchasedLicenses
            ds = configProxyForLoadDataFromBDAndExecute(
                MsSqlServersQueryConfigurator.getNumberOfPurchasedLicenses());
            DataTable table = ds.Tables[0];

            state.numberOfPurcharedLicenses = new double[state.unicSoftwareNames.Count()];
            for (int i = 0; i < state.unicSoftwareNames.Count(); i++)
            {
                state.numberOfPurcharedLicenses[i] = int.Parse(table.Rows[i][1].ToString());
            }

            //Распределение в процентах закупленных лицензий
            ds = configProxyForLoadDataFromBDAndExecute(
                MsSqlServersQueryConfigurator.getPartsInPersentOfPurchasedLicenses());
            table          = ds.Tables[0];
            state.percents = new double[state.unicSoftwareNames.Count()];
            for (int i = 0; i < state.unicSoftwareNames.Count(); i++)
            {
                state.percents[i] = double.Parse(table.Rows[i][1].ToString());
            }

            return(state);
        }
Example #2
0
        public MarcovitsModel()
        {
            state = new MarcovitsModelState();
            DataSet ds = configProxyForLoadDataFromNewBDAndExecute(
                MsSqlServersQueryConfigurator.getUnicLicensesName());

            string[] newnames = unucNamesConverter.convert(ds);
        }
Example #3
0
        public override void loadStore()//загрузка данных
        {
            DataWorker <MsSQLServerStateFields, DataSet> accessProxy = new MsSQLServerProxy();
            //получение значения id
            DataSet ds = configProxyForLoadDataFromNewBDAndExecute(
                MsSqlServersQueryConfigurator.getDataOfUsersUseLicenses());

            state.data = converter.convert(ds);
            notifyObservers();
        }
Example #4
0
 public void update()
 {
     for (int i = 0; i < state.unicSoftwareNames.Count(); i++)
     {
         configProxyForLoadDataFromBDAndExecute(
             MsSqlServersQueryConfigurator.updateCountOfLicense(
                 state.unicSoftwareNames[i], state.numberOfPurcharedLicenses[i]));
         configProxyForLoadDataFromBDAndExecute(
             MsSqlServersQueryConfigurator.updatePartInPersentOfPurchasedLicenses(
                 state.unicSoftwareNames[i], state.percents[i]));
     }
 }
Example #5
0
        public override void calculationStatistics()
        {
            try
            {
                //Получение уникальных имен лицензий

                /*DataSet ds = configProxyForLoadDataFromNewBDAndExecute(
                 * MsSqlServersQueryConfigurator.getUnicLicensesName());
                 * state.unicSoftwareNames = unucNamesConverter.convert(ds);*/
                state.unicSoftwareNames = (string[])config.UnicSoftwareNames.Clone();
                if (state.unicSoftwareNames.Count() < 2)
                {
                    throw new NotEnoughDataToAnalyze("Not enough data to analyze");
                }
                //Формирование запроса на получение данных
                DataSet ds = configProxyForLoadDataFromNewBDAndExecute(MsSqlServersQueryConfigurator.
                                                                       getDataOfUseAllLicenses(state.unicSoftwareNames, config.getInterval()));
                state.data = converter.convert(ds);
                if (state.data.Count < 5)
                {
                    throw new NotEnoughDataToAnalyze("Not enough data to analyze");
                }


                //Рассчет средних значений кол-ва лицензий
                state.avgNumbersUseLicense = new double[state.unicSoftwareNames.Length];
                for (int i = 0; i < state.data.Count; i++)
                {
                    for (int j = 0; j < state.data.ElementAt(i).licenses.Length; j++)
                    {
                        state.avgNumbersUseLicense[j] += state.data.ElementAt(i).licenses[j];
                    }
                }
                for (int j = 0; j < state.avgNumbersUseLicense.Length; j++)
                {
                    state.avgNumbersUseLicense[j] = state.avgNumbersUseLicense[j] / state.data.Count;
                }

                //Число закупленных лицензий читается из таблицы PurchasedLicenses

                /*ds = configProxyForLoadDataFromNewBDAndExecute(
                 *  MsSqlServersQueryConfigurator.getNumberOfPurchasedLicenses());
                 * DataTable table = ds.Tables[0];
                 * state.numberBuyLicense = new double[state.unicSoftwareNames.Count()];
                 * for (int i = 0; i < state.unicSoftwareNames.Count(); i++)
                 * {
                 *  state.numberBuyLicense[i] = int.Parse(table.Rows[i][1].ToString());
                 * }*/
                state.numberBuyLicense = (double[])config.NumberOfPurcharedLicenses.Clone();
                double licenseCount = 0;
                for (int i = 0; i < state.numberBuyLicense.Length; i++)
                {
                    if (state.numberBuyLicense[i] <= 0)
                    {
                        throw new NotEnoughDataToAnalyze("Not enough data to analyze. Count of " +
                                                         "purchased license must have more than zero. Plese check it " +
                                                         "(Меню/Закупленные лицензии). For exclude one or more license " +
                                                         "types from calculating please set zero in table with the " +
                                                         "percentage of purchased licenses (Меню/Закупленные лицензии) in " +
                                                         "row(rows) with this license types.");
                    }
                    licenseCount += state.numberBuyLicense[i];
                }
                if (licenseCount <= 0)
                {
                    throw new NotEnoughDataToAnalyze("Not enough data to analyze. Please, fill " +
                                                     "number of licenses purchased (Меню/Закупленные лицензии)");
                }

                //Расчет разницы между кол-вом закупленных и текущих лицензий
                for (int i = 0; i < state.data.Count; i++)
                {
                    for (int j = 0; j < state.data.ElementAt(i).licenses.Length; j++)
                    {
                        state.data.ElementAt(i).licenses[j] = (state.data.ElementAt(i).licenses[j] -
                                                               state.numberBuyLicense[j]) / state.numberBuyLicense[j];
                    }
                }

                state.avgDeviationFromPurchasedNumber = new double[state.unicSoftwareNames.Length];
                //расчет ковариации
                double[,] covarMas = new double[state.unicSoftwareNames.Length, state.unicSoftwareNames.
                                                Length];
                for (int i = 0; i < state.unicSoftwareNames.Length; i++)
                {
                    for (int j = 0; j < state.unicSoftwareNames.Length; j++)
                    {
                        double[] matrixA = new double[state.data.Count];
                        double[] matrixB = new double[state.data.Count];
                        for (int m = 0; m < state.data.Count; m++)
                        {
                            matrixA[m] = state.data.ElementAt(m).licenses[i];
                            matrixB[m] = state.data.ElementAt(m).licenses[j];
                        }
                        covarMas[i, j] = MathWorker.covar(matrixA, matrixB);

                        //Для рассчета доходности считаю доходность по каждой отдельной лицензии
                        state.avgDeviationFromPurchasedNumber[i] = (1 - Math.Abs(MathWorker.avg(matrixA)));
                    }
                }
                //Cоотношения в процентах читается из таблицы PercentageOfLicense

                /*ds = configProxyForLoadDataFromNewBDAndExecute(
                 *  MsSqlServersQueryConfigurator.getPartsInPersentOfPurchasedLicenses());
                 * DataTable table = ds.Tables[0];
                 * state.percents = new double[state.unicSoftwareNames.Count(), 1];
                 * for (int i = 0; i < state.unicSoftwareNames.Count(); i++)
                 * {
                 *  state.percents[i, 0] = double.Parse(table.Rows[i][1].ToString());
                 * }*/
                state.percents = new double[state.unicSoftwareNames.Count(), 1];
                for (int i = 0; i < state.unicSoftwareNames.Count(); i++)
                {
                    state.percents[i, 0] = config.Percents[i];
                }
                double partsSum = 0;
                for (int i = 0; i < state.percents.Length; i++)
                {
                    partsSum += state.percents[i, 0];
                }
                if (partsSum <= 0 || partsSum > 1)
                {
                    throw new NotEnoughDataToAnalyze("Not enough data to analyze. " +
                                                     "Please fill in the ratio of purchased licenses as a percentage" + " (Меню/Закупленные лицензии)");
                }
                //Подсчет общего риска
                state.risk = MathWorker.multiplyMatrix(covarMas, state.percents);

                double[,] transpPercents = new double[1, state.percents.Length];
                for (int i = 0; i < state.percents.Length; i++)
                {
                    transpPercents[0, i] = state.percents[i, 0];
                }

                state.risk = MathWorker.multiplyMatrix(transpPercents, state.risk);

                //Подсчет общего дохода
                state.income = 0;
                for (int i = 0; i < state.avgDeviationFromPurchasedNumber.Length; i++)
                {
                    state.income += state.avgDeviationFromPurchasedNumber[i] * state.percents[i, 0];
                }

                notifyObservers();
            }
            catch (Exception ex)
            {
                ExceptionHandler.getInstance().processing(ex);
            }
        }
Example #6
0
        public override void loadStore()
        {
            try
            {
                //чтение файла с конфигурацией модели

                /*TextFilesDataLoader loader = new TextFilesDataLoader();
                 * TextFilesConfigFieldsOnLoad loadersConfig =
                 *  new TextFilesConfigFieldsOnLoad(config.getConfigData());
                 * loader.setConfig(loadersConfig);
                 * loader.execute();
                 * state.originalRules = loader.getResult();*/

                state  = new ModelingState();
                report = new ModelingReport(state);
                //Создание модели в реалтайме
                DataWorker <ModelsCreatorConfigState, List <string> > loader =
                    new ModelsCreatorProxy();
                ModelsCreatorConfigState creatorsConfig = new ModelsCreatorConfigState();
                //Сбор необходимых данных
                DataSet unicNamesDS = configProxyForLoadDataFromNewBDAndExecute(
                    MsSqlServersQueryConfigurator.getUnicLicensesName());
                DataConverter <DataSet, string[]> unicNamesConverter =
                    new DistinctSoftwareNamesConverter();
                string[] unicNames = unicNamesConverter.convert(unicNamesDS);
                StateForConverterOfModelCreatorConfig stateForConverter =
                    new StateForConverterOfModelCreatorConfig();

                stateForConverter.unicNames = unicNames;

                stateForConverter.numberBuyLicenses = configProxyForLoadDataFromNewBDAndExecute(
                    MsSqlServersQueryConfigurator.getNumberOfPurchasedLicenses());

                for (int i = 0; i < unicNames.Length; i++)
                {
                    stateForConverter.bufOftimeBetweenQueryToGetLicenses.Add(
                        configProxyForLoadDataFromNewBDAndExecute(MsSqlServersQueryConfigurator.getTimesGiveLicense(
                                                                      unicNames[i], config.getInterval())));
                    stateForConverter.bufOfTimesOfInBetweenOutLicenses.Add(
                        configProxyForLoadDataFromNewBDAndExecute(MsSqlServersQueryConfigurator.getInBetweenOutLicenses(
                                                                      unicNames[i], config.getInterval())));
                    stateForConverter.numberOfGetingLicensesPerTime.Add(
                        configProxyForLoadDataFromNewBDAndExecute(MsSqlServersQueryConfigurator.getNumberOfLicenesForTime(
                                                                      unicNames[i], config.getInterval())));
                    stateForConverter.avgLicensePerTime.Add(
                        configProxyForLoadDataFromNewBDAndExecute(MsSqlServersQueryConfigurator.getAvgLicesensePerTime(
                                                                      unicNames[i], config.getInterval())));
                }

                //Перевод типа DataSet к нужному формату
                DataConverter <StateForConverterOfModelCreatorConfig,
                               ReturnStateForConverterOfModelCreatorConfig> convertData =
                    new ModelCreatorConfigCreator();
                ReturnStateForConverterOfModelCreatorConfig licencesInfo =
                    convertData.convert(stateForConverter);


                double licenseCount = 0;
                for (int i = 0; i < licencesInfo.numberBuyLicenses.Length; i++)
                {
                    if (licencesInfo.numberBuyLicenses[i] <= 0)
                    {
                        throw new NotEnoughDataToAnalyze("Not enough data to analyze. Count of " +
                                                         "purchased license must have more than zero. Plese check it " +
                                                         "(Меню/Закупленные лицензии). For exclude one or more license " +
                                                         "types from calculating please set zero in table with the " +
                                                         "percentage of purchased licenses (Меню/Закупленные лицензии) in " +
                                                         "row(rows) with this license types.");
                    }
                    licenseCount += licencesInfo.numberBuyLicenses[i];
                }
                if (licenseCount <= 0)
                {
                    throw new NotEnoughDataToAnalyze("Not enough data to analyze. Please, fill " +
                                                     "number of licenses purchased (Меню/Закупленные лицензии)");
                }

                //Создание конфига
                creatorsConfig.licenceInfo = new List <LicenceInfo>();
                for (int i = 0; i < unicNames.Length; i++)
                {
                    if (licencesInfo.bufOfTimesOfInBetweenOutLicenses.ElementAt(i).
                        characteristic.Count() > 1 &
                        licencesInfo.bufOftimeBetweenQueryToGetLicenses.ElementAt(i).
                        characteristic.Count() > 1)
                    {
                        int numberBuyLicense            = licencesInfo.numberBuyLicenses[i];
                        int avgDelayTimeInTheProcessing = Convert.ToInt32(MathWorker.avg(
                                                                              licencesInfo.bufOfTimesOfInBetweenOutLicenses.ElementAt(i).characteristic));
                        int avgSquereDelayTimeInTheProcessing = Convert.ToInt32(MathWorker.
                                                                                standardDeviation(licencesInfo.bufOfTimesOfInBetweenOutLicenses.
                                                                                                  ElementAt(i).characteristic));
                        if (avgSquereDelayTimeInTheProcessing > avgDelayTimeInTheProcessing)
                        {
                            avgDelayTimeInTheProcessing = (avgSquereDelayTimeInTheProcessing +
                                                           avgDelayTimeInTheProcessing) / 2;
                            avgSquereDelayTimeInTheProcessing = avgDelayTimeInTheProcessing;
                        }
                        int avgRequestedTime = Convert.ToInt32(MathWorker.avg(
                                                                   licencesInfo.bufOftimeBetweenQueryToGetLicenses.ElementAt(i).characteristic));
                        int avgSquereRequestedTime = Convert.ToInt32(MathWorker.
                                                                     standardDeviation(licencesInfo.bufOftimeBetweenQueryToGetLicenses.
                                                                                       ElementAt(i).characteristic));
                        if (avgSquereRequestedTime > avgRequestedTime)
                        {
                            avgRequestedTime       = (avgSquereRequestedTime + avgRequestedTime) / 2;
                            avgSquereRequestedTime = avgRequestedTime;
                        }
                        creatorsConfig.licenceInfo.Add(new LicenceInfo(unicNames[i], numberBuyLicense,
                                                                       avgDelayTimeInTheProcessing, avgSquereDelayTimeInTheProcessing,
                                                                       licencesInfo.avgLicensePerTime[i], avgRequestedTime,
                                                                       avgSquereRequestedTime));
                    }
                }
                //Вычисление матрицы корреляций
                int size = creatorsConfig.licenceInfo.Count;
                creatorsConfig.korellation = new double[size, size];
                for (int i = 0; i < size; i++)
                {
                    for (int m = i; m < size; m++)
                    {
                        if (licencesInfo.numberOfGetingLicensesPerTime.ElementAt(i).
                            characteristic.Count() != 0 &
                            licencesInfo.numberOfGetingLicensesPerTime.ElementAt(m).
                            characteristic.Count() != 0)
                        {
                            //Перед вычислением корелляции необходимо выяснить, не состоят ли
                            //проверяемые массивы из одинаковых элементов
                            bool countCorell = true;
                            if (MathWorker.standardDeviation(licencesInfo.
                                                             numberOfGetingLicensesPerTime.ElementAt(i).characteristic) == 0 ||
                                MathWorker.standardDeviation(licencesInfo.
                                                             numberOfGetingLicensesPerTime.ElementAt(m).characteristic) == 0)
                            {
                                countCorell = false;
                            }
                            if (countCorell)
                            {
                                double currentCorellation = MathWorker.corellation(
                                    licencesInfo.numberOfGetingLicensesPerTime.ElementAt(i).characteristic,
                                    licencesInfo.numberOfGetingLicensesPerTime.ElementAt(m).characteristic);
                                creatorsConfig.korellation[i, m] = currentCorellation;
                                creatorsConfig.korellation[m, i] = currentCorellation;
                            }
                            else
                            {
                                creatorsConfig.korellation[i, m] = 0;
                                creatorsConfig.korellation[m, i] = 0;
                            }
                        }
                    }
                }
                creatorsConfig.withKovar = true;
                loader.setConfig(creatorsConfig);
                loader.execute();
                state.originalRules = loader.getResult();

                //создание всех очередей, устройств, меток и тд
                RulesParser rules_parser = new RulesParser();
                rules_parser.go_parse(this);
            }
            catch (Exception ex)
            {
                ExceptionHandler.getInstance().processing(ex);
            }
        }