예제 #1
0
 public static StatsModel Aggregate(Save savegame)
 {
     var stats = new SaveStats(savegame);
     var regiments = stats.WorldRegiments();
     var ships = stats.WorldShips();
     return new StatsModel()
     {
         Player = savegame.Player,
         Players = string.Join(", ", 
             (savegame.Countries ?? Enumerable.Empty<Country>()).Where(x =>
             x.WasPlayer.GetValueOrDefault()).Select(x => x.Abbreviation)),
         PlayerCountries = stats.PlayerStats(),
         Date = savegame.Date,
         Manpower = stats.WorldManpower(),
         PotentialManpower = stats.MaxWorldManpower(),
         LeaderReport = stats.LeaderReport(),
         BiggestNavalWars = stats.NavalWarReport().Take(10),
         BiggestLandWars = stats.LandWarReport().Take(10),
         BiggestLandBattles = stats.LandBattleReport().Take(10),
         BiggestNavalBattles = stats.NavalBattleReport().Take(10),
         BiggestRivalries = stats.CommanderRivalries().Take(10),
         CountryMilitaryStats = stats.CountryKillsAndLosses().Take(10),
         LedgerCorrelations = stats.LedgerCorrelations(),
         ScoreStats = stats.ScoreRankings().Where(x => x.rank <= 10 || stats.IsPlayer(x.name)),
         Debt = stats.CountryDebts().Take(10),
         TradePower = stats.CountryTradeReport().Take(10),
         RegimentCount = regiments.Item1,
         RegimentSum = regiments.Item2,
         ShipCount = ships.Item1,
         ShipSum = ships.Item2
     };
 }
예제 #2
0
        public StatsModule(ITemplate tmpl, IIdGenerator idgen, SavegameStorage storage)
        {
            Post["/games"] = _ =>
            {
                // Get the temporary location of the file on the server
                var file = Request.Headers["X-FILE"].FirstOrDefault();

                // Get the extension of the file when it was uploaded as the
                // temporary file doesn't have an extension
                var extension = Request.Headers["X-FILE-EXTENSION"].FirstOrDefault();
                if (file == null)
                    throw new ArgumentException("File can't be null");
                if (extension == null)
                    throw new ArgumentException("File extension can't be null");

                Save savegame;
                using (var stream = getStream(file, extension))
                using (parsingTimer.NewContext())
                    savegame = new Save(stream);

                // Turn the savegame into html and return the url for it
                var stats = statsTimer.Time(() => Aggregate(savegame));
                string contents = templateTimer.Time(() => tmpl.Render(stats));
                string id = idgen.NextId();
                return storage.Store(contents, id);
            };
        }
예제 #3
0
        public void TemplateRendersSuccessfully()
        {
#if !__MonoCS__
            var a = new TradeStats.PowerStats("a", 1, 1, 1, 1, 1, 1);
#endif

            var tmpl = new Templater("template.html");
            var save = new Save();
            save.Player = "MEE";
            string contents = tmpl.Render(StatsModule.Aggregate(save));
            StringAssert.Contains("MEE", contents);
        }