private static void LoadFromDb()
 {
     _pool = new Dictionary<long, FactorStatistic>();
     var collection = new DataBaseCollection<FactorStatistic>();
     collection.Load(@"select BIT_MASK, FACTOR_NAME, NUMBER_OF_STARTERS, NUMBER_OF_WINNERS, ROI, IV from FACTOR_NAME");
     collection.ForEach(fs => _pool.Add(fs.BitMask, fs));
 }
        public static void CreateGoldenFigureFile(string filename)
        {
            var collection = new DataBaseCollection<StarterInfo>();

            collection.Load(_sqlLoad);

            int counter = 0;
            using (var tw = new StreamWriter(filename))
            {
                string currentHorse = "";
                string line = "";

                foreach (var si in collection)
                {
                    ++counter;

                    if (0 == counter % 100)
                    {
                        Console.WriteLine(counter);
                    }

                    if(si.GoldenFigure == -999 || si.WinnersGoldenFigure == -999)
                        continue;

                    string horse = si.HorseName;

                    if (currentHorse.Length > 0 && currentHorse != horse)
                    {
                        if (line.Length > 0)
                        {
                            tw.Write(currentHorse);
                            tw.Write(",");
                            tw.WriteLine(line);
                        }

                        line = "";
                    }

                    currentHorse = horse;

                    if (si.FinishPosition > 0)
                    {
                        if (line.Length > 0)
                        {
                            line += ",";
                        }

                        line += si.GetAsParsableString();
                    }

                }

                if (line.Length > 0)
                {
                    tw.Write(currentHorse);
                    tw.Write(",");
                    tw.WriteLine(line);
                }

                tw.Close();
            }
        }
        private void LoadAllRacesForTheDistance()
        {
            if (_skipLoading)
                return;

            try
            {
                Cursor = Cursors.WaitCursor;

                if (null == _currentRaceInfo)
                    return;

                _gridShowAllRacesForTheDistance.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;

                DateTime fd = _periodSelector.FromDate;
                DateTime td = _periodSelector.ToDate;

                string fromDate = string.Format("{0}{1:00}{2:00}", fd.Year, fd.Month, fd.Day);
                string toDate = string.Format("{0}{1:00}{2:00}", td.Year, td.Month, td.Day);
                string surf = _currentRaceInfo.Surface;
                string trackCode = _currentRaceInfo.TrackCode;
                string aboutFlag = _currentRaceInfo.AboutFlag.Trim();

                _tbDistance.Text = Utilities.ConvertYardsToMilesOrFurlongs((int) _currentRaceInfo.Distance);

                if (aboutFlag.Contains("A"))
                {
                    _tbDistance.Text = new string('*', 1) + _tbDistance.Text;
                }

                _tbSurface.Text = surf;
                var collection = new DataBaseCollection<RaceResults>();

                string sqlLoader = string.Format(_sqlLoadRacesForDistanceAndTrack, trackCode, _currentRaceInfo.Distance, surf, aboutFlag, fromDate, toDate);
                collection.Load(sqlLoader);

                RaceResults.InitializeGrid(_gridShowAllRacesForTheDistance, collection.Count);
                WinnerInfo thisRaceInfo = null;
                int rowIndex = 0;
                collection.ForEach(rr => rr.AddToGrid(_gridShowAllRacesForTheDistance, _currentRaceInfo.RaceId, rowIndex++));
                _gridShowAllRacesForTheDistance.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                _tbNumberOfRaces.Text = collection.Count.ToString();

            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }