예제 #1
0
        public async Task Save(MMgameNG game)
        {
            // /**
            foreach (var pl in game.GetPlayers())
            {
                if (pl.Name.StartsWith("Random") || pl.Name.StartsWith("Dummy"))
                {
                    continue;
                }
                var dbpl = _db.MMdbPlayers.Where(x => x.Name == pl.Name).FirstOrDefault();
                if (dbpl != null)
                {
                    var dbrat = _db.MMdbRatings.Where(x => x.MMdbPlayerId == dbpl.MMdbPlayerId && x.Lobby == game.Lobby).FirstOrDefault();
                    if (dbrat == null)
                    {
                        dbrat = new MMdbRating();
                    }
                    var rat = pl.Rating[game.Lobby];
                    dbrat.EXP          = rat.EXP;
                    dbrat.Games        = rat.Games;
                    dbrat.Lobby        = game.Lobby;
                    dbrat.MU           = rat.MU;
                    dbrat.SIGMA        = rat.SIGMA;
                    dbrat.MMdbPlayerId = dbpl.MMdbPlayerId;
                    dbrat.MMdbPlayer   = dbpl;

                    if (dbrat.MMdbRatingId == null)
                    {
                        dbpl.MMdbRatings.Add(dbrat);
                    }
                    //_db.MMdbRatings.Add(dbrat);
                    else
                    {
                        _db.MMdbRatings.Update(dbrat);
                    }
                }
            }
            await _db.SaveChangesAsync();

            // **/
            string output = Program.workdir + "/games/" + game.ID + "_report.json";

            if (!File.Exists(output))
            {
                using (FileStream fs = File.Create(output))
                {
                    await JsonSerializer.SerializeAsync(fs, game);
                }
            }
        }
예제 #2
0
 public async Task SaveRace(MMgameNG game)
 {
     // /**
     using (var _db = new MMdb(_mmdb))
     {
         foreach (var pl in game.GetPlayers())
         {
             var dbpl = _db.MMdbRaces.Where(x => x.Name == pl.Name).FirstOrDefault();
             if (dbpl != null)
             {
                 foreach (var rat in pl.Rating[game.Lobby].Where(x => x.Db == false).OrderBy(o => o.Games).ToArray())
                 {
                     MMdbRaceRating dbrat;
                     dbrat            = new MMdbRaceRating();
                     dbrat.EXP        = rat.EXP;
                     dbrat.Games      = rat.Games;
                     dbrat.Lobby      = game.Lobby;
                     dbrat.MU         = rat.MU;
                     dbrat.SIGMA      = rat.SIGMA;
                     dbrat.MMdbRaceId = dbpl.MMdbRaceId;
                     dbrat.MMdbRace   = dbpl;
                     dbrat.Time       = rat.Time;
                     rat.Db           = true;
                     _db.MMdbRaceRatings.Add(dbrat);
                     //dbpl.MMdbRaceRatings.Add(dbrat);
                 }
             }
         }
         await _db.SaveChangesAsync();
     }
     // **/
 }
예제 #3
0
        public async Task Save()
        {
            // /**
            List <MMdbPlayer> temp = new List <MMdbPlayer>();

            using (var db = new MMdb(_mmdb))
            {
                foreach (var conf in MMplayers.Values.Where(x => x.DBId == 0))
                {
                    MMdbPlayer dbpl = new MMdbPlayer(conf);
                    db.MMdbPlayers.Add(dbpl);
                    temp.Add(dbpl);
                }

                foreach (var conf in MMplayers.Values.Where(x => x.DBupdate == true))
                {
                    MMdbPlayer pl = new MMdbPlayer(conf);
                    db.MMdbPlayers.Update(pl);
                }


                List <MMdbRace> race_temp = new List <MMdbRace>();

                /**
                 * foreach (var ent in MMraces.Values)
                 * {
                 *  MMdbRace cmdr = new MMdbRace(ent);
                 *  db.MMdbRaces.Add(cmdr);
                 *  race_temp.Add(cmdr);
                 * }
                 **/
                await db.SaveChangesAsync();

                foreach (var ent in temp)
                {
                    MMplayerNG pl = MMplayers.Values.Where(x => x.Name == ent.Name).FirstOrDefault();
                    pl.DBId = ent.MMdbPlayerId;
                }

                foreach (var ent in race_temp)
                {
                    MMplayerNG pl = MMraces.Values.Where(x => x.Name == ent.Name).FirstOrDefault();
                    pl.DBId = ent.MMdbRaceId;
                }
            }
            // **/
        }
예제 #4
0
파일: StartUp.cs 프로젝트: Mnuzz/dsmm_web
        public async Task Save(MMgameNG game)
        {
            // /**
            using (var _db = new MMdb(_mmdb))
            {
                foreach (var pl in game.GetPlayers())
                {
                    if (pl.Name.StartsWith("Random") || pl.Name.StartsWith("Dummy"))
                    {
                        continue;
                    }
                    var dbpl = _db.MMdbPlayers.Where(x => x.Name == pl.Name).FirstOrDefault();
                    if (dbpl != null)
                    {
                        var dbrat = _db.MMdbRatings.Where(x => x.MMdbPlayerId == dbpl.MMdbPlayerId && x.Lobby == game.Lobby).FirstOrDefault();
                        if (dbrat == null)
                        {
                            dbrat = new MMdbRating();
                        }
                        var rat = pl.Rating[game.Lobby];
                        dbrat.EXP          = rat.EXP;
                        dbrat.Games        = rat.Games;
                        dbrat.Lobby        = game.Lobby;
                        dbrat.MU           = rat.MU;
                        dbrat.SIGMA        = rat.SIGMA;
                        dbrat.MMdbPlayerId = dbpl.MMdbPlayerId;
                        dbrat.MMdbPlayer   = dbpl;

                        if (dbrat.MMdbRatingId == null)
                        {
                            dbpl.MMdbRatings.Add(dbrat);
                        }
                        //_db.MMdbRatings.Add(dbrat);
                        else
                        {
                            _db.MMdbRatings.Update(dbrat);
                        }
                    }
                }
                await _db.SaveChangesAsync();
            }
            // **/
        }