Example #1
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();
            }
        }
Example #2
0
 private List<DBScanProPlayerGame> GetRegion(List<DBScanProPlayerGame> points, DBScanProPlayerGame p, int eps)
 {
     List<DBScanProPlayerGame> region = new List<DBScanProPlayerGame>();
     for (int i = 0; i < points.Count; i++)
     {
         int dist = DBScanProPlayerGame.Distance(p, points[i]);
         if (dist <= eps) region.Add(points[i]);
     }
     return region;
 }
Example #3
0
 public static int Distance(DBScanProPlayerGame g1, DBScanProPlayerGame g2)
 {
     var comparer = new ItemPurchaseTimelineComparer();
     return comparer.DistanceBetween(g1.Game.ItemPurchaseTimeline, g2.Game.ItemPurchaseTimeline);
 }
Example #4
0
 private bool ExpandCluster(List<DBScanProPlayerGame> points, DBScanProPlayerGame p, int clusterId, int eps, int minPts)
 {
     List<DBScanProPlayerGame> seeds = GetRegion(points, p, eps);
     if (seeds.Count < minPts) // no core point
     {
         p.ClusterId = DBScanProPlayerGame.NOISE;
         return false;
     }
     else // all points in seeds are density reachable from point 'p'
     {
         for (int i = 0; i < seeds.Count; i++) seeds[i].ClusterId = clusterId;
         seeds.Remove(p);
         while (seeds.Count > 0)
         {
             DBScanProPlayerGame currentP = seeds[0];
             List<DBScanProPlayerGame> result = GetRegion(points, currentP, eps);
             if (result.Count >= minPts)
             {
                 for (int i = 0; i < result.Count; i++)
                 {
                     DBScanProPlayerGame resultP = result[i];
                     if (resultP.ClusterId == DBScanProPlayerGame.UNCLASSIFIED || resultP.ClusterId == DBScanProPlayerGame.NOISE)
                     {
                         if (resultP.ClusterId == DBScanProPlayerGame.UNCLASSIFIED) seeds.Add(resultP);
                         resultP.ClusterId = clusterId;
                     }
                 }
             }
             seeds.Remove(currentP);
         }
         return true;
     }
 }