コード例 #1
0
        public MLBHOFPrediction PredictOnHallOfFameBallot(MLBBaseballBatter mLBBaseballBatter)
        {
            var predEngineOnHallOfFameBallot =
                _mlContext.Model.CreatePredictionEngine <MLBBaseballBatter, MLBHOFPrediction>(_loadedModelOnHallOfFameBallot);

            return(predEngineOnHallOfFameBallot.Predict(mLBBaseballBatter));
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("LUCENE CREATE INDEX - Start");

            // Create Lucene Index Location
            var indexLocation    = Path.Combine(Environment.CurrentDirectory, "LuceneIndex");
            var indexZipLocation = Path.Combine(Environment.CurrentDirectory, "LuceneIndexZip");

            if (!System.IO.Directory.Exists(indexLocation))
            {
                System.IO.Directory.CreateDirectory(indexLocation);
            }

            if (!System.IO.Directory.Exists(indexZipLocation))
            {
                System.IO.Directory.CreateDirectory(indexZipLocation);
            }

            var dataStream = GetBaseballData();

            var lines = ReadLines(() => dataStream, Encoding.UTF8);

            // Skip the first header line
            var batters = lines
                          .Skip(1)
                          .Select(v => MLBBaseballBatter.FromCsv(v))
                          .ToList();


            // LUCENE - CREATE THE INDEX
            var AppLuceneVersion = LuceneVersion.LUCENE_48;

            var dir = FSDirectory.Open(indexLocation);

            //create an analyzer to process the text
            var analyzer = new StandardAnalyzer(AppLuceneVersion);

            //create an index writer
            var indexConfig = new IndexWriterConfig(AppLuceneVersion, analyzer);

            indexConfig.OpenMode = OpenMode.CREATE;

            var writer = new IndexWriter(dir, indexConfig);

            // Get max Years Played for each batter
            var battersMaxYearsPlayed = from b in batters
                                        group b by b.ID into g
                                        select new MLBBaseballBatter {
                ID = g.Key, YearsPlayed = g.Max(b => b.YearsPlayed)
            };

            Console.WriteLine("LUCENE CREATE INDEX - Iterating Data for Index");

            foreach (var batter in batters)
            {
                var isBatterMaxYearsRecord = (from batterMax in battersMaxYearsPlayed
                                              where ((batterMax.ID == batter.ID) && (batterMax.YearsPlayed == batter.YearsPlayed))
                                              select new { ID = batterMax.ID }).Count();

                Document doc = new Document
                {
                    // Field names map to the MLBBaseballPlayer.cs class
                    // that is used in ML.NET models, demos etc.

                    // StringField indexes but doesn't tokenize
                    new StringField("Id",
                                    batter.ID,
                                    Field.Store.YES),
                    new Int32Field("IsBatterMaxYearsRecord",
                                   isBatterMaxYearsRecord, Field.Store.YES),
                    new TextField("FullPlayerName",
                                  batter.FullPlayerName,
                                  Field.Store.YES),
                    new StringField("InductedToHallOfFame",
                                    batter.InductedToHallOfFame.ToString(),
                                    Field.Store.YES),
                    new StringField("OnHallOfFameBallot",
                                    batter.OnHallOfFameBallot.ToString(),
                                    Field.Store.YES),
                    new SingleField("YearsPlayed",
                                    batter.YearsPlayed, Field.Store.YES),
                    // Use StoredField to minimize index storage, since these fields won't be searched on
                    new StoredField("AB",
                                    batter.AB),
                    new StoredField("R",
                                    batter.R),
                    new StoredField("H",
                                    batter.H),
                    new StoredField("Doubles",
                                    batter.Doubles),
                    new StoredField("Triples",
                                    batter.Triples),
                    new StoredField("HR",
                                    batter.HR),
                    new StoredField("RBI",
                                    batter.RBI),
                    new StoredField("SB",
                                    batter.SB),
                    new StoredField("BattingAverage",
                                    batter.BattingAverage),
                    new StoredField("SluggingPct",
                                    batter.SluggingPct),
                    new StoredField("AllStarAppearances",
                                    batter.AllStarAppearances),
                    new StoredField("MVPs",
                                    batter.MVPs),
                    new StoredField("TripleCrowns",
                                    batter.TripleCrowns),
                    new StoredField("GoldGloves",
                                    batter.GoldGloves),
                    new StoredField("MajorLeaguePlayerOfTheYearAwards",
                                    batter.MajorLeaguePlayerOfTheYearAwards),
                    new StoredField("TB",
                                    batter.TB),
                    new StoredField("TotalPlayerAwards",
                                    batter.TotalPlayerAwards),
                    new StoredField("LastYearPlayed",
                                    batter.LastYearPlayed)
                };

                // Console.WriteLine("Added: " + batter.ToString());
                writer.AddDocument(doc);
            }

            writer.Flush(triggerMerge: true, applyAllDeletes: false);
            writer.Commit();

            var numberDocs = writer.NumDocs;

            Console.WriteLine("LUCENE CREATE INDEX - Number of Docs Written to Index: " + numberDocs);

            // Close the index writer
            writer.Dispose();
            Console.WriteLine("LUCENE CREATE INDEX - Index Created");

            // LUCENE - PACKAGE THE INDEX AS ZIP FILE
            var packagePath = Path.Combine(indexZipLocation, "LuceneIndex.zip");

            // Delete the Zip file before proceeding
            if (File.Exists(packagePath))
            {
                File.Delete(packagePath);
            }

            ZipFile.CreateFromDirectory(indexLocation, packagePath, CompressionLevel.Optimal, false);
            Console.WriteLine("LUCENE CREATE INDEX - Index Packaged (Zip)");

            // LUCENE - TEST THE INDEX
            // Load the index from Zip file (mimic it loading)
            Console.WriteLine("LUCENE CREATE INDEX - Text the Index from Packaged (Zip)");

            ZipFile.ExtractToDirectory(packagePath, Environment.CurrentDirectory, true);
            var zipDirectory = FSDirectory.Open(Environment.CurrentDirectory);

            var indexReader = DirectoryReader.Open(zipDirectory);
            var searcher    = new IndexSearcher(indexReader);

            // Simple Query
            QueryParser parser        = new QueryParser(AppLuceneVersion, "FullPlayerName", analyzer);
            var         query         = parser.Parse("Todd");
            var         searchResults = searcher.Search(query, 500);// 20 /* top 20 */);
            var         hits          = searchResults.ScoreDocs;

            Console.WriteLine("LUCENE CREATE INDEX - Search for 'Todd': " + hits.Length);

            //foreach (var hit in hits)
            //{
            //    var foundDoc = searcher.Doc(hit.Doc);
            //    var name = foundDoc.GetField("FullPlayerName").GetStringValue();
            //    var yearsPlayed = foundDoc.GetField("YearsPlayed").GetSingleValue();
            //    var explanation = searcher.Explain(query, hit.Doc);

            //    Console.WriteLine("Found: " + name + " - " + hit.Score);
            //    Console.WriteLine("Explanation: " + explanation.ToString());

            //    var score = hit.Score;
            //}


            // Simple Query- With Filter
            var queryRanged = NumericRangeQuery.NewInt32Range("IsBatterMaxYearsRecord", 1, 1, true, true);

            BooleanQuery andQuery = new BooleanQuery();

            andQuery.Add(query, Occur.MUST);
            andQuery.Add(queryRanged, Occur.MUST);

            var searchResultsWithFilter = searcher.Search(andQuery, 500); /* top 500 */;
            var hitsWithFilter          = searchResultsWithFilter.ScoreDocs;

            Console.WriteLine("LUCENE CREATE INDEX - Search for 'Todd' with Max Years Filter: " + hitsWithFilter.Length);

            //foreach (var hit in hitsWithFilter)
            //{
            //    var foundDoc = searcher.Doc(hit.Doc);
            //    var name = foundDoc.GetField("FullPlayerName").GetStringValue();
            //    var isBatterMaxYearsRecord = foundDoc.GetField("IsBatterMaxYearsRecord").GetInt32Value();
            //    var explanation = searcher.Explain(query, hit.Doc);

            //    Console.WriteLine("Found: " + name + " - " + hit.Score);
            //    Console.WriteLine("Explanation: " + explanation.ToString());

            //    var score = hit.Score;
            //}

            // Query For Id
            var termHankAaron = new Term("Id", "aaronha01");
            var termQuery     = new TermQuery(termHankAaron);

            var searchResultsTermQuery = searcher.Search(termQuery, 50); /* top 50 */;
            var hitsTermQuery          = searchResultsTermQuery.ScoreDocs;

            Console.WriteLine("LUCENE CREATE INDEX - Search for 'Id = aaronha01': " + hitsTermQuery.Length);
        }
コード例 #3
0
        public Task <List <MLBBaseballBatter> > GetSampleBaseballData()
        {
            // Return sample baseball players (batters)
            // Mix of fictitious, active & retired players of all skills

            // Note: In a production system this service would load the list of batters
            // from distributed persisted storage, searched in information retrieval engine (i.e. Azure Search, Lucene),
            // a relational database etc.

            // Load MLB baseball batters from local CSV file
            string filePathMLBBaseballBatters = "Data/MLBBaseballBatters.csv";

            var batters = File.ReadAllLines(filePathMLBBaseballBatters)
                          .Skip(1)
                          .Select(v => MLBBaseballBatter.FromCsv(v))
                          .ToList();

            // Create Fictitious Players
            //MLBBaseballBatter badMLBBatter = new MLBBaseballBatter
            //{
            //    FullPlayerName = "Barry Badd (Fictitious Player)",
            //    ID = 100f,
            //    InductedToHallOfFame = false,
            //    LastYearPlayed = 0f,
            //    OnHallOfFameBallot = false,
            //    YearsPlayed = 2f,
            //    AB = 100f,
            //    R = 10f,
            //    H = 30f,
            //    Doubles = 1f,
            //    Triples = 1f,
            //    HR = 1f,
            //    RBI = 10f,
            //    SB = 10f,
            //    BattingAverage = 0.3f,
            //    SluggingPct = 0.15f,
            //    AllStarAppearances = 0f,
            //    MVPs = 0f,
            //    TripleCrowns = 0f,
            //    GoldGloves = 0f,
            //    MajorLeaguePlayerOfTheYearAwards = 0f,
            //    TB = 200f
            //};
            //MLBBaseballBatter averageMLBBatter = new MLBBaseballBatter
            //{
            //    FullPlayerName = "Andy Average (Fictitious Player)",
            //    ID = 200f,
            //    InductedToHallOfFame = false,
            //    LastYearPlayed = 0f,
            //    OnHallOfFameBallot = false,
            //    YearsPlayed = 17f,
            //    AB = 8393f,
            //    R = 1162f,
            //    H = 2300f,
            //    Doubles = 410f,
            //    Triples = 8f,
            //    HR = 400f,
            //    RBI = 1312f,
            //    SB = 9f,
            //    BattingAverage = 0.278f,
            //    SluggingPct = 0.476f,
            //    AllStarAppearances = 5f,
            //    MVPs = 0f,
            //    TripleCrowns = 0f,
            //    GoldGloves = 0f,
            //    MajorLeaguePlayerOfTheYearAwards = 0f,
            //    TB = 3910f
            //};
            //MLBBaseballBatter greatMLBBatter = new MLBBaseballBatter
            //{
            //    FullPlayerName = "Gary The Great (Fictitious Player)",
            //    ID = 300f,
            //    InductedToHallOfFame = false,
            //    LastYearPlayed = 0f,
            //    OnHallOfFameBallot = false,
            //    YearsPlayed = 20f,
            //    AB = 10000f,
            //    R = 1900f,
            //    H = 3500f,
            //    Doubles = 500f,
            //    Triples = 150f,
            //    HR = 600f,
            //    RBI = 1800f,
            //    SB = 400f,
            //    BattingAverage = 0.350f,
            //    SluggingPct = 0.65f,
            //    AllStarAppearances = 14f,
            //    MVPs = 2f,
            //    TripleCrowns = 1f,
            //    GoldGloves = 4f,
            //    MajorLeaguePlayerOfTheYearAwards = 2f,
            //    TB = 7000f
            //};

            //// Add Fictitious Players
            //batters.Add(badMLBBatter);
            //batters.Add(averageMLBBatter);
            //batters.Add(greatMLBBatter);

            return(Task.FromResult(
                       batters.OrderByDescending(a => a.YearsPlayed).ToList()
                       ));;
        }
        public Task <List <MLBBaseballBatter> > GetSampleBaseballData()
        {
            MLBBaseballBatter badMLBBatter = new MLBBaseballBatter
            {
                FullPlayerName       = "Barry Badd (fictitious)",
                ID                   = 100f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 0f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 2f,
                AB                   = 100f,
                R                  = 10f,
                H                  = 30f,
                Doubles            = 1f,
                Triples            = 1f,
                HR                 = 1f,
                RBI                = 10f,
                SB                 = 10f,
                BattingAverage     = 0.3f,
                SluggingPct        = 0.15f,
                AllStarAppearances = 0f,
                MVPs               = 0f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 200f
            };
            MLBBaseballBatter averageMLBBatter = new MLBBaseballBatter
            {
                FullPlayerName       = "Andy Average (fictitious)",
                ID                   = 200f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 0f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 17f,
                AB                   = 8393f,
                R                  = 1162f,
                H                  = 2300f,
                Doubles            = 410f,
                Triples            = 8f,
                HR                 = 400f,
                RBI                = 1312f,
                SB                 = 9f,
                BattingAverage     = 0.278f,
                SluggingPct        = 0.476f,
                AllStarAppearances = 5f,
                MVPs               = 0f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 3910f
            };
            MLBBaseballBatter greatMLBBatter = new MLBBaseballBatter
            {
                FullPlayerName       = "Gary The Great (fictitious)",
                ID                   = 300f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 0f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 20f,
                AB                   = 10000f,
                R                  = 1900f,
                H                  = 3500f,
                Doubles            = 500f,
                Triples            = 150f,
                HR                 = 600f,
                RBI                = 1800f,
                SB                 = 400f,
                BattingAverage     = 0.350f,
                SluggingPct        = 0.65f,
                AllStarAppearances = 14f,
                MVPs               = 2f,
                TripleCrowns       = 1f,
                GoldGloves         = 4f,
                MajorLeaguePlayerOfTheYearAwards = 2f,
                TB = 7000f
            };
            MLBBaseballBatter babeRuth = new MLBBaseballBatter
            {
                FullPlayerName       = "Babe Ruth",
                ID                   = 400f,
                InductedToHallOfFame = true,
                LastYearPlayed       = 1935f,
                OnHallOfFameBallot   = true,
                YearsPlayed          = 22f,
                AB                   = 8399f,
                R                  = 2174f,
                H                  = 2873f,
                Doubles            = 506f,
                Triples            = 136f,
                HR                 = 714f,
                RBI                = 2214f,
                SB                 = 123f,
                BattingAverage     = 0.342f,
                SluggingPct        = 0.690f,
                AllStarAppearances = 2f,
                MVPs               = 1f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 5793f
            };
            MLBBaseballBatter mikeTrout = new MLBBaseballBatter
            {
                FullPlayerName       = "Mike Trout",
                ID                   = 500f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 2019f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 9f,
                AB                   = 4340f,
                R                  = 903f,
                H                  = 1324f,
                Doubles            = 251f,
                Triples            = 46f,
                HR                 = 285f,
                RBI                = 752f,
                SB                 = 200f,
                BattingAverage     = 0.305f,
                SluggingPct        = 0.581f,
                AllStarAppearances = 8f,
                MVPs               = 2f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 2522f
            };
            MLBBaseballBatter haroldBaines = new MLBBaseballBatter
            {
                FullPlayerName       = "Harold Baines",
                ID                   = 600f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 2001f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 22f,
                AB                   = 9908f,
                R                  = 1299f,
                H                  = 2866f,
                Doubles            = 488f,
                Triples            = 49f,
                HR                 = 384f,
                RBI                = 1628f,
                SB                 = 34f,
                BattingAverage     = 0.289f,
                SluggingPct        = 0.289f,
                AllStarAppearances = 6f,
                MVPs               = 0f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 5525f
            };

            List <MLBBaseballBatter> batters = new List <MLBBaseballBatter>()
            {
                badMLBBatter, averageMLBBatter, greatMLBBatter,
                babeRuth, mikeTrout, haroldBaines
            };

            return(Task.FromResult(
                       batters
                       ));
        }
コード例 #5
0
        public static Task <List <MLBBaseballBatter> > GetSampleBaseballData()
        {
            // Return sample baseball players (batters)
            // Mix of fictitious, active & retired players of all skills

            // Note: In a production system this service would load the list of batters
            // from persisted storage, searched in information retrieval engine (i.e. Azure Search, Lucene),
            // a relational database etc.

            // Fictitious players
            MLBBaseballBatter badMLBBatter = new MLBBaseballBatter
            {
                FullPlayerName       = "Barry Badd (Fictitious Player)",
                ID                   = 100f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 0f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 2f,
                AB                   = 100f,
                R                  = 10f,
                H                  = 30f,
                Doubles            = 1f,
                Triples            = 1f,
                HR                 = 1f,
                RBI                = 10f,
                SB                 = 10f,
                BattingAverage     = 0.3f,
                SluggingPct        = 0.15f,
                AllStarAppearances = 0f,
                MVPs               = 0f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 200f
            };
            MLBBaseballBatter averageMLBBatter = new MLBBaseballBatter
            {
                FullPlayerName       = "Andy Average (Fictitious Player)",
                ID                   = 200f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 0f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 17f,
                AB                   = 8393f,
                R                  = 1162f,
                H                  = 2300f,
                Doubles            = 410f,
                Triples            = 8f,
                HR                 = 400f,
                RBI                = 1312f,
                SB                 = 9f,
                BattingAverage     = 0.278f,
                SluggingPct        = 0.476f,
                AllStarAppearances = 5f,
                MVPs               = 0f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 3910f
            };
            MLBBaseballBatter greatMLBBatter = new MLBBaseballBatter
            {
                FullPlayerName       = "Gary The Great (Fictitious Player)",
                ID                   = 300f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 0f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 20f,
                AB                   = 10000f,
                R                  = 1900f,
                H                  = 3500f,
                Doubles            = 500f,
                Triples            = 150f,
                HR                 = 600f,
                RBI                = 1800f,
                SB                 = 400f,
                BattingAverage     = 0.350f,
                SluggingPct        = 0.65f,
                AllStarAppearances = 14f,
                MVPs               = 2f,
                TripleCrowns       = 1f,
                GoldGloves         = 4f,
                MajorLeaguePlayerOfTheYearAwards = 2f,
                TB = 7000f
            };

            // Real players statistics (up to the end of the 2019 season)
            MLBBaseballBatter babeRuth = new MLBBaseballBatter
            {
                FullPlayerName       = "Babe Ruth",
                ID                   = 400f,
                InductedToHallOfFame = true,
                LastYearPlayed       = 1935f,
                OnHallOfFameBallot   = true,
                YearsPlayed          = 22f,
                AB                   = 8399f,
                R                  = 2174f,
                H                  = 2873f,
                Doubles            = 506f,
                Triples            = 136f,
                HR                 = 714f,
                RBI                = 2214f,
                SB                 = 123f,
                BattingAverage     = 0.342f,
                SluggingPct        = 0.690f,
                AllStarAppearances = 2f,
                MVPs               = 1f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 5793f
            };
            MLBBaseballBatter mikeTrout = new MLBBaseballBatter
            {
                FullPlayerName       = "Mike Trout (Active Player)",
                ID                   = 500f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 2019f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 9f,
                AB                   = 4340f,
                R                  = 903f,
                H                  = 1324f,
                Doubles            = 251f,
                Triples            = 46f,
                HR                 = 285f,
                RBI                = 752f,
                SB                 = 200f,
                BattingAverage     = 0.305f,
                SluggingPct        = 0.581f,
                AllStarAppearances = 8f,
                MVPs               = 2f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 2522f,
                TotalPlayerAwards = 13f
            };
            MLBBaseballBatter haroldBaines = new MLBBaseballBatter
            {
                FullPlayerName       = "Harold Baines",
                ID                   = 600f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 2001f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 22f,
                AB                   = 9908f,
                R                  = 1299f,
                H                  = 2866f,
                Doubles            = 488f,
                Triples            = 49f,
                HR                 = 384f,
                RBI                = 1628f,
                SB                 = 34f,
                BattingAverage     = 0.289f,
                SluggingPct        = 0.289f,
                AllStarAppearances = 6f,
                MVPs               = 0f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 5525f,
                TotalPlayerAwards = 4f
            };
            MLBBaseballBatter bryceHarper = new MLBBaseballBatter
            {
                FullPlayerName       = "Bryce Harper (Active Player)",
                ID                   = 700f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 2019f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 8f,
                AB                   = 3879f,
                R                  = 708f,
                H                  = 1071f,
                Doubles            = 219f,
                Triples            = 19f,
                HR                 = 219f,
                RBI                = 635f,
                SB                 = 90f,
                BattingAverage     = 0.276f,
                SluggingPct        = 0.512f,
                AllStarAppearances = 6f,
                MVPs               = 1f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 1985f,
                TotalPlayerAwards = 4f
            };
            MLBBaseballBatter derekJeter = new MLBBaseballBatter
            {
                FullPlayerName       = "Derek Jeter",
                ID                   = 101f,
                InductedToHallOfFame = true,
                LastYearPlayed       = 2014f,
                OnHallOfFameBallot   = true,
                YearsPlayed          = 20f,
                AB                   = 11195f,
                R                  = 1923f,
                H                  = 3465f,
                Doubles            = 544f,
                Triples            = 66f,
                HR                 = 260f,
                RBI                = 1311f,
                SB                 = 358f,
                BattingAverage     = 0.310f,
                SluggingPct        = 0.440f,
                AllStarAppearances = 14f,
                MVPs               = 1f,
                TripleCrowns       = 0f,
                GoldGloves         = 5f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 4921f,
                TotalPlayerAwards = 20f
            };
            MLBBaseballBatter willieMays = new MLBBaseballBatter
            {
                FullPlayerName       = "Willie Mays",
                ID                   = 900f,
                InductedToHallOfFame = true,
                LastYearPlayed       = 1973f,
                OnHallOfFameBallot   = true,
                YearsPlayed          = 22f,
                AB                   = 10881f,
                R                  = 2062f,
                H                  = 3283f,
                Doubles            = 523f,
                Triples            = 140f,
                HR                 = 660f,
                RBI                = 1903f,
                SB                 = 338f,
                BattingAverage     = 0.302f,
                SluggingPct        = 0.557f,
                AllStarAppearances = 24f,
                MVPs               = 2f,
                TripleCrowns       = 0f,
                GoldGloves         = 12f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 6066f,
                TotalPlayerAwards = 32f
            };
            MLBBaseballBatter daleMurphy = new MLBBaseballBatter
            {
                FullPlayerName       = "Dale Murphy",
                ID                   = 1900f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 1993f,
                OnHallOfFameBallot   = true,
                YearsPlayed          = 18f,
                AB                   = 7960f,
                R                  = 1197f,
                H                  = 2111f,
                Doubles            = 350f,
                Triples            = 39f,
                HR                 = 398f,
                RBI                = 1266f,
                SB                 = 161f,
                BattingAverage     = 0.265f,
                SluggingPct        = 0.469f,
                AllStarAppearances = 7f,
                MVPs               = 2f,
                TripleCrowns       = 0f,
                GoldGloves         = 5f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 3733f,
                TotalPlayerAwards = 19f
            };
            MLBBaseballBatter davidOrtiz = new MLBBaseballBatter
            {
                FullPlayerName       = "David Ortiz",
                ID                   = 1905f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 2016f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 20f,
                AB                   = 8640f,
                R                  = 1419f,
                H                  = 2472f,
                Doubles            = 632f,
                Triples            = 19f,
                HR                 = 541f,
                RBI                = 1768f,
                SB                 = 17f,
                BattingAverage     = 0.286f,
                SluggingPct        = 0.552f,
                AllStarAppearances = 10f,
                MVPs               = 0f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 4765f,
                TotalPlayerAwards = 18f
            };
            MLBBaseballBatter calRipken = new MLBBaseballBatter
            {
                FullPlayerName       = "Cal Ripken Jr",
                ID                   = 1000f,
                InductedToHallOfFame = true,
                LastYearPlayed       = 2001f,
                OnHallOfFameBallot   = true,
                YearsPlayed          = 21f,
                AB                   = 11551f,
                R                  = 1647f,
                H                  = 3184f,
                Doubles            = 603f,
                Triples            = 44f,
                HR                 = 431f,
                RBI                = 1695f,
                SB                 = 36f,
                BattingAverage     = 0.276f,
                SluggingPct        = 0.447f,
                AllStarAppearances = 19f,
                MVPs               = 2f,
                TripleCrowns       = 0f,
                GoldGloves         = 2f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 5168f,
                TotalPlayerAwards = 29f
            };
            MLBBaseballBatter garySheffield = new MLBBaseballBatter
            {
                FullPlayerName       = "Gary Sheffield",
                ID                   = 1050f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 2009f,
                OnHallOfFameBallot   = true,
                YearsPlayed          = 22f,
                AB                   = 9217f,
                R                  = 1636f,
                H                  = 2689f,
                Doubles            = 467f,
                Triples            = 27f,
                HR                 = 509f,
                RBI                = 1676f,
                SB                 = 104f,
                BattingAverage     = 0.292f,
                SluggingPct        = 0.514f,
                AllStarAppearances = 9f,
                MVPs               = 0f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 4737f,
                TotalPlayerAwards = 9f
            };
            MLBBaseballBatter omarVizquel = new MLBBaseballBatter
            {
                FullPlayerName       = "Omar Vizquel",
                ID                   = 1300f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 2012f,
                OnHallOfFameBallot   = true,
                YearsPlayed          = 24f,
                AB                   = 10586f,
                R                  = 1445f,
                H                  = 2877f,
                Doubles            = 456f,
                Triples            = 77f,
                HR                 = 80f,
                RBI                = 951f,
                SB                 = 404f,
                BattingAverage     = 0.272f,
                SluggingPct        = 0.352f,
                AllStarAppearances = 3f,
                MVPs               = 0f,
                TripleCrowns       = 0f,
                GoldGloves         = 11f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 3727f,
                TotalPlayerAwards = 12f
            };
            MLBBaseballBatter larryWalker = new MLBBaseballBatter
            {
                FullPlayerName       = "Larry Walker",
                ID                   = 1400f,
                InductedToHallOfFame = true,
                LastYearPlayed       = 2005f,
                OnHallOfFameBallot   = true,
                YearsPlayed          = 17f,
                AB                   = 6907f,
                R                  = 1355f,
                H                  = 2160f,
                Doubles            = 471f,
                Triples            = 62f,
                HR                 = 383f,
                RBI                = 1311f,
                SB                 = 230f,
                BattingAverage     = 0.313f,
                SluggingPct        = 0.565f,
                AllStarAppearances = 5f,
                MVPs               = 1f,
                TripleCrowns       = 0f,
                GoldGloves         = 7f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 3904f,
                TotalPlayerAwards = 14f
            };
            MLBBaseballBatter ryanZimmerman = new MLBBaseballBatter
            {
                FullPlayerName       = "Ryan Zimmerman (Active Player)",
                ID                   = 1500f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 2019f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 15f,
                AB                   = 6399f,
                R                  = 936f,
                H                  = 1784f,
                Doubles            = 401f,
                Triples            = 22f,
                HR                 = 270f,
                RBI                = 1015f,
                SB                 = 43f,
                BattingAverage     = 0.279f,
                SluggingPct        = 0.479f,
                AllStarAppearances = 2f,
                MVPs               = 0f,
                TripleCrowns       = 0f,
                GoldGloves         = 1f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 3039f,
                TotalPlayerAwards = 5f
            };

            List <MLBBaseballBatter> batters = new List <MLBBaseballBatter>()
            {
                badMLBBatter, averageMLBBatter, greatMLBBatter,
                haroldBaines, bryceHarper, derekJeter, willieMays, davidOrtiz,
                daleMurphy, calRipken, babeRuth, garySheffield,
                mikeTrout, omarVizquel, larryWalker, ryanZimmerman
            };

            return(Task.FromResult(
                       batters
                       ));
        }
コード例 #6
0
        public static string GetWhatIfUrl(bool useMachineLearningModel, bool MultipleModels, MLBBaseballBatter baseballBatter, int numberOfSeasonsPlayed)
        {
            var basePage = string.Empty;

            if (!useMachineLearningModel)
            {
                basePage = "WhatIfAnalysisRulesEngine";
            }
            else
            {
                if (MultipleModels)
                {
                    basePage = "WhatIfAnalysisMultipleModels";
                }
                else
                {
                    basePage = "WhatIfAnalysisSingleModel";
                }
            }

            string whatIfUrl = string.Format(
                "/{0}/{1}-{2}/YearsPlayed/{3}", basePage, baseballBatter.LastYearPlayed,
                Util.RemoveWhiteSpace(baseballBatter.FullPlayerName), numberOfSeasonsPlayed);

            return(whatIfUrl);
        }
        public Task <List <MLBBaseballBatter> > GetSampleBaseballData()
        {
            // Fictious players
            MLBBaseballBatter badMLBBatter = new MLBBaseballBatter
            {
                FullPlayerName       = "Barry Badd (Fictitious Player)",
                ID                   = 100f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 0f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 2f,
                AB                   = 100f,
                R                  = 10f,
                H                  = 30f,
                Doubles            = 1f,
                Triples            = 1f,
                HR                 = 1f,
                RBI                = 10f,
                SB                 = 10f,
                BattingAverage     = 0.3f,
                SluggingPct        = 0.15f,
                AllStarAppearances = 0f,
                MVPs               = 0f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 200f
            };
            MLBBaseballBatter averageMLBBatter = new MLBBaseballBatter
            {
                FullPlayerName       = "Andy Average (Fictitious Player)",
                ID                   = 200f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 0f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 17f,
                AB                   = 8393f,
                R                  = 1162f,
                H                  = 2300f,
                Doubles            = 410f,
                Triples            = 8f,
                HR                 = 400f,
                RBI                = 1312f,
                SB                 = 9f,
                BattingAverage     = 0.278f,
                SluggingPct        = 0.476f,
                AllStarAppearances = 5f,
                MVPs               = 0f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 3910f
            };
            MLBBaseballBatter greatMLBBatter = new MLBBaseballBatter
            {
                FullPlayerName       = "Gary The Great (Fictitious Player)",
                ID                   = 300f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 0f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 20f,
                AB                   = 10000f,
                R                  = 1900f,
                H                  = 3500f,
                Doubles            = 500f,
                Triples            = 150f,
                HR                 = 600f,
                RBI                = 1800f,
                SB                 = 400f,
                BattingAverage     = 0.350f,
                SluggingPct        = 0.65f,
                AllStarAppearances = 14f,
                MVPs               = 2f,
                TripleCrowns       = 1f,
                GoldGloves         = 4f,
                MajorLeaguePlayerOfTheYearAwards = 2f,
                TB = 7000f
            };
            // Real players up to 2019 season
            MLBBaseballBatter babeRuth = new MLBBaseballBatter
            {
                FullPlayerName       = "Babe Ruth",
                ID                   = 400f,
                InductedToHallOfFame = true,
                LastYearPlayed       = 1935f,
                OnHallOfFameBallot   = true,
                YearsPlayed          = 22f,
                AB                   = 8399f,
                R                  = 2174f,
                H                  = 2873f,
                Doubles            = 506f,
                Triples            = 136f,
                HR                 = 714f,
                RBI                = 2214f,
                SB                 = 123f,
                BattingAverage     = 0.342f,
                SluggingPct        = 0.690f,
                AllStarAppearances = 2f,
                MVPs               = 1f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 5793f
            };
            MLBBaseballBatter mikeTrout = new MLBBaseballBatter
            {
                FullPlayerName       = "Mike Trout (Active Player)",
                ID                   = 500f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 2019f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 9f,
                AB                   = 4340f,
                R                  = 903f,
                H                  = 1324f,
                Doubles            = 251f,
                Triples            = 46f,
                HR                 = 285f,
                RBI                = 752f,
                SB                 = 200f,
                BattingAverage     = 0.305f,
                SluggingPct        = 0.581f,
                AllStarAppearances = 8f,
                MVPs               = 2f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 2522f
            };
            MLBBaseballBatter haroldBaines = new MLBBaseballBatter
            {
                FullPlayerName       = "Harold Baines",
                ID                   = 600f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 2001f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 22f,
                AB                   = 9908f,
                R                  = 1299f,
                H                  = 2866f,
                Doubles            = 488f,
                Triples            = 49f,
                HR                 = 384f,
                RBI                = 1628f,
                SB                 = 34f,
                BattingAverage     = 0.289f,
                SluggingPct        = 0.289f,
                AllStarAppearances = 6f,
                MVPs               = 0f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 5525f
            };
            MLBBaseballBatter bryceHarper = new MLBBaseballBatter
            {
                FullPlayerName       = "Bryce Harper (Active Player)",
                ID                   = 700f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 2019f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 8f,
                AB                   = 3879f,
                R                  = 708f,
                H                  = 1071f,
                Doubles            = 219f,
                Triples            = 19f,
                HR                 = 219f,
                RBI                = 635f,
                SB                 = 90f,
                BattingAverage     = 0.276f,
                SluggingPct        = 0.512f,
                AllStarAppearances = 6f,
                MVPs               = 1f,
                TripleCrowns       = 0f,
                GoldGloves         = 0f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 1985f
            };
            MLBBaseballBatter willieMays = new MLBBaseballBatter
            {
                FullPlayerName       = "Willie Mays",
                ID                   = 900f,
                InductedToHallOfFame = true,
                LastYearPlayed       = 1973f,
                OnHallOfFameBallot   = true,
                YearsPlayed          = 22f,
                AB                   = 10881f,
                R                  = 2062f,
                H                  = 3283f,
                Doubles            = 523f,
                Triples            = 140f,
                HR                 = 660f,
                RBI                = 1903f,
                SB                 = 338f,
                BattingAverage     = 0.302f,
                SluggingPct        = 0.557f,
                AllStarAppearances = 24f,
                MVPs               = 2f,
                TripleCrowns       = 0f,
                GoldGloves         = 12f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 6066f
            };
            MLBBaseballBatter daleMurphy = new MLBBaseballBatter
            {
                FullPlayerName       = "Dale Murphy",
                ID                   = 1900f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 1993f,
                OnHallOfFameBallot   = true,
                YearsPlayed          = 18f,
                AB                   = 7960f,
                R                  = 1197f,
                H                  = 2111f,
                Doubles            = 350f,
                Triples            = 39f,
                HR                 = 398f,
                RBI                = 1266f,
                SB                 = 161f,
                BattingAverage     = 0.265f,
                SluggingPct        = 0.469f,
                AllStarAppearances = 7f,
                MVPs               = 2f,
                TripleCrowns       = 0f,
                GoldGloves         = 5f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 3733f
            };
            MLBBaseballBatter calRipken = new MLBBaseballBatter
            {
                FullPlayerName       = "Cal Ripken Jr",
                ID                   = 1000f,
                InductedToHallOfFame = true,
                LastYearPlayed       = 2001f,
                OnHallOfFameBallot   = true,
                YearsPlayed          = 21f,
                AB                   = 11551f,
                R                  = 1647f,
                H                  = 3184f,
                Doubles            = 603f,
                Triples            = 44f,
                HR                 = 431f,
                RBI                = 1695f,
                SB                 = 36f,
                BattingAverage     = 0.276f,
                SluggingPct        = 0.447f,
                AllStarAppearances = 19f,
                MVPs               = 2f,
                TripleCrowns       = 0f,
                GoldGloves         = 2f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 5168f
            };
            MLBBaseballBatter ryanZimmerman = new MLBBaseballBatter
            {
                FullPlayerName       = "Ryan Zimmerman (Active Player)",
                ID                   = 1100f,
                InductedToHallOfFame = false,
                LastYearPlayed       = 2019f,
                OnHallOfFameBallot   = false,
                YearsPlayed          = 15f,
                AB                   = 6399f,
                R                  = 936f,
                H                  = 1784f,
                Doubles            = 401f,
                Triples            = 22f,
                HR                 = 270f,
                RBI                = 1015f,
                SB                 = 43f,
                BattingAverage     = 0.279f,
                SluggingPct        = 0.479f,
                AllStarAppearances = 2f,
                MVPs               = 0f,
                TripleCrowns       = 0f,
                GoldGloves         = 1f,
                MajorLeaguePlayerOfTheYearAwards = 0f,
                TB = 3039f
            };

            List <MLBBaseballBatter> batters = new List <MLBBaseballBatter>()
            {
                badMLBBatter, averageMLBBatter, greatMLBBatter,
                haroldBaines, bryceHarper, willieMays, daleMurphy,
                calRipken, babeRuth, mikeTrout, ryanZimmerman
            };

            return(Task.FromResult(
                       batters
                       ));
        }