Exemplo n.º 1
0
        public void Run()
        {
            int counter = 0;

            Parallel.ForEach(Items, file =>
            {
                for (int nn = 1; nn < NeuronNumber; nn++)       //neuron number
                {
                    for (int i = 0; i < RepeatForEachFile; i++) //learning tests for file with x neurons in network
                    {
                        try
                        {
                            NBN nbn    = new NBN(nn, file);
                            var result = nbn.Run(1);

                            DateTime d = DateTime.Now;
                            History h  = new History();
                            h.Name     = String.Format("{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}", Path.GetFileNameWithoutExtension(result.Filename),
                                                       d.Year, d.Month, d.Day, d.Hour, d.Minute, d.Second, d.Millisecond);
                            h.Data = marekbar.Xml.Serialize <LearnResult>(result);
                            h.Insert();

                            if (PDF)
                            {
                                try
                                {
                                    string filename = Common.Folder.Data + "\\" + h.Name + ".pdf";

                                    PDFGenerate data   = new PDFGenerate();
                                    data.Filename      = filename;
                                    data.Result        = result;
                                    data.ChartFilename = GeneratePlot(result.RMSE[0], Path.GetFileNameWithoutExtension(result.Filename));
                                    HistoryPDF pdf     = new HistoryPDF(data.Result, data.ChartFilename, true);
                                    pdf.Save(data.Filename);
                                }
                                catch
                                {      //don't care about it
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            ex.GetError();
                        }
                        finally
                        {
                            counter++;
                            if (OnUpdate != null)
                            {
                                OnUpdate(counter);
                            }
                        }
                    }
                }
            });
        }
Exemplo n.º 2
0
        private void saveToPdfSimple(bool flag)
        {
            try
            {
                String filename = Common.Dialog.Save(LearnByError.Internazional.Resource.Inst.Get("r68"), "pdf");
                if (filename != "" && result != null)
                {
                    String chartFilename = Common.Folder.Data + "\\" +
                                           DateTime.Now.ToString().Replace(':', '_').Replace(' ', '_').Replace('-', '_') + ".bmp";
                    chart.SaveImage(chartFilename, System.Drawing.Imaging.ImageFormat.Bmp);

                    PDFGenerate tmp = new PDFGenerate();
                    tmp.Filename      = filename;
                    tmp.Result        = result;
                    tmp.ChartFilename = chartFilename;

                    var bw = new System.ComponentModel.BackgroundWorker();
                    bw.DoWork += (a, b) =>
                    {
                        var        data = (PDFGenerate)b.Argument;
                        HistoryPDF pdf  = new HistoryPDF(data.Result, data.ChartFilename, flag);

                        if (pdf.Save(data.Filename))
                        {
                            pdf.Open();

                            b.Result = LearnByError.Internazional.Resource.Inst.Get("r69") + data.Filename;
                        }
                        else
                        {
                            b.Result = LearnByError.Internazional.Resource.Inst.Get("r70");
                        }
                    };
                    bw.RunWorkerCompleted += (a, b) =>
                    {
                        status.Text      = (String)b.Result;
                        progress.Visible = false;
                    };
                    progress.Visible = true;
                    bw.RunWorkerAsync(tmp);
                }
            }
            catch (Exception ex)
            {
                ex.ToLog();
                status.Text = ex.Message;
            }
        }