Beispiel #1
0
        public void TestCenterOfCluster()
        {
            var grouper = new DBScan();
            var dbScanList = new List<DBScanProPlayerGame>();
            dbScanList.Add(new DBScanProPlayerGame(new ProPlayerGame(SummonerIds.C9.Sneaky, 1, 3, timeline1)));
            dbScanList.Add(new DBScanProPlayerGame(new ProPlayerGame(SummonerIds.C9.Sneaky, 2, 3, timeline2)));
            dbScanList.Add(new DBScanProPlayerGame(new ProPlayerGame(SummonerIds.C9.Sneaky, 3, 3, timeline3)));
            dbScanList.Add(new DBScanProPlayerGame(new ProPlayerGame(SummonerIds.C9.Sneaky, 4, 3, timeline4)));
            dbScanList.Add(new DBScanProPlayerGame(new ProPlayerGame(SummonerIds.C9.Sneaky, 5, 3, timeline5)));
            dbScanList.Add(new DBScanProPlayerGame(new ProPlayerGame(SummonerIds.C9.Sneaky, 6, 3, timeline6)));

            var results = grouper.GetClusters(dbScanList, 3, 2);
            Assert.AreEqual(2, results.Count);
            var centerOfCluster1 = grouper.FindCenterOfCluster(results[0]);

            // 3 should be the center because 1 is closest to 2 and 3 but 3 is equidistant to 1 and is longer
            Assert.AreEqual(3, centerOfCluster1.Game.GameId);

            var centerOfCluster2 = grouper.FindCenterOfCluster(results[1]);
            // this is not interesting because the cluster has 2 identical games, but make sure we don't choke.
            // it isn't important if 4 or 5 is the center, but our algorithm will stumble upon 4 first so it
            // should be returned
            Assert.AreEqual(4, centerOfCluster2.Game.GameId);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            using (var context = new GameContext())
            {
                var summonerIdsInTable = (from y in context.Games
                                       select y.SummonerId).Distinct().ToList();
                Console.WriteLine("There are {0} summoners in the database", summonerIdsInTable.Count());

                foreach (var proPlayerSummonerId in summonerIdsInTable)
                {
                    Console.WriteLine("Running through summoner id {0}", proPlayerSummonerId);
                    // we will only even both to run any algorithm to try an generate
                    // an item set if the pro has more than 5 games on the champion
                    var listOfGamesAccordingToChampion = (from x in context.Games
                                                          where x.SummonerId == proPlayerSummonerId
                                                          group x by x.ChampionId into champLists
                                                          where champLists.Count() >= 5
                                                          select champLists).ToList();

                    // the champList contains all games this pro played with 1 particular champ
                    foreach (var champList in listOfGamesAccordingToChampion)
                    {
                        Console.WriteLine("Running through champ id {0}", champList.Key);
                        Console.WriteLine("Games count on this champ is is {0}", champList.Count());

                        var dbScanList = new List<DBScanProPlayerGame>();
                        foreach (var game in champList)
                        {
                            System.Diagnostics.Debug.WriteLine("Game Id is {0}", game.GameId);
                            var dbScanProPlayerGame = new DBScanProPlayerGame(game);
                            dbScanList.Add(dbScanProPlayerGame);
                        }

                        Console.WriteLine("Running DBScan on games");
                        var dbScan = new DBScan();
                        var clusters = dbScan.GetClusters(dbScanList, 5, 3);

                        foreach (var oneCluster in clusters)
                        {
                            Console.WriteLine("Cluster of count {0} identified", oneCluster.Count);
                        }

                        if (clusters.Count != 0)
                        {
                            Console.WriteLine("Trying to find biggest cluster");
                            var biggestCluster = (from cluster in clusters
                                                  orderby cluster.Count
                                                  select cluster).First();

                            var centerOfBiggestCluster = dbScan.FindCenterOfCluster(biggestCluster);
                            var timelineFromCenter = centerOfBiggestCluster.Game.ItemPurchaseTimeline;
                            var itemBlocks = timelineFromCenter.TryToSplitIntoPurchases(15);

                            var itemSet = new ItemSet("Item Set", itemBlocks);
                            var itemSetJson = itemSet.ToJson();
                            Console.WriteLine("Generated item set with json\n{0}", itemSetJson);

                            var oldItem = context.ItemSets.SingleOrDefault((t) => t.SummonerId == proPlayerSummonerId && t.ChampionId == champList.Key);
                            //var oldItem = context.ItemSets.Find(proPlayerSummonerId, champList.Key);
                            if (oldItem != null)
                            {
                                oldItem.ItemSetJson = itemSetJson;
                            }
                            else
                            {
                                context.ItemSets.Add(new ProPlayerItemSet(proPlayerSummonerId, champList.Key, itemSetJson));
                            }
                        }
                        else
                        {
                            Console.WriteLine("No clusters found");
                        }
                    }
                }
                context.SaveChanges();
            }
        }
Beispiel #3
0
        public void TestTwoClustersAreIdentifiedWithTwoRadicallyDifferentBuilds()
        {
            var grouper = new DBScan();
            var dbScanList = new List<DBScanProPlayerGame>();
            dbScanList.Add(new DBScanProPlayerGame(new ProPlayerGame(SummonerIds.C9.Sneaky, 1, 3, timeline1)));
            dbScanList.Add(new DBScanProPlayerGame(new ProPlayerGame(SummonerIds.C9.Sneaky, 2, 3, timeline2)));
            dbScanList.Add(new DBScanProPlayerGame(new ProPlayerGame(SummonerIds.C9.Sneaky, 3, 3, timeline3)));
            dbScanList.Add(new DBScanProPlayerGame(new ProPlayerGame(SummonerIds.C9.Sneaky, 4, 3, timeline4)));
            dbScanList.Add(new DBScanProPlayerGame(new ProPlayerGame(SummonerIds.C9.Sneaky, 5, 3, timeline5)));
            dbScanList.Add(new DBScanProPlayerGame(new ProPlayerGame(SummonerIds.C9.Sneaky, 6, 3, timeline6)));

            var results = grouper.GetClusters(dbScanList, 3, 2);
            Assert.AreEqual(2, results.Count);
        }