Example #1
0
        public Mid_3_1(ref RawData r)
        {
            rd           = r;
            rlist        = new R1pnList();
            mid3_1       = new int[max_mid31_Count, rd.Cols];
            mid3_1_Count = 0;
            for (int i = 0; i < max_mid31_Count; i++)
            {
                for (int j = 0; j < rd.Cols; j++)
                {
                    mid3_1[i, j] = 0;
                }
            }

            sw = new StreamWriter(Common.debugpath + "\\" + "MID3_1.txt");
            int count = (int)(100 / Common.GpspInterval);

            for (int i = 0; i < count; i++)
            {
                R1pn r1 = new R1pn(5);
                rlist.Add(r1);
            }

            // make G%SP table
            int index;

            for (Int16 i = 0; i < r.Cols; i++)
            {
                index = (int)(r.PerSP[i] / Common.GpspInterval);
                rlist.rList[index].Add(i);
            }
            // test code
            // rlist.rList[3].Add(5);
            // rlist.rList[3].Add(9);
            // rlist.rList[3].Add(28);
            // rlist.rList[3].Add(45);
            // rlist.rList[3].Add(34);

            //Get Max index of a R1pn
            count = rlist.GetMaxCount();
            index = 0;
            for (int i = 0; i < rlist.rList.Count; i++)
            {
                if (rlist.rList[i].cp == count)
                {
                    for (int j = 0; j < rlist.rList[i].cp; j++)
                    {
                        mid3_1[index, rlist.rList[i].r1pn[j]] = 1;
                    }
                    index++;
                }
            }
            mid3_1_Count = index;

            rlist.print(ref sw, 10);

            int[] temp = new int[rd.Cols];
            if (mid3_1_Count == 1)
            {
                for (int i = 0; i < rd.Cols; i++)
                {
                    temp[i] = mid3_1[0, i];
                }
                Common.printArray("Mid-3-1: Result: ", temp, ref sw);
            }
            else
            {
                for (int k = 0; k < mid3_1_Count; k++)
                {
                    for (int i = 0; i < rd.Cols; i++)
                    {
                        temp[i] = mid3_1[k, i];
                    }
                    Common.printArray("Mid-3-1-" + (k + 1).ToString() + ": Result: ", temp, ref sw);
                }
            }

            rank = new int[rd.Cols];
            rlist.makeRankArray(ref rank);
        }
Example #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                string programfiles = Environment.GetEnvironmentVariable("USERPROFILE");
                if (programfiles.Length < 1)
                {
                    programfiles = Environment.GetEnvironmentVariable("TMP");
                    if (programfiles.Length < 1)
                    {
                        programfiles = Directory.GetCurrentDirectory();
                    }
                }
                MyPATH     = programfiles + "\\JasonAlg";
                ConfigPath = MyPATH + "\\currentfolder.cfg";
                if (!Directory.Exists(MyPATH))
                {
                    Directory.CreateDirectory(MyPATH);
                }
                GOSTOP = false;
                //if (false)
                if (File.Exists(ConfigPath))
                {
                    try
                    {
                        StreamReader sr = new StreamReader(ConfigPath);
                        txtCurDir.Text = sr.ReadLine();
                        sr.Close();
                        // make file list of Excel.
                        btnReload_Click(sender, e);
                    }
                    catch (Exception)
                    { }
                }
                else
                {
                    /*
                     * IDictionary	environmentVariables = Environment.GetEnvironmentVariables();
                     * foreach (DictionaryEntry de in environmentVariables)
                     *   {
                     *   Console.WriteLine("  {0} = {1}", de.Key, de.Value);
                     *   }
                     */
                    txtCurDir.Text = Environment.GetEnvironmentVariable("USERPROFILE");
                    if (txtCurDir.Text == "")
                    {
                        txtCurDir.Text = Directory.GetCurrentDirectory();
                    }

                    /*
                     * try
                     * {
                     *  FileAttributes attri = File.GetAttributes(ConfigPath);
                     *  attri = RemoveAttribute(attri, FileAttributes.System | FileAttributes.Hidden);
                     *  File.SetAttributes(ConfigPath, attri);
                     * }
                     * catch (Exception)
                     * { }
                     */
                    StreamWriter sr = new StreamWriter(ConfigPath);
                    sr.WriteLine(txtCurDir.Text);
                    sr.Close();
                }
                rd    = null;
                resDB = null;

                // lock 기능.'
                //File.SetAttributes(ConfigPath, FileAttributes.Hidden | FileAttributes.System);
                cmbJoblist.Enabled = false;
                btnReload.Enabled  = false;
                btnCalc.Enabled    = false;
                statusLabel1.Text  = "먼저 Get Permission을 눌러,프로그램 실행 Permission 획득해야 합니다.";
                Common.debugpath   = txtCurDir.Text;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "CRITICAL ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            cmbPercent.SelectedIndex = 0;
            Common.GpspInterval      = 2;
        }
Example #3
0
        public Mid_4_1(ref RawData r)
        {
            rd     = r;
            mid4_1 = new int[rd.Cols];
            mx_mn  = new double[rd.Cols];
            rlist  = new R1pnList();
            Array.Clear(mid4_1, 0, mid4_1.Length);
            sw = new StreamWriter(Common.debugpath + "\\" + "MID4_1.txt");

            Common.printArray("MID4_1 :Rawdata %SP ", rd.PerSP, ref sw);
            sw.WriteLine("MID4_1: Average %SP : " + rd.APerSP.ToString("#####0.00"));

            // make mx_mn array
            for (int i = 0; i < rd.Cols; i++)
            {
                mx_mn[i] = rd.APerSP - rd.PerSP[i];
            }
            // get the most number out of + values.
            int    index = Common.MaxIndex(ref mx_mn);
            double val   = mx_mn[index];
            R1pn   r1    = new R1pn(10);

            for (Int16 i = 0; i < rd.Cols; i++)
            {
                if (mx_mn[i] == val)
                {
                    mid4_1[i] = 1; r1.Add(i);
                }
            }
            rlist.Add(r1);
            Common.printArray("MID4_1 :first", mid4_1, ref sw);
            // get the least number out of - values;
            index = Common.MinIndex(ref mx_mn);
            val   = mx_mn[index];
            r1    = new R1pn(10);
            for (Int16 i = 0; i < rd.Cols; i++)
            {
                if (mx_mn[i] == val)
                {
                    mid4_1[i] = 1; r1.Add(i);
                }
            }
            rlist.Add(r1);
            Common.printArray("MID4_1 :second", mid4_1, ref sw);
            // get the least number out of + values;
            index = Common.MinIndexOutofPlus(ref mx_mn);
            val   = mx_mn[index];
            r1    = new R1pn(10);
            for (Int16 i = 0; i < rd.Cols; i++)
            {
                if (mx_mn[i] == val)
                {
                    mid4_1[i] = 1; r1.Add(i);
                }
            }
            rlist.Add(r1);
            Common.printArray("MID4_1 :third", mid4_1, ref sw);

            // get the most number out of - values;
            index = Common.MaxIndexOutofMinus(ref mx_mn);
            val   = mx_mn[index];
            r1    = new R1pn(10);
            for (Int16 i = 0; i < rd.Cols; i++)
            {
                if (mx_mn[i] == val)
                {
                    mid4_1[i] = 1; r1.Add(i);
                }
            }
            rlist.Add(r1);
            Common.printArray("MID4_1 :MX/MN", mx_mn, ref sw);
            Common.printArray("MID4_1 :MID4_1", mid4_1, ref sw);

            rlist.print(ref sw);
        }
Example #4
0
        private void cmbJoblist_SelectedIndexChanged(object sender, EventArgs e)
        {
            Excel.Workbook excelWorkbook = null;
            rd              = null;
            resDB           = null;
            GOSTOP          = false;
            btnCalc.Enabled = false;
            try
            {
                txtTpn.Text  = "";
                txtTpsn.Text = "";
                txtPosn.Text = "";
                string str = txtCurDir.Text + "\\" + cmbJoblist.SelectedItem.ToString();
                if (!File.Exists(str))
                {
                    MessageBox.Show("File is not found, " + str, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // Read File and display the file header.
                Excel.Application excelApp = new Excel.Application(); // Creates a new Excel Application
                excelApp.Visible = false;                             // Makes Excel visible to the user.

                // The following code opens an existing workbook
                string workbookPath = str;  // Add your own path here

                try
                {
                    excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0,
                                                            false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true,
                                                            false, 0, true, false, false);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("File open Error:  " + ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // The following gets the Worksheets collection
                Excel.Sheets excelSheets = excelWorkbook.Worksheets;

                // The following gets Sheet1 for editing
                string          currentSheet   = "RawDB";
                Excel.Worksheet excelWorksheet = null;
                try
                {
                    excelWorksheet = (Excel.Worksheet)excelSheets.get_Item("RawDB");
                }
                catch
                {
                    try
                    {
                        excelWorksheet = (Excel.Worksheet)excelSheets.get_Item("Raw DB");
                    }
                    catch
                    {
                        MessageBox.Show("Error: There is not the Sheet that is named 'Raw DB'", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        if (excelWorkbook != null)
                        {
                            excelWorkbook.Close();
                        }
                        return;
                    }
                }

                // The following gets cell A1 for editing
                int tpn, tpsn, posn, RawStart, ColStart;
                try
                {
                    tpn           = (int)excelWorksheet.Cells[1, 2].Value2;
                    Common.TPN    = tpn;
                    txtTpn.Text   = tpn.ToString();
                    tpsn          = (int)excelWorksheet.Cells[2, 2].Value2;
                    Common.TSPN   = tpsn;
                    txtTpsn.Text  = tpsn.ToString();
                    posn          = (int)excelWorksheet.Cells[3, 2].Value2;
                    Common.POSN   = posn;
                    txtPosn.Text  = posn.ToString();
                    RawStart      = (int)excelWorksheet.Cells[4, 2].Value2;
                    ColStart      = (int)excelWorksheet.Cells[4, 3].Value2;
                    txtStart.Text = "Row:" + RawStart.ToString() + ",Col:" + ColStart.ToString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Data Read Error, please check the input data(TPN,TPSN,POSN,Start Position) in 'RAW DB' sheet.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    if (excelWorkbook != null)
                    {
                        excelWorkbook.Close();
                    }
                    return;
                }

                // Read All Data and make a RawData Class
                rd = new RawData(posn, tpn, tpsn);
                int d = 0;
                for (int i = 0; i < posn; i++)
                {
                    for (int j = 0; j < tpn; j++)
                    {
                        rd.Set(i, j, 0);
                    }
                    for (int j = 0; j < tpn; j++)
                    {
                        try
                        {
                            d = Convert.ToInt32(excelWorksheet.Cells[RawStart + i, ColStart + j].Value2);
                            if (d > 0 && d <= tpn)
                            {
                                rd.Set(i, d - 1, 1);
                            }
                        }
                        catch
                        {
                            d = 0;
                        }
                        if (d == 0)
                        {
                            break;
                        }
                    }
                    if (i % 100 == 0)
                    {
                        Console.WriteLine("line: " + i.ToString());
                    }
                }
                excelWorkbook.Close();
                excelWorkbook = null;
                //rd.printRawData();
                btnCalc.Enabled      = true;
                StatusProgress.Value = 0;
                statusLabel1.Text    = "";
                timer1.Enabled       = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:  unhandled error was raised. system message:" + ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (excelWorkbook != null)
                {
                    excelWorkbook.Close();
                }
            }
        }
Example #5
0
        public Mid_4_3_new1(ref RawData r, ref Mid_4_1 md41, ref Mid_4_2 m42)
        {
            rd     = r;
            md42   = m42;
            mid4_3 = new int[rd.Cols];
            Array.Clear(mid4_3, 0, mid4_3.Length);
            sw          = new StreamWriter(Common.debugpath + "\\" + "MID4_3.txt");
            MXPlus      = new double[rd.Cols];
            MXMinus     = new double[rd.Cols];
            MXPlusPN    = new int[rd.Cols];
            MXMinusPN   = new int[rd.Cols];
            MXPlusCount = 0; MXMinusCount = 0;
            MXavg       = 0; MNAvg = 0;
            for (int i = 0; i < md41.mx_mn.Length; i++)
            {
                if (md41.mx_mn[i] > 0)
                {
                    MXPlusPN[MXPlusCount] = i; MXPlus[MXPlusCount++] = md41.mx_mn[i]; MXavg += md41.mx_mn[i];
                }
                else if (md41.mx_mn[i] < 0)
                {
                    MXMinusPN[MXMinusCount] = i; MXMinus[MXMinusCount++] = Math.Abs(md41.mx_mn[i]); MNAvg += Math.Abs(md41.mx_mn[i]);
                }
            }
            MXavg = MXavg / MXPlusCount;
            MNAvg = MNAvg / MXMinusCount;

            MXselectCount = 0; MNselectCount = 0;
            MXselectPN    = new int[MXPlusCount];
            MNselectPN    = new int[MXMinusCount];
            MXPlusDiff    = new double[MXPlusCount];
            MXMinusDiff   = new double[MXMinusCount];

            for (int i = 0; i < MXPlusCount; i++)
            {
                MXPlusDiff[i] = Math.Abs(MXPlus[i] - MXavg);
            }
            for (int i = 0; i < MXMinusCount; i++)
            {
                MXMinusDiff[i] = Math.Abs(MXMinus[i] - MNAvg);
            }
            double min1 = Double.MaxValue, min2 = Double.MaxValue;

            for (int i = 0; i < MXPlusCount; i++)
            {
                if (MXPlusDiff[i] < min1)
                {
                    min1 = MXPlusDiff[i];
                }
            }
            for (int i = 0; i < MXMinusCount; i++)
            {
                if (MXMinusDiff[i] < min2)
                {
                    min2 = MXMinusDiff[i];
                }
            }
            for (int i = 0; i < MXPlusCount; i++)
            {
                if (MXPlusDiff[i] == min1)
                {
                    MXselectPN[MXselectCount] = MXPlusPN[i]; MXselectCount++;
                    mid4_3[MXPlusPN[i]]       = 1;
                }
            }
            for (int i = 0; i < MXMinusCount; i++)
            {
                if (MXMinusDiff[i] == min2)
                {
                    MNselectPN[MNselectCount] = MXMinusPN[i]; MNselectCount++;
                    mid4_3[MXMinusPN[i]]      = 1;
                }
            }

            /*
             * // MX%SP
             * lower1 = MXavg * (1 - variation);
             * upper1 = MXavg * (1 + variation);
             * for (int i = 0; i < MXPlusCount; i++)
             * {
             *  if (MXPlus[i] >= lower1 && MXPlus[i] <= upper1)
             *  {
             *      MXselectPN[MXselectCount] = MXPlusPN[i]; MXselectCount++;
             *      mid4_3[MXPlusPN[i]] = 1;
             *  }
             * }
             * // MN%SP
             * lower2 = MNAvg * (1 - variation);
             * upper2 = MNAvg * (1 + variation);
             * for (int i = 0; i < MXMinusCount; i++)
             * {
             *  if (MXMinus[i] >= lower2 && MXMinus[i] <= upper2)
             *  {
             *      MNselectPN[MNselectCount] = MXMinusPN[i]; MNselectCount++;
             *      mid4_3[MXMinusPN[i]] = 1;
             *  }
             * }
             */

            // Print Data
            // MX List
            string one = "";

            sw.WriteLine("MX PN List :  (PN, %SP) ,  Count: " + MXPlusCount.ToString());
            for (int i = 0; i < MXPlusCount; i++)
            {
                one = one + "(" + (MXPlusPN[i] + 1).ToString() + ":" + MXPlus[i].ToString("#####0.00") + ") ";
                if (i > 0 && i % 5 == 0)
                {
                    sw.WriteLine(one);
                    one = "";
                }
            }
            if (one != "")
            {
                sw.WriteLine(one);
            }
            // MN List
            sw.WriteLine();
            one = "";
            sw.WriteLine("MN PN List :  (PN, %SP),  Count: " + MXMinusCount.ToString());
            for (int i = 0; i < MXMinusCount; i++)
            {
                one = one + "(" + (MXMinusPN[i] + 1).ToString() + ":" + (MXMinus[i] * -1).ToString("#####0.00") + ") ";
                if (i > 0 && i % 5 == 0)
                {
                    sw.WriteLine(one);
                    one = "";
                }
            }
            if (one != "")
            {
                sw.WriteLine(one);
            }
            sw.WriteLine();
            // average
            //sw.WriteLine("AveMX%SP =" + MXavg.ToString("#######0.00") + "  Range:+/-" + (variation*100).ToString() + "% (" + lower1.ToString("######0.00") + "~" + upper1.ToString("######0.00") + ")");
            //sw.WriteLine("AveMN%SP =" + (MNAvg * -1).ToString("#######0.00") + "  Range:+/-" + (variation * 100).ToString() + "% (" + (lower2*-1).ToString("######0.00") + "~" + (upper2*-1).ToString("######0.00") + ")");
            sw.WriteLine("AveMX%SP =" + MXavg.ToString("#######0.00"));
            sw.WriteLine("AveMN%SP =" + (MNAvg * -1).ToString("#######0.00"));
            sw.WriteLine();

            // Difference table
            one = "";
            sw.WriteLine("MX PN List :  Difference Table ,  Count: " + MXPlusCount.ToString());
            for (int i = 0; i < MXPlusCount; i++)
            {
                one = one + "(" + (MXPlusPN[i] + 1).ToString() + ":" + (MXPlus[i] - MXavg).ToString("#####0.00") + ") ";
                if (Math.Abs(MXPlus[i] - MXavg) == min1)
                {
                    one = one + "**    ";
                }
                if (i > 0 && i % 5 == 0)
                {
                    sw.WriteLine(one);
                    one = "";
                }
            }
            if (one != "")
            {
                sw.WriteLine(one);
            }
            // MN List
            sw.WriteLine();
            one = "";
            sw.WriteLine("MN PN List :   Difference Table ,  Count: " + MXMinusCount.ToString());
            for (int i = 0; i < MXMinusCount; i++)
            {
                one = one + "(" + (MXMinusPN[i] + 1).ToString() + ":" + (MXMinus[i] - MNAvg).ToString("#####0.00") + ") ";
                if (Math.Abs(MXMinus[i] - MNAvg) == min2)
                {
                    one = one + "**    ";
                }
                if (i > 0 && i % 5 == 0)
                {
                    sw.WriteLine(one);
                    one = "";
                }
            }
            if (one != "")
            {
                sw.WriteLine(one);
            }
            sw.WriteLine();

            // pn list
            sw.WriteLine();
            sw.Write("MX%SP Selected PNs' List : ");
            one = "";
            for (int i = 0; i < MXselectCount; i++)
            {
                one = one + (MXselectPN[i] + 1).ToString() + " ";
            }
            sw.WriteLine(one);
            sw.Write("MN%SP Selected PNs' List : ");
            one = "";
            for (int i = 0; i < MNselectCount; i++)
            {
                one = one + (MNselectPN[i] + 1).ToString() + " ";
            }
            sw.WriteLine(one);
            sw.WriteLine();

            Common.printArray("MID4_3 :MID4_3", mid4_3, ref sw);
        }