Exemplo n.º 1
0
        public static void WriteDeltaToJpeg(string filePath, Spec spec, int index, int pos = 0)
        {
            try
            {
                var Tr = ThresholdConfigs.GetInstance();
                //   var index = GetIndex();

                Bitmap bitmap = null;
                using (var stream = File.OpenRead(filePath))
                {
                    bitmap = (Bitmap)Bitmap.FromStream(stream);
                }

                double percent  = 0;
                int    position = pos;
                //     string level = spec.result;
                //if (DR != (DetectionResult)0)
                //{
                //    position=300;

                //}

                var msg = string.Empty;
                if (spec.IsSaturated)
                {
                    msg = "saturated";
                }
                else
                if (spec.IsNoisy)
                {
                    msg = "noisy";
                }
                else if (spec.NoPeakDetected)
                {
                    msg = "noPeakDetected";
                }

                else
                {
                    var level = ProcessUnit.GetInstnace().GetDangerLevel(spec.delta1, spec.delta2, out percent, index);


                    if (((int)level) > -1 && level != DangerLevel.saturation)
                    {
                        msg = Tr.Elements[(int)level].ThresholdName[index];
                    }
                }

                //   Tr.Elements[(int)DangerLevel]
                using (bitmap)
                    using (var graphics = Graphics.FromImage(bitmap))
                        using (var font = new Font("Arial", 15, FontStyle.Regular))
                        {
                            String S = "ScanRate:" + spec.scanRate.ToString("####.##");
                            S += " Delta1:" + spec.delta1.ToString("0.##");
                            S += " Delta2:" + spec.delta2.ToString("0.##");
                            S += "\nMaxVoltage:" + spec.MaxVoltage.ToString("0.##");
                            S += " Voltage1:" + spec.voltageDelta1.ToString("0.##");
                            S += " Voltage2:" + spec.voltageDelta2.ToString("0.##");
                            S += "\nDangerLevel:" + msg;
                            S += "\nPercent:" + percent.ToString("0.##");
                            S += "\nSNR:" + spec.SNR.ToString("0.##");

                            graphics.DrawString(S, font, Brushes.Black, 0, position);

                            //graphics.DrawString("ScanRate:" + scanrate.ToString("####.##"), font, Brushes.Red, 0, 0);
                            // graphics.DrawString("Delta1:" + spec.delta1.ToString("####.##"), font, Brushes.Red, 0, 80);
                            //  graphics.DrawString("Delta2:" + spec.delta2.ToString("####.##"), font, Brushes.Red, 0, 160);
                            //   graphics.DrawString("DangerLevel:" + level, font, Brushes.Red, 0, 240);
                            // Important part!
                            bitmap.Save(filePath);
                        }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 2
0
        public DetectionResult DetermineCancerOrWarningOrHealthy(out int Range, out DangerLevel DangerLevel, List <double> Currents, double[] Voltages, int IndexOfMax, Spec spec, int index)
        {
            DangerLevel = DangerLevel.free;

            DetectionResult Res = DetectionResult.Warning;

            Range = 100;

            var MaxValue = Currents[IndexOfMax];

            spec.MaxVoltage = Voltages[IndexOfMax];

            spec.voltageDelta1 = spec.MaxVoltage;
            double MinimumCurrentBeforeMax = 1000000;
            double MinimumCurrentAfterMax  = 1000000;

            //  spec =new Spec();
            spec.delta1 = 0;
            spec.delta2 = 0;

            for (int i = IndexOfMax; i > 0; i--)
            {
                if (MinimumCurrentBeforeMax > Currents[i])
                {
                    MinimumCurrentBeforeMax = Currents[i];
                }
                if (Voltages[i] < 0)
                {
                    break;
                }
            }

            for (int i = IndexOfMax; i < Currents.Count; i++)
            {
                if (MinimumCurrentAfterMax > Currents[i])
                {
                    MinimumCurrentAfterMax = Currents[i];
                    spec.voltageDelta2     = Voltages[i];
                }

                if (Voltages[i] > Voltages[i + 1])
                {
                    break;
                }
            }


            double DeltaCurrent1 = MaxValue;
            double DeltaCurrent2 = MaxValue - MinimumCurrentAfterMax;

            spec.delta1 = DeltaCurrent1;
            spec.delta2 = DeltaCurrent2;

            var Threshold = ConstantThreshold.GetInstance();

            double percent;
            var    dangerLavel = GetDangerLevel(spec.delta1, spec.delta2, out percent, index);


            spec.DangerLevel = dangerLavel;

            switch (dangerLavel)
            {
            case DangerLevel.free:
            case DangerLevel.free_warning:
                Res = DetectionResult.Healthy;
                break;

            case DangerLevel.danger:
                Res = DetectionResult.Cancer;
                break;


            case DangerLevel.warning:
            case DangerLevel.warning_danger:
                Res = DetectionResult.Warning;
                break;
            }


            return(Res);
        }
Exemplo n.º 3
0
        public static string ExcelsaveBtn_Click(Spec spec, List <double> listI, List <double> listV, string range, int index, int ScanRate, DateTime Date)
        {
            var    fileaddress  = "null";
            var    imageaddress = "null";
            string foldertime   = Date.ToString("dd-MM-yyyy");
            string filetime     = Date.ToString();
            string image_name;

            filetime = filetime.Replace('/', '-');
            filetime = filetime.Replace(':', '.');

            string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + foldertime;

            System.IO.Directory.CreateDirectory(path);


            //if (rownum1 < 10)
            //{
            //    //    radLabelElement4.Text = "";
            //    //  return;
            //}


            //{
            string file_name = "Test " + filetime + ".xls";

            image_name   = "Test " + filetime + ".jpg";
            imageaddress = Path.Combine(path, image_name);
            //}



            fileaddress = Path.Combine(path, file_name);



            try
            {
                SpreadsheetInfo.SetLicense("ETZW-AT28-33Q6-1HAS");
                var workbook = new ExcelFile();
                // Add new woksheet to Excel file.
                var worksheet = workbook.Worksheets.Add("Sheet1");
                // Set the value of the cell "A1".
                //  worksheet.Cells["A1"].Value = "Hello world!";


                //Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();

                // if (xlApp == null)
                {
                    //   MessageBox.Show("Excel is not properly installed!!");
                    // return;
                }



                //   Excel.Workbook xlWorkBook;
                // Excel.Worksheet xlWorkSheet;
                // object misValue = System.Reflection.Missing.Value;

                // xlWorkBook = xlApp.Workbooks.Add(misValue);
                // xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);


                worksheet.Cells["C1"].Value = " ******************************* NBEL Cancer Diagnostic Probe Output file **********************************";
                worksheet.Cells["C2"].Value = "******************************************************************************************************";

                //xlWorkSheet.Cells[1, 3] = " ******************************* NBEL Cancer Diagnostic Probe Output file **********************************";
                //xlWorkSheet.Cells[2, 3] = " ******************************************************************************************************";

                worksheet.Cells["C3"].Value = "                                                         Task Performed At " + DateTime.Now + "                            ";

                //xlWorkSheet.Cells[3, 3] = "                                                         Task Performed At " + DateTime.Now + "                            ";
                worksheet.Cells["C4"].Value = "                                                         Task Performed At " + DateTime.Now + "                            ";
                //xlWorkSheet.Cells[4, 3] = "                                       Results of Measurment (" + myPane1.Title.Text + ") Is As Following :";

                worksheet.Cells["C5"].Value = "              Start Point : -600 mV " + "  End Point : 600 mV " + "  Scan Rate : " + ScanRate; //SRBoxCV1.Text;
                //xlWorkSheet.Cells[5, 3] = "              Start Point : -600 mV " + "  End Point : 600 mV " + "  Scan Rate : " + ScanRate; //SRBoxCV1.Text;
                worksheet.Cells["E6"].Value = "     Voltage (mV) ";
                //xlWorkSheet.Cells[6, 5] = "     Voltage (mV) ";
                worksheet.Cells["J6"].Value = "     Current (" + range + ") ";


                for (int i = 0; i < listV.Count - 1; i++)
                {
                    if (range == "mA")
                    {
                        worksheet.Cells["E" + (12 + i).ToString()].Value = listV[i];
                        worksheet.Cells["J" + (12 + i).ToString()].Value = 1000 * listI[i];
                    }

                    else if (range == "uA")
                    {
                        worksheet.Cells["E" + (12 + i).ToString()].Value = listV[i];
                        worksheet.Cells["J" + (12 + i).ToString()].Value = listI[i];
                    }
                    else if (range == "uA")
                    {
                        worksheet.Cells["E" + (12 + i).ToString()].Value = listV[i];
                        worksheet.Cells["J" + (12 + i).ToString()].Value = listI[i] / 1000;
                    }
                }



                workbook.Save(fileaddress);



                return(imageaddress);
            }
            catch (Exception ex)
            {
                //  MessageBox.Show("Excel is not properly installed!!");
                return(null);
            }
        }