public void MineFandangoTicketSalesFuture_Mine() { var test = ConstructTest(); var actual = test.Mine(); Assert.IsNotNull(actual); Assert.IsTrue(actual.Any(), "The list was empty."); var gameEnd = MovieDateUtil.GameSunday(); WriteMovies(actual); }
public void MineFandangoTicketSales_Mine() { var test = ConstructTest(); var actual = test.Mine(); Assert.IsNotNull(actual); Assert.IsTrue(actual.Any(), "The list was empty."); var gameEnd = MovieDateUtil.GameSunday(); WriteMovies(actual.Where(movie => movie.WeekendEnding == gameEnd.AddDays(-2))); WriteMovies(actual.Where(movie => movie.WeekendEnding == gameEnd.AddDays(-1))); WriteMovies(actual.Where(movie => movie.WeekendEnding == gameEnd)); }
public void MineVisualRecreation_Mine_GenerateBoxOfficeValues() { var test = new MineVisualRecreation(); var fmlBO = new MineFantasyMovieLeagueBoxOffice(); var actual = test.Mine(); var fml = fmlBO.Mine(); Assert.IsNotNull(actual); Assert.IsTrue(actual.Any(), "The list was empty."); var toRemove = new List <IMovie>(); foreach (var movie in actual) { var fmlMovie = fml.FirstOrDefault(item => item.Equals(movie) || item.MovieName.EndsWith(movie.MovieName)); if (fmlMovie == null) { // Remove FML movies that are not found (uses Equals() - fuzzy logic) toRemove.Add(movie); } else { movie.MovieName = fmlMovie.MovieName; } } toRemove.ForEach(item => actual.Remove(item)); var weekendEnding = MovieDateUtil.GameSunday(); var tab = "\t"; Logger.WriteLine($"{tab}{tab}{tab}var weekend = new DateTime({weekendEnding.Year}, {weekendEnding.Month}, {weekendEnding.Day});"); Logger.WriteLine($"{tab}{tab}{tab}UrlSource = \"{test.UrlSource}\";"); Logger.WriteLine($"{tab}{tab}{tab}return new List<IMovie>"); Logger.WriteLine($"{tab}{tab}{tab}{tab}{tab}{tab}{{"); foreach (var movie in actual.OrderByDescending(item => item.Cost)) { var dayOfWeek = movie.Day.HasValue ? $", Day = DayOfWeek.{movie.Day.ToString()}" : string.Empty; Logger.WriteLine($"{tab}{tab}{tab}{tab}{tab}{tab}{tab}{tab}new Movie {{ MovieName = \"{movie.MovieName}\", Earnings = {movie.Earnings}m, WeekendEnding = weekend{dayOfWeek} }},"); } Logger.WriteLine($"{tab}{tab}{tab}{tab}{tab}{tab}}};"); }
/// <summary> /// Create all of the movie miners. /// </summary> /// <returns></returns> private List <IMiner> CreateMiners() { var result = new List <IMiner> { new MineFantasyMovieLeagueBoxOffice { IsHidden = true }, new MineMine(this) { Weight = 1 }, new MineToddThatcher(), new MineBoxOfficePro(), new MineBoxOfficeMojo(), //new MineVisualRecreation(), new MineCoupe { IsHidden = true, OkToMine = false }, //new MineCulturedVultures(), new MineBoxOfficeProphet(), new MineBoxOfficeReport(), new MineTheNumbers { IsHidden = true } }; // Grab last weeks results for comparisons. Always put this list last. result.Add(new MineBoxOfficeMojo(MovieDateUtil.LastSunday(MovieDateUtil.GameSunday().AddDays(-1)))); var properties = new Dictionary <string, string>(); var index = 0; foreach (var miner in result) { properties.Add($"miner{index:00}Name", miner.Name); index++; } _telemetryClient.TrackTrace($"Constructed Miners", SeverityLevel.Information, properties); return(result); }
/// <summary> /// Replace the estimates in the FML Miner with the Box Office Mojo estimates. /// </summary> /// <param name="fmlMiner">The FML Miner with estimate data.</param> private void LoadBoxOfficeMojoEstimates(IMiner fmlMiner) { //var gameSunday = MovieDateUtil.LastSunday(); var gameSunday = MovieDateUtil.GameSunday(); var mojoEstimates = new MineBoxOfficeMojo(gameSunday); var mojoMovies = mojoEstimates.Mine(); FilterMinerMovies(mojoEstimates, gameSunday); if (fmlMiner.Movies != null && fmlMiner.Movies.Any() && mojoMovies != null && mojoMovies.Any()) { foreach (var fmlMovie in fmlMiner.Movies) { var found = mojoMovies.FirstOrDefault(item => item.Equals(fmlMovie)); if (found != null && found.WeekendEnding == fmlMovie.WeekendEnding) { fmlMovie.Earnings = found.EarningsBase; // DON'T assign the bonus (if there is one). } } } }
private List <IMovie> FilterMovies() { var fmlMovie = _fmlMiner.Movies.FirstOrDefault(); var endDate = fmlMovie?.WeekendEnding; // Could be a Monday. var startDate = MovieDateUtil.GameSunday().AddDays(-2); // Starts Friday var compoundMovie = _fmlMiner.CompoundMovie; if (compoundMovie != null) { // A compound movie exists (typically FRI, SAT, SUN) foreach (var movie in Miner.Movies) { if (movie.Equals(compoundMovie)) { movie.Day = movie.WeekendEnding.DayOfWeek; } } } // Filter the list (Friday <- Sunday or Monday) // Group the movies by name. var result = Miner.Movies.Where(movie => startDate <= movie.WeekendEnding && movie.WeekendEnding <= endDate) .GroupBy(movie => movie.Name) // Will split out the day too for compound movie. .Select(group => new Movie { MovieName = group.FirstOrDefault()?.MovieName, Day = group.FirstOrDefault()?.Day, Earnings = group.Sum(item => item.Earnings) }) .Cast <IMovie>() .OrderByDescending(movie => movie.Earnings) .ToList(); var gameMovies = _fmlMiner?.Movies; result = result.Where(movie => gameMovies == null || gameMovies.Contains(movie)).ToList(); CompressMovies(result); // Assign the cost, image, and date so the view has this. foreach (var movie in result) { var found = gameMovies.FirstOrDefault(item => item.Equals(movie)); var lastWeek = _mojoMiner?.Movies?.FirstOrDefault(item => item.Equals(movie)); if (found != null) { movie.Cost = found.Cost; movie.ImageUrl = found.ImageUrl; movie.WeekendEnding = endDate ?? DateTime.Now; movie.IsNew = lastWeek == null; if (movie.IsNew) { if (compoundMovie == null) { movie.Earnings = Miner.Movies.Where(movie2 => startDate.AddDays(-1) <= movie2.WeekendEnding && movie2.WeekendEnding <= endDate && movie2.Equals(movie)) .Sum(movie3 => movie3.EarningsBase); } else if (movie.Day == DayOfWeek.Friday) { // Can't use Equals() here since it uses the day comparison if it exists. movie.Earnings += Miner.Movies.Where(movie2 => startDate.AddDays(-1) == movie2.WeekendEnding && movie2.MovieName == movie.MovieName) .Sum(movie3 => movie3.EarningsBase); } } } } return(result); }
public void MovieDateUtil_GameSunday_IsASunday() { var actual = MovieDateUtil.GameSunday(); Assert.AreEqual(DayOfWeek.Sunday, actual.DayOfWeek); }
public void MovieDateUtil_GameSunday_OnMonday_IsASunday() { var actual = MovieDateUtil.GameSunday(new DateTime(2018, 9, 10), true); Assert.AreEqual(DayOfWeek.Sunday, actual.DayOfWeek); }