private void button1_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.InitialDirectory = Application.StartupPath;
                dlg.Multiselect      = true;

                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    foreach (string filename in dlg.FileNames)
                    {
                        RaceData race = RaceData.Load(filename);
                        foreach (KeyValuePair <long, RaceDataItem> kvp in race)
                        {
                            kvp.Value.Waters.FixWaterType();
                        }
                        race.Save(filename);
                    }
                }
            }
        }
Exemple #2
0
        private void btnFit_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.InitialDirectory = Application.StartupPath;
                dlg.Multiselect      = true;

                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    this.btnFit.Enabled = false;

                    Thread t = new Thread(delegate(object args)
                    {
                        string[] filenames = (string[])args;
                        foreach (string filename in dlg.FileNames)
                        {
                            RaceData race = RaceData.Load(filename);

                            int i = 0;
                            foreach (KeyValuePair <long, RaceDataItem> item in race)
                            {
                                if (i++ == -1)
                                {
                                    continue;
                                }
                                this.Invoke(new MethodInvoker(delegate
                                {
                                    this.txtFitLog.AppendText(string.Format("{0:HH:mm:ss} > {1} of {2} fitting...\r\n", DateTime.Now, item.Key, filename));
                                }));

                                item.Value.Odds.ClearSCR();
                                double E          = Fitting.fit(item.Value.Odds, 0.0001);
                                item.Value.Odds.E = E;

                                this.Invoke(new MethodInvoker(delegate
                                {
                                    this.txtFitLog.AppendText(string.Format("{0:HH:mm:ss} > {1} of {2} E = {3}\r\n", DateTime.Now, item.Key, filename, E));
                                }));

                                if (i >= 2)
                                {
                                    break;
                                }
                            }

                            Match m = Regex.Match(filename, @"^(.+?)\.fit(\d*)$");
                            if (m.Success)
                            {
                                if (m.Groups[2].Value == "")
                                {
                                    race.Save(m.Groups[1].Value + ".fit2");
                                }
                                else
                                {
                                    race.Save(m.Groups[1].Value + ".fit" + (int.Parse(m.Groups[2].Value) + 1).ToString());
                                }
                            }
                            else
                            {
                                race.Save(filename + ".fit");
                            }


                            this.Invoke(new MethodInvoker(delegate
                            {
                                this.txtFitLog.AppendText(string.Format("{0:HH:mm:ss} > file {1} finished\r\n", DateTime.Now, filename));
                            }));
                        }

                        this.Invoke(new MethodInvoker(delegate
                        {
                            this.txtFitLog.AppendText(string.Format("{0:HH:mm:ss} > all finished\r\n", DateTime.Now));
                            this.btnFit.Enabled = true;
                        }));
                    });
                    t.Start(dlg.FileNames);
                }
            }
        }