Exemple #1
0
        public ActionResult <int> ReloadCache()
        {
            int gameResultCount = 0;

            var games = _context.Game.ToList();

            foreach (Game game in games)
            {
                var gameResults = _context.GameResult.Where(x => x.game_id == game.game_id).ToList();
                foreach (GameResult gameResult in gameResults)
                {
                    //Console.WriteLine("cache loading game result for game_id : " + game.game_id);
                    RedisUtil.AddGameResultToRedis(gameResult);
                    gameResultCount++;
                }
            }
            return(gameResultCount);
        }
        public async Task <IActionResult> ReloadCache()
        {
            int gameResultCount = 0;

            var games = await _context.Game.Where(x => x.share_yn == "Y").ToListAsync();

            foreach (Game game in games)
            {
                var gameResults = await _context.GameResult.Where(x => x.game_id == game.game_id).ToListAsync();

                foreach (GameResult gameResult in gameResults)
                {
                    Console.WriteLine("cache loading game result for game_id : " + game.game_id);
                    RedisUtil.AddGameResultToRedis(gameResult);
                    gameResultCount++;
                }
            }
            return(Ok(gameResultCount));
        }
Exemple #3
0
        public async Task <IActionResult> Put([FromBody] StageLogPutDTO dto)
        {
            Console.WriteLine("stagelogs PUT entered.");

            var stageLog = _context.StageLog.Where(x => x.game_id == dto.game_id && x.stage_id == dto.stage_id).FirstOrDefault();

            if (stageLog == null)
            {
                return(NotFound("StageLog not found."));
            }

            stageLog.objects_score = dto.objects_score;
            stageLog.time_score    = dto.time_score;
            stageLog.clear_score   = dto.clear_score;
            stageLog.stage_score   = dto.stage_score;
            stageLog.total_score   = dto.total_score;
            stageLog.completed_yn  = dto.completed_yn;
            stageLog.end_date      = DateTime.Now;

            var value = _context.StageLog.Update(stageLog);
            await _context.SaveChangesAsync();

            int playtime = (int)(stageLog.end_date - stageLog.start_date)?.TotalSeconds;

            var gameResult = _context.GameResult.Where(x => x.game_id == dto.game_id).FirstOrDefault();

            if (gameResult == null)
            {
                return(NotFound("GameResult not found."));
            }

            gameResult.total_score         += dto.total_score;
            gameResult.total_found_objects += dto.found_objects;
            gameResult.total_playtime      += playtime;
            _context.GameResult.Update(gameResult);
            await _context.SaveChangesAsync();

            RedisUtil.AddGameResultToRedis(gameResult);

            return(Ok(dto.game_id));
        }
        public async Task <IActionResult> CalcGameResult(int game_id)
        {
            string bucketName = "reinvent-gottalent";

            var stageLogs = await _context.StageLog.Where(x => x.game_id == game_id).ToListAsync();

            double        totalScore   = 0.0f;
            string        genderResult = "";
            string        gradeResult  = "";
            List <string> signedURLs   = new List <string>();
            int           ageResult    = 0;

            foreach (var stageLog in stageLogs)
            {
                if (stageLog.action_type == "Profile")
                {
                    genderResult = stageLog.gender;
                    ageResult    = stageLog.age;
                }
                else
                {
                    totalScore += stageLog.score;
                    signedURLs.Add(S3Util.GetPresignedURL(this.S3Client, bucketName, stageLog.file_loc));
                }
            }

            // TODO : need to use Cache service for judgement
            if (totalScore < 160)
            {
                gradeResult = "Extra";
            }
            else if (160 <= totalScore && totalScore < 190)
            {
                gradeResult = "Supporting";
            }
            else
            {
                gradeResult = "Leading";
            }

            // casting randomly
            int    randomRecord  = new Random().Next() % _context.Cast.Where(x => x.gender == genderResult && x.grade == gradeResult).Count();;
            var    castResult    = _context.Cast.Where(x => x.gender == genderResult && x.grade == gradeResult).Skip(randomRecord).Take(1).First();
            string resultPageUrl = "TBD";

            // Database update
            GameResult newGameResult = new GameResult {
                game_id         = game_id,
                result_page_url = resultPageUrl,
                total_score     = totalScore,
                total_rank      = 0,
                cast_result     = castResult.cast_id,
                grade_result    = gradeResult,
                gender_result   = genderResult,
                age_result      = ageResult
            };

            Game game = await _context.Game.Where(x => x.game_id == game_id).FirstOrDefaultAsync();

            game.end_date = DateTime.Now;
            game.share_yn = "Y";

            var value = _context.GameResult.Add(newGameResult);
            await _context.SaveChangesAsync();

            RedisUtil.AddGameResultToRedis(newGameResult);
            newGameResult.total_rank = RedisUtil.GetGameRanking(newGameResult.game_id) + 1;

            return(Ok(new { newGameResult, castResult.actor, castResult.title, signedURLs }));
        }