// return realvalue of probabilty that random int its range
        public static string get_delay_minute(double Random_num, Distribution[] table)
        {
            for (int i = 0; i < 3; i++)
            {
                if (Random_num >= table[i].start && Random_num <= table[i].end )
                    return table[i].realvalue;
            }

            return "";
        }
        // return realvalue of probabilty that random int its range
        public static string get_life_hour(double Random_num, Distribution[] table)
        {
            for (int i = 0; i < 10; i++)
            {
                if (Random_num >= table[i].start && Random_num <= table[i].end )
                    return table[i].realvalue;
            }

            return "";
        }
        // calculate distribution variable
        public static void getDistributionTabel(Distribution[] distTemp, int num_probabilty)
        {
            double starting = 0, ending = 0;

            for (int i = 0; i < num_probabilty; ++i)
            {
                if(num_probabilty==10)
                    ending += distTemp[i].Probability;
                else
                    ending += distTemp[i].Probability *10;

                distTemp[i].end = distTemp[i].CumulativeProbability = ending;

                if(num_probabilty==10)
                    distTemp[i].start = (double)starting + .01;
                else
                    distTemp[i].start = (double)starting + 1;

                starting = ending;
            }
        }
        // calculation of Delay Time Distribution
        public static void calc_delay_time(System.Windows.Forms.DataGridView DGV)
        {

            int probabilty_num = DGV.Rows.Count - 1;
            delayProb = new Distribution[probabilty_num];
            for (int i = 0; i < probabilty_num; ++i)
            {
                delayProb[i] = new Distribution();
                delayProb[i].realvalue = DGV.Rows[i].Cells[0].Value.ToString();
                if (check(i, 1, DGV) == true)
                    delayProb[i].Probability = double.Parse(DGV.Rows[i].Cells[1].Value.ToString());
                else
                    delayProb[i].Probability = 0;

            }
            Distribution.getDistributionTabel(delayProb, probabilty_num);

            for (int i = 0; i < probabilty_num; ++i)
            {

                DGV.Rows[i].Cells[2].Value = delayProb[i].CumulativeProbability /= 10;
                DGV.Rows[i].Cells[3].Value = delayProb[i].start;
                DGV.Rows[i].Cells[4].Value = delayProb[i].end;
                
            }

        }
        // calculation of Bearing life Distribution
        public static void calc_bear_life_probabilty(System.Windows.Forms.DataGridView DGV)
        {
            
            int probabilty_num=DGV.Rows.Count-1;
             beerProb = new Distribution[probabilty_num];
            for (int i = 0; i < probabilty_num; ++i)
            {
                beerProb[i] = new Distribution();
                beerProb[i].realvalue = DGV.Rows[i].Cells[0].Value.ToString();

                if (check(i, 1, DGV) == true)
                    beerProb[i].Probability = double.Parse(DGV.Rows[i].Cells[1].Value.ToString());
                else
                    beerProb[i].Probability = 0;

            } 
            Distribution.getDistributionTabel(beerProb, probabilty_num);

            for (int i = 0; i < probabilty_num; ++i)
            {

                double temp = Math.Round(beerProb[i].CumulativeProbability,2);

                    DGV.Rows[i].Cells[2].Value = beerProb[i].CumulativeProbability;
                    DGV.Rows[i].Cells[3].Value = beerProb[i].start *= 100 ;
                    DGV.Rows[i].Cells[4].Value = beerProb[i].end *= 100 ;

                   

                    beerProb[i].start =Convert.ToInt32( beerProb[i].start);
                    beerProb[i].end = Convert.ToInt32(beerProb[i].end);
                
               
            }
            
        }