public void TestAddToEndSucceeds() { var timeline = new ItemPurchaseTimeline(); timeline.AddToEnd(new Item(2009, TimeSpan.Zero)); timeline.AddToEnd(new Item(2009, TimeSpan.Zero)); timeline.AddToEnd(new Item(2009, new TimeSpan(10))); Assert.AreEqual(3, timeline.Count); }
public void TestIsArrayIndexable() { var timeline = new ItemPurchaseTimeline(); timeline.AddToEndByItemId(2009, new TimeSpan(10)); timeline.AddToEndByItemId(3087, new TimeSpan(20)); timeline.AddToEndByItemId(3290, new TimeSpan(30)); Assert.AreEqual(3, timeline.Count); Assert.AreEqual(2009, timeline[0].Id); Assert.AreEqual(3087, timeline[1].Id); Assert.AreEqual(3290, timeline[2].Id); }
public void TestCanBeWrittenToDatabase() { var timeline = new ItemPurchaseTimeline(); timeline.AddToEndByItemId(3086, TimeSpan.Zero); timeline.AddToEndByItemId(3087, TimeSpan.FromSeconds(14)); timeline.AddToEndByItemId(3087, TimeSpan.FromSeconds(16)); var context = new GameContext(); var proGame = new ProPlayerGame(); proGame.GameId = 1; proGame.SummonerId = 5; proGame.ItemPurchaseTimeline = timeline; context.Games.Add(proGame); context.SaveChanges(); }
static void Main(string[] args) { try { var client = new RiotClient(Region.NA, new RiotClientSettings { ApiKey = ConfigurationManager.AppSettings["RiotAPIKey"] }); using (var context = new GameContext()) { foreach (var proUnderObservation in SummonerIds.Pros) { Console.WriteLine("Processing pro with summoner Id {0}", proUnderObservation); var matchList = client.GetMatchList(proUnderObservation, seasons: new Season[] { Season.SEASON2015 }, rankedQueues: new RankedQueue[] { RankedQueue.RANKED_SOLO_5x5 }); Console.WriteLine("We have info on {0} games for this pro", matchList.TotalGames); foreach (var game in matchList.Matches) { // some EUW games were causing problems (maybe region transfer?) if (game.PlatformId.Equals("NA1")) { System.Diagnostics.Debug.WriteLine("Processing game id {0}", game.MatchId); var oldItem = context.Games.SingleOrDefault((t) => t.SummonerId == proUnderObservation && t.GameId == game.MatchId); //var oldItem = context.Games.Find(proUnderObservation, game.MatchId); if (oldItem == null) // not in database already { var singleMatch = client.GetMatch(game.MatchId, true); var itemListFromSingleMatch = new ItemPurchaseTimeline(singleMatch, proUnderObservation); var championId = game.Champion; var proPlayerGame = new ProPlayerGame(proUnderObservation, game.MatchId, championId, itemListFromSingleMatch); context.Games.Add(proPlayerGame); context.SaveChanges(); } } } } } } catch(Exception e) { // may not always have a debugger Console.WriteLine(e); throw e; } }
public void TestAdcStartingItemsAreDistanceOfTwoWithoutTimeGrouping() { var timeline1 = new ItemPurchaseTimeline(); var timeline2 = new ItemPurchaseTimeline(); // potion, doran's blade, then trinket timeline1.AddToEndByItemId(2003, TimeSpan.Zero); timeline1.AddToEndByItemId(1055, TimeSpan.Zero); timeline1.AddToEndByItemId(3340, TimeSpan.Zero); // trinket, dblade, then potion timeline2.AddToEndByItemId(3340, TimeSpan.Zero); timeline2.AddToEndByItemId(1055, TimeSpan.Zero); timeline2.AddToEndByItemId(2003, TimeSpan.Zero); var comparer = new ItemPurchaseTimelineComparer(groupItemsByTime: false); Assert.AreEqual(2, comparer.DistanceBetween(timeline1, timeline2)); }
public void TestIfReorderingResultsInWorseDistanceWeDontReorderInMoreSubtleCase() { var timeline1 = new ItemPurchaseTimeline(); var timeline2 = new ItemPurchaseTimeline(); timeline1.AddToEndByItemId(3340, TimeSpan.Zero); timeline1.AddToEndByItemId(2003, TimeSpan.Zero + TimeSpan.FromSeconds(16)); timeline1.AddToEndByItemId(1055, TimeSpan.Zero + TimeSpan.FromSeconds(32)); timeline1.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(48)); timeline2.AddToEndByItemId(3340, TimeSpan.Zero); timeline2.AddToEndByItemId(2003, TimeSpan.Zero); timeline2.AddToEndByItemId(1055, TimeSpan.Zero); timeline2.AddToEndByItemId(3048, TimeSpan.Zero); // reordering would be very bad here, as they were already only a distance of 1 var comparer = new ItemPurchaseTimelineComparer(false); Assert.AreEqual(1, comparer.DistanceBetween(timeline1, timeline2)); }
public void TestAdcStartingItemsAreDistanceOfTwoWithTimeGroupingButPurchasedFarApart() { var timeline1 = new ItemPurchaseTimeline(); var timeline2 = new ItemPurchaseTimeline(); // potion, doran's blade, then trinket timeline1.AddToEndByItemId(2003, TimeSpan.Zero); timeline1.AddToEndByItemId(1055, TimeSpan.Zero + TimeSpan.FromSeconds(16)); timeline1.AddToEndByItemId(3340, TimeSpan.Zero + TimeSpan.FromSeconds(32)); // trinket, dblade, then potion timeline2.AddToEndByItemId(3340, TimeSpan.Zero); timeline2.AddToEndByItemId(1055, TimeSpan.Zero); timeline2.AddToEndByItemId(2003, TimeSpan.Zero); // don't ignore consumables var comparer = new ItemPurchaseTimelineComparer(false); Assert.AreEqual(2, comparer.DistanceBetween(timeline1, timeline2)); }
public void TestSetup() { timeline1 = new ItemPurchaseTimeline(); timeline1.AddToEndByItemId(3340, TimeSpan.Zero); timeline1.AddToEndByItemId(2003, TimeSpan.Zero + TimeSpan.FromSeconds(16)); timeline1.AddToEndByItemId(1055, TimeSpan.Zero + TimeSpan.FromSeconds(32)); timeline1.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(48)); timeline1.AddToEndByItemId(1054, TimeSpan.Zero + TimeSpan.FromSeconds(64)); // timeline 2 will be similar to item 1, but not identical timeline2 = new ItemPurchaseTimeline(); timeline2.AddToEndByItemId(3340, TimeSpan.Zero); timeline2.AddToEndByItemId(2003, TimeSpan.Zero + TimeSpan.FromSeconds(16)); timeline2.AddToEndByItemId(1055, TimeSpan.Zero + TimeSpan.FromSeconds(32)); timeline2.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(48)); timeline2.AddToEndByItemId(2049, TimeSpan.Zero + TimeSpan.FromSeconds(64)); // timeline 3 is the same as game 1 but is longer. it should be included // in their cluster because it is so close (0 distance) to 1 timeline3 = new ItemPurchaseTimeline(); timeline3.AddToEndByItemId(3340, TimeSpan.Zero); timeline3.AddToEndByItemId(2003, TimeSpan.Zero + TimeSpan.FromSeconds(16)); timeline3.AddToEndByItemId(1055, TimeSpan.Zero + TimeSpan.FromSeconds(32)); timeline3.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(48)); timeline3.AddToEndByItemId(1054, TimeSpan.Zero + TimeSpan.FromSeconds(64)); timeline3.AddToEndByItemId(2049, TimeSpan.Zero + TimeSpan.FromSeconds(80)); timeline3.AddToEndByItemId(1037, TimeSpan.Zero + TimeSpan.FromSeconds(96)); timeline3.AddToEndByItemId(1036, TimeSpan.Zero + TimeSpan.FromSeconds(112)); timeline3.AddToEndByItemId(1039, TimeSpan.Zero + TimeSpan.FromSeconds(128)); timeline3.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(144)); // timeline 4 is a new build timeline4 = new ItemPurchaseTimeline(); timeline4.AddToEndByItemId(3041, TimeSpan.Zero); timeline4.AddToEndByItemId(3181, TimeSpan.Zero + TimeSpan.FromSeconds(16)); timeline4.AddToEndByItemId(3042, TimeSpan.Zero + TimeSpan.FromSeconds(32)); timeline4.AddToEndByItemId(3301, TimeSpan.Zero + TimeSpan.FromSeconds(48)); timeline4.AddToEndByItemId(1052, TimeSpan.Zero + TimeSpan.FromSeconds(64)); // timeline 5 is a duplicate of build 4 timeline5 = new ItemPurchaseTimeline(); timeline5.AddToEndByItemId(3041, TimeSpan.Zero); timeline5.AddToEndByItemId(3181, TimeSpan.Zero + TimeSpan.FromSeconds(16)); timeline5.AddToEndByItemId(3042, TimeSpan.Zero + TimeSpan.FromSeconds(32)); timeline5.AddToEndByItemId(3301, TimeSpan.Zero + TimeSpan.FromSeconds(48)); timeline5.AddToEndByItemId(1052, TimeSpan.Zero + TimeSpan.FromSeconds(64)); // timeline 6 is just too different to be in anything and should be noise timeline6 = new ItemPurchaseTimeline(); timeline6.AddToEndByItemId(3041, TimeSpan.Zero); timeline6.AddToEndByItemId(3340, TimeSpan.Zero + TimeSpan.FromSeconds(16)); timeline6.AddToEndByItemId(2003, TimeSpan.Zero + TimeSpan.FromSeconds(32)); timeline6.AddToEndByItemId(1055, TimeSpan.Zero + TimeSpan.FromSeconds(48)); timeline6.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(64)); timeline6.AddToEndByItemId(1054, TimeSpan.Zero + TimeSpan.FromSeconds(80)); timeline6.AddToEndByItemId(2049, TimeSpan.Zero + TimeSpan.FromSeconds(96)); timeline6.AddToEndByItemId(1037, TimeSpan.Zero + TimeSpan.FromSeconds(112)); timeline6.AddToEndByItemId(1036, TimeSpan.Zero + TimeSpan.FromSeconds(128)); timeline6.AddToEndByItemId(1039, TimeSpan.Zero + TimeSpan.FromSeconds(144)); timeline6.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(160)); timeline6.AddToEndByItemId(3181, TimeSpan.Zero + TimeSpan.FromSeconds(176)); timeline6.AddToEndByItemId(3042, TimeSpan.Zero + TimeSpan.FromSeconds(192)); timeline6.AddToEndByItemId(3301, TimeSpan.Zero + TimeSpan.FromSeconds(208)); timeline6.AddToEndByItemId(1052, TimeSpan.Zero + TimeSpan.FromSeconds(224)); }
public void TestItemChangeIsDistanceOfOne() { var timeline1 = new ItemPurchaseTimeline(); var timeline2 = new ItemPurchaseTimeline(); // statikk shiv then biscuit timeline1.AddToEndByItemId(3087, TimeSpan.Zero); timeline1.AddToEndByItemId(2009, TimeSpan.Zero); // statikk shiv then warmogs timeline2.AddToEndByItemId(3087, TimeSpan.Zero); timeline2.AddToEndByItemId(3083, TimeSpan.Zero); var comparer = new ItemPurchaseTimelineComparer(false, false); Assert.AreEqual(1, comparer.DistanceBetween(timeline1, timeline2)); }
public void TestAddToEndExceptionsWithInvalidTime() { var timeline = new ItemPurchaseTimeline(); timeline.AddToEnd(new Item(2009, new TimeSpan(10))); timeline.AddToEnd(new Item(2009, TimeSpan.Zero)); }
public void TestTwoItemBlock() { var timeline = new ItemPurchaseTimeline(); timeline.AddToEndByItemId(3086, TimeSpan.Zero); timeline.AddToEndByItemId(3087, TimeSpan.FromSeconds(14)); timeline.AddToEndByItemId(3087, TimeSpan.FromSeconds(16)); var itemBlocks = timeline.TryToSplitIntoPurchases(15); Assert.AreEqual(2, itemBlocks.Count); Assert.AreEqual(2, itemBlocks[0].Items.Count); Assert.AreEqual("First Purchase", itemBlocks[0].Name); Assert.AreEqual(1, itemBlocks[1].Items.Count); Assert.AreEqual("Next Purchase", itemBlocks[1].Name); }
public void TestToString() { var timeline = new ItemPurchaseTimeline(); timeline.AddToEndByItemId(3086, new TimeSpan(10)); timeline.AddToEndByItemId(3087, new TimeSpan(20)); Assert.AreEqual("Zeal -> Statikk Shiv", timeline.ToString()); }
public void TestOneBigItemBlock() { var timeline = new ItemPurchaseTimeline(); timeline.AddToEndByItemId(3086, new TimeSpan(10)); timeline.AddToEndByItemId(3087, new TimeSpan(20)); timeline.AddToEndByItemId(3087, new TimeSpan(20)); var itemBlocks = timeline.TryToSplitIntoPurchases(15); Assert.AreEqual(1, itemBlocks.Count); Assert.AreEqual("First Purchase", itemBlocks[0].Name); }
public void TestMatchDetailConstructor() { var matchDetails = new MatchDetail(); matchDetails.ParticipantIdentities = new List<MatchParticipantIdentity>(); var identityWeIgnore = new MatchParticipantIdentity(); identityWeIgnore.ParticipantId = 3; identityWeIgnore.Player = new MatchPlayer(); identityWeIgnore.Player.SummonerId = SummonerIds.C9.Sneaky; matchDetails.ParticipantIdentities.Add(identityWeIgnore); var identityWeWant = new MatchParticipantIdentity(); identityWeWant.ParticipantId = 4; identityWeWant.Player = new MatchPlayer(); identityWeWant.Player.SummonerId = SummonerIds.C9.Balls; matchDetails.ParticipantIdentities.Add(identityWeWant); matchDetails.Timeline = new Timeline(); matchDetails.Timeline.Frames = new List<Frame>(); var framesList = matchDetails.Timeline.Frames; var frame = new Frame(); frame.Events = new List<Event>(); var eventWeWant = new Event(); eventWeWant.EventType = EventType.ITEM_PURCHASED; eventWeWant.ParticipantId = 4; eventWeWant.ItemId = 3068; var eventWeIgnore = new Event(); eventWeIgnore.EventType = EventType.ITEM_PURCHASED; eventWeIgnore.ParticipantId = 3; eventWeIgnore.ItemId = 3087; frame.Events.Add(eventWeIgnore); frame.Events.Add(eventWeWant); framesList.Add(frame); var timeline = new ItemPurchaseTimeline(matchDetails, SummonerIds.C9.Balls); Assert.AreEqual(1, timeline.Count); Assert.AreEqual(3068, timeline[0].Id); timeline = new ItemPurchaseTimeline(matchDetails, SummonerIds.C9.Sneaky); Assert.AreEqual(1, timeline.Count); Assert.AreEqual(3087, timeline[0].Id); }
public void TestJsonSerialization() { var timeline = new ItemPurchaseTimeline(); timeline.AddToEndByItemId(3086, TimeSpan.Zero); timeline.AddToEndByItemId(3087, TimeSpan.FromSeconds(14)); timeline.AddToEndByItemId(3087, TimeSpan.FromSeconds(16)); var json = JsonConvert.SerializeObject(timeline); var enumerable = JsonConvert.DeserializeObject<IEnumerable<Item>>(json); var newTimeilne = new ItemPurchaseTimeline(enumerable); Assert.AreEqual(3, newTimeilne.Count); Assert.AreEqual(3086, newTimeilne[0].Id); Assert.AreEqual(3087, newTimeilne[1].Id); Assert.AreEqual(3087, newTimeilne[2].Id); }
public void TestItemPurchaseTimelineSimpleConstructor() { var timeline = new ItemPurchaseTimeline(); Assert.AreEqual(0, timeline.Count); }
/// <summary> /// Constructor that initializes properties with passed in values /// </summary> /// <param name="summonerId"> /// Summoner ID the item timeline corresponds to /// </param> /// <param name="gameId"> /// Game ID the item timeline corresponds to /// </param> /// <param name="itemPurchaseTimeline"> /// The item purchase timeline for the given summoner and game /// </param> public ProPlayerGame(long summonerId, long gameId, long championId, ItemPurchaseTimeline itemPurchaseTimeline) { SummonerId = summonerId; GameId = gameId; ChampionId = championId; ItemPurchaseTimeline = itemPurchaseTimeline; }
public void TestOutOfOrderItemsIsDistanceOfTwo() { var timeline1 = new ItemPurchaseTimeline(); var timeline2 = new ItemPurchaseTimeline(); // statikk shiv then biscuit timeline1.AddToEndByItemId(3087, TimeSpan.Zero); timeline1.AddToEndByItemId(2009, TimeSpan.Zero); // biscuit, then statikk shiv timeline2.AddToEndByItemId(2009, TimeSpan.Zero); timeline2.AddToEndByItemId(3087, TimeSpan.Zero); var comparer = new ItemPurchaseTimelineComparer(false, false); Assert.AreEqual(2, comparer.DistanceBetween(timeline1, timeline2)); }
public void TestVeryLongLongAndDifferentTimelineDoesNotMatchSubTimeline() { var timeline1 = new ItemPurchaseTimeline(); timeline1.AddToEndByItemId(3340, TimeSpan.Zero); timeline1.AddToEndByItemId(2003, TimeSpan.Zero + TimeSpan.FromSeconds(16)); timeline1.AddToEndByItemId(1055, TimeSpan.Zero + TimeSpan.FromSeconds(32)); timeline1.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(48)); timeline1.AddToEndByItemId(1054, TimeSpan.Zero + TimeSpan.FromSeconds(64)); var timeline6 = new ItemPurchaseTimeline(); timeline6.AddToEndByItemId(3041, TimeSpan.Zero); timeline6.AddToEndByItemId(3340, TimeSpan.Zero + TimeSpan.FromSeconds(16)); timeline6.AddToEndByItemId(2003, TimeSpan.Zero + TimeSpan.FromSeconds(32)); timeline6.AddToEndByItemId(1055, TimeSpan.Zero + TimeSpan.FromSeconds(48)); timeline6.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(64)); timeline6.AddToEndByItemId(1054, TimeSpan.Zero + TimeSpan.FromSeconds(80)); timeline6.AddToEndByItemId(2049, TimeSpan.Zero + TimeSpan.FromSeconds(96)); timeline6.AddToEndByItemId(1037, TimeSpan.Zero + TimeSpan.FromSeconds(112)); timeline6.AddToEndByItemId(1036, TimeSpan.Zero + TimeSpan.FromSeconds(128)); timeline6.AddToEndByItemId(1039, TimeSpan.Zero + TimeSpan.FromSeconds(144)); timeline6.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(160)); timeline6.AddToEndByItemId(3181, TimeSpan.Zero + TimeSpan.FromSeconds(176)); timeline6.AddToEndByItemId(3042, TimeSpan.Zero + TimeSpan.FromSeconds(192)); timeline6.AddToEndByItemId(3301, TimeSpan.Zero + TimeSpan.FromSeconds(208)); timeline6.AddToEndByItemId(1052, TimeSpan.Zero + TimeSpan.FromSeconds(224)); var comparer = new ItemPurchaseTimelineComparer(false); Assert.AreEqual(10, comparer.DistanceBetween(timeline1, timeline6)); }
public void TestShortTimelinesWithNoConsumablesAreEqual() { var timeline1 = new ItemPurchaseTimeline(); var timeline2 = new ItemPurchaseTimeline(); // statikk shiv timeline1.AddToEndByItemId(3087, TimeSpan.Zero); timeline2.AddToEndByItemId(3087, TimeSpan.Zero); var comparer = new ItemPurchaseTimelineComparer(); Assert.AreEqual(0, comparer.DistanceBetween(timeline1, timeline2)); }
public void TestShortTimelinesWithConsumablesAreNotEqualWhenConsumablesConsidered() { var timeline1 = new ItemPurchaseTimeline(); var timeline2 = new ItemPurchaseTimeline(); // biscuit timeline1.AddToEndByItemId(2009, TimeSpan.Zero); // statikk shiv timeline1.AddToEndByItemId(3087, TimeSpan.Zero); timeline2.AddToEndByItemId(3087, TimeSpan.Zero); var comparer = new ItemPurchaseTimelineComparer(false); Assert.AreEqual(1, comparer.DistanceBetween(timeline1, timeline2)); }
public void TestShortEqualTimelinesWithDifferentLengthsAreEqual() { var timeline1 = new ItemPurchaseTimeline(); var timeline2 = new ItemPurchaseTimeline(); // statikk shiv timeline1.AddToEndByItemId(3087, TimeSpan.Zero); // biscuit timeline1.AddToEndByItemId(2009, TimeSpan.Zero); timeline2.AddToEndByItemId(3087, TimeSpan.Zero); var comparer = new ItemPurchaseTimelineComparer(false, false); Assert.AreEqual(0, comparer.DistanceBetween(timeline1, timeline2)); }
public void TestIsEnumerableInOrder() { var timeline = new ItemPurchaseTimeline(); timeline.AddToEndByItemId(2009, new TimeSpan(10)); timeline.AddToEndByItemId(3087, new TimeSpan(20)); timeline.AddToEndByItemId(3290, new TimeSpan(30)); Assert.AreEqual(3, timeline.Count); var previousItemId = 0; var previousTimestamp = TimeSpan.Zero; foreach(var item in timeline) { Assert.IsTrue(item.Id > previousItemId); Assert.IsTrue(item.TimeOfPurchase > previousTimestamp); previousItemId = item.Id; previousTimestamp = item.TimeOfPurchase; } }
/// <summary> /// Default constructor. Properties can be set after construction /// </summary> public ProPlayerGame() { ItemPurchaseTimeline = new ItemPurchaseTimeline(); }