示例#1
0
        public void ManiaAccuracy()
        {
            const int C300  = 37;
            const int C100  = 24;
            const int C50   = 0;
            const int CGeki = 20;
            const int CKatu = 7;
            const int CMiss = 6;

            var accMania = Accuracy.GetAccuracy(C300, C100, C50, CMiss, CGeki, CKatu, PlayMode.Mania);

            Logger.Info($"{accMania:P}");
        }
示例#2
0
        public void OsuAccuracy()
        {
            const int C300  = 2038;
            const int C100  = 100;
            const int C50   = 2;
            const int CGeki = 239;
            const int CKatu = 49;
            const int CMiss = 5;

            var accStd = Accuracy.GetAccuracy(C300, C100, C50, CMiss, CGeki, CKatu, PlayMode.Osu);

            Assert.AreEqual(accStd, 0.9658119658119658);
        }
示例#3
0
        public void CtbAccuracy()
        {
            const int C300  = 3618;
            const int C100  = 28;
            const int C50   = 47;
            const int CGeki = 2768;
            const int CKatu = 1;
            const int CMiss = 2;

            var accCtb = Accuracy.GetAccuracy(C300, C100, C50, CMiss, CGeki, CKatu, PlayMode.Ctb);

            Logger.Info($"{accCtb}");
        }
示例#4
0
        public void TaikoAccuracy()
        {
            const int C300  = 870;
            const int C100  = 88;
            const int C50   = 0;
            const int CGeki = 0;
            const int CKatu = 0;
            const int CMiss = 1;

            var accTaiko = Accuracy.GetAccuracy(C300, C100, C50, CMiss, CGeki, CKatu, PlayMode.Taiko);

            Assert.AreEqual(accTaiko, 0.9530761209593326);
        }
示例#5
0
        public double GetAccuracy(PlayMode mode)
        {
            switch (mode)
            {
            case PlayMode.Osu:
                return(Accuracy.GetAccuracy(Count300Osu, Count100Osu, Count50Osu, CountMissOsu, 0, 0, PlayMode.Osu));

            case PlayMode.Taiko:
                return(Accuracy.GetAccuracy(
                           Count300Taiko, Count100Taiko, Count50Taiko, CountMissTaiko, 0, 0, PlayMode.Osu
                           ));

            case PlayMode.Ctb:
                return(Accuracy.GetAccuracy(Count300Ctb, Count100Ctb, Count50Ctb, CountMissCtb, 0, 0, PlayMode.Osu));
            }

            return(0);
        }
示例#6
0
        private static async Task Main(string[] args)
        {
            const string AWS_ACCESS_KEY_ID     = "AWS_ACCESS_KEY_ID";
            const string AWS_SECRET_ACCESS_KEY = "AWS_SECRET_ACCESS_KEY";

            Console.WriteLine("Hello World!");

            var self = await File.ReadAllBytesAsync("assets\\self.jpg");

            var front = await File.ReadAllBytesAsync("assets\\front.png");

            var back = await File.ReadAllBytesAsync("assets\\back.png");

            var command = new AnalizeDocumentCommand {
                Self = self, Back = back, Front = front
            };

            var region = RegionEndpoint.USEast1;
            var client = new AmazonRekognitionClient(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, region);

            #region Analiza se é documento
            using (var stream = new MemoryStream(command.Back))
            {
                var request = new DetectLabelsRequest {
                    Image = new Image {
                        Bytes = stream
                    }
                };

                var response = await client.DetectLabelsAsync(request);

                var labels = response.Labels;

                foreach (var label in labels)
                {
                    var accuracy = Accuracy.GetAccuracy(label.Confidence);

                    if (DocumentTypes.IsValidDocument(label.Name))
                    {
                        if (accuracy.IsLow)
                        {
                            Console.WriteLine("Não é um documento");
                        }
                        if (accuracy.IsMedium)
                        {
                            Console.WriteLine("Pode ser que seja um documento");
                        }
                        if (accuracy.IsHigh)
                        {
                            Console.WriteLine("É muito provável que seja um documento");
                        }

                        break;
                    }
                }
            }
            #endregion

            #region Compara com a self
            using (var source = new MemoryStream(command.Self))
                using (var target = new MemoryStream(command.Front))
                {
                    var request = new CompareFacesRequest {
                        SourceImage = new Image {
                            Bytes = source
                        }, TargetImage = new Image {
                            Bytes = target
                        }
                    };

                    var response = await client.CompareFacesAsync(request);

                    var faces = response.FaceMatches;

                    if (faces.Count != 1)
                    {
                        Console.WriteLine("Resultado inconsistente");
                    }

                    var accuracy = Accuracy.GetAccuracy(faces.First().Similarity);

                    if (accuracy.IsLow)
                    {
                        Console.WriteLine("Esse documento não da mesma pessoa");
                    }
                    if (accuracy.IsMedium)
                    {
                        Console.WriteLine("Pode ser que este documento seja da mesma pessoa");
                    }
                    if (accuracy.IsHigh)
                    {
                        Console.WriteLine("É muito provável que este documento seja da mesma pessoa");
                    }
                }
            #endregion

            #region Verifica se é do portador válido
            using (var stream = new MemoryStream(command.Back))
            {
                var request = new DetectTextRequest {
                    Image = new Image {
                        Bytes = stream
                    }
                };

                var response = await client.DetectTextAsync(request);

                var texts = response.TextDetections;

                foreach (var text in texts)
                {
                    var accuracy = Accuracy.GetAccuracy(text.Confidence);

                    if ("CPF".Equals(text.DetectedText, StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (accuracy.IsLow)
                        {
                            Console.WriteLine("não contém um número de CPF");
                        }
                        if (accuracy.IsMedium)
                        {
                            Console.WriteLine("Pode ser que contenha um número de CPF");
                        }
                        if (accuracy.IsHigh)
                        {
                            Console.WriteLine("É muito provável que contenha um número de CPF");
                        }

                        break;
                    }
                }
            }
            #endregion

            Console.WriteLine("That's all folks!");
        }
示例#7
0
        public async Task <IActionResult> PostSubmitModular()
        {
            string score  = Request.Form["score"];
            string iv     = Request.Form["iv"];
            string osuver = Request.Form["osuver"];
            string pass   = Request.Form["pass"];

            var(b, scores) = ScoreSubmissionParser.ParseScore(_factory, score, iv, osuver);

            if (scores.UserId == -1)
            {
                return(Ok("error: pass"));
            }

            if (scores.ScoreOwner == null)
            {
                scores.ScoreOwner = Users.GetUser(_factory, scores.UserId);
            }

            if (scores.ScoreOwner == null)
            {
                return(Ok("error: pass"));
            }

            if (!scores.ScoreOwner.IsPassword(pass))
            {
                return(Ok("error: pass"));
            }

            var isRelaxing = (scores.Mods & Mod.Relax) != 0;
            var pr         = _ps.GetPresence(scores.ScoreOwner.Id);

            if (!b || !RankedMods.IsRanked(scores.Mods))
            {
                if (isRelaxing)
                {
                    var rx = LeaderboardRx.GetLeaderboard(_factory, scores.ScoreOwner);
                    rx.IncreasePlaycount(_factory, scores.PlayMode);
                    rx.IncreaseScore(_factory, (ulong)scores.TotalScore, false, scores.PlayMode);
                }
                else
                {
                    var std = LeaderboardStd.GetLeaderboard(_factory, scores.ScoreOwner);
                    std.IncreasePlaycount(_factory, scores.PlayMode);
                    std.IncreaseScore(_factory, (ulong)scores.TotalScore, false, scores.PlayMode);
                }

                await _ev.RunEvent(
                    EventType.BanchoUserStatsRequest,
                    new BanchoUserStatsRequestArgs { userIds = new List <int> {
                                                         scores.ScoreOwner.Id
                                                     }, pr = pr }
                    );

                return(Ok("Thanks for your hard work!"));
            }

            /*
             * switch (scores.PlayMode)
             * {
             *  case PlayMode.Osu:
             *      oppai op = new oppai(BeatmapDownloader.GetBeatmap(scores.FileMd5, _config));
             *      op.SetAcc((int) scores.Count300, (int) scores.Count50, (int) scores.CountMiss);
             *      op.SetCombo(scores.MaxCombo);
             *      op.SetMods(scores.Mods);
             *      op.Calculate();
             *
             *      scores.PeppyPoints = op.GetPP();
             *      Logger.Info("Peppy Points:", scores.PeppyPoints);
             *      break;
             * }
             */

            var ReplayFile = Request.Form.Files.GetFile("score");

            if (!Directory.Exists("data/replays"))
            {
                Directory.CreateDirectory("data/replays");
            }

            await using (var m = new MemoryStream())
            {
                ReplayFile.CopyTo(m);
                m.Position       = 0;
                scores.ReplayMd5 = Hex.ToHex(Crypto.GetMd5(m)) ?? string.Empty;
                if (!string.IsNullOrEmpty(scores.ReplayMd5))
                {
                    await using (var replayFile = System.IO.File.Create($"data/replays/{scores.ReplayMd5}"))
                    {
                        m.Position = 0;
                        m.WriteTo(replayFile);
                        m.Close();
                        replayFile.Close();
                    }
                }
            }

            BeatmapDownloader.GetBeatmap(scores.FileMd5, _config);

            if (isRelaxing)
            {
                scores.Mods -= Mod.Relax;
            }
            scores.PeppyPoints = PerformancePointsProcessor.Compute(scores);
            if (isRelaxing)
            {
                scores.Mods |= Mod.Relax;
            }

            var oldScore = Scores.GetScores(
                _factory,
                scores.FileMd5,
                scores.ScoreOwner,
                scores.PlayMode,
                isRelaxing,
                false,
                false,
                false,
                scores.Mods,
                true
                ).FirstOrDefault();

            var oldStd    = LeaderboardStd.GetLeaderboard(_factory, scores.ScoreOwner);
            var oldStdPos = oldStd.GetPosition(_factory, scores.PlayMode);

            if (oldScore != null && oldScore.TotalScore <= scores.TotalScore)
            {
                using var db = _factory.GetForWrite();
                db.Context.Scores.Remove(oldScore);
                System.IO.File.Delete($"data/replays/{oldScore.ReplayMd5}");

                Scores.InsertScore(_factory, scores);
            }
            else if (oldScore == null)
            {
                Scores.InsertScore(_factory, scores);
            }
            else
            {
                System.IO.File.Delete($"data/replays/{scores.ReplayMd5}");
            }

            if (isRelaxing)
            {
                var rx = LeaderboardRx.GetLeaderboard(_factory, scores.ScoreOwner);
                rx.IncreasePlaycount(_factory, scores.PlayMode);
                rx.IncreaseCount300(_factory, scores.Count300, scores.PlayMode);
                rx.IncreaseCount100(_factory, scores.Count100, scores.PlayMode);
                rx.IncreaseCount50(_factory, scores.Count50, scores.PlayMode);
                rx.IncreaseCountMiss(_factory, scores.CountMiss, scores.PlayMode);
                rx.IncreaseScore(_factory, (ulong)scores.TotalScore, true, scores.PlayMode);
                rx.IncreaseScore(_factory, (ulong)scores.TotalScore, false, scores.PlayMode);

                rx.UpdatePP(_factory, scores.PlayMode);

                pr.LeaderboardRx = rx;
                await _ev.RunEvent(
                    EventType.BanchoUserStatsRequest,
                    new BanchoUserStatsRequestArgs { userIds = new List <int> {
                                                         scores.ScoreOwner.Id
                                                     }, pr = pr }
                    );
            }
            else
            {
                var std = LeaderboardStd.GetLeaderboard(_factory, scores.ScoreOwner);
                std.IncreasePlaycount(_factory, scores.PlayMode);
                std.IncreaseCount300(_factory, scores.Count300, scores.PlayMode);
                std.IncreaseCount100(_factory, scores.Count100, scores.PlayMode);
                std.IncreaseCount50(_factory, scores.Count50, scores.PlayMode);
                std.IncreaseCountMiss(_factory, scores.CountMiss, scores.PlayMode);
                std.IncreaseScore(_factory, (ulong)scores.TotalScore, true, scores.PlayMode);
                std.IncreaseScore(_factory, (ulong)scores.TotalScore, false, scores.PlayMode);

                std.UpdatePP(_factory, scores.PlayMode);
            }

            var newStd    = LeaderboardStd.GetLeaderboard(_factory, scores.ScoreOwner);
            var newStdPos = newStd.GetPosition(_factory, scores.PlayMode);


            var NewScore = Scores.GetScores(
                _factory,
                scores.FileMd5,
                scores.ScoreOwner,
                scores.PlayMode,
                isRelaxing,
                false,
                false,
                false,
                scores.Mods,
                true
                ).FirstOrDefault();

            var cg = new Cheesegull(_config);

            cg.SetBM(scores.FileMd5);

            var sets = cg.GetSets();
            var bm   = sets?[0].ChildrenBeatmaps.First(x => x.FileMD5 == scores.FileMd5) ?? new CheesegullBeatmap();

            double oldAcc;
            double newAcc;

            ulong oldRankedScore;
            ulong newRankedScore;

            double oldPP;
            double newPP;

            switch (scores.PlayMode)
            {
            case PlayMode.Osu:
                oldAcc = Accuracy.GetAccuracy(
                    oldStd.Count300Osu,
                    oldStd.Count100Osu,
                    oldStd.Count50Osu,
                    oldStd.Count300Osu, 0, 0,
                    PlayMode.Osu
                    );

                newAcc = Accuracy.GetAccuracy(
                    newStd.Count300Osu,
                    newStd.Count100Osu,
                    newStd.Count50Osu,
                    newStd.Count300Osu, 0, 0,
                    PlayMode.Osu
                    );

                oldRankedScore = oldStd.RankedScoreOsu;
                newRankedScore = newStd.RankedScoreOsu;

                oldPP = oldStd.PerformancePointsOsu;
                newPP = newStd.PerformancePointsOsu;
                break;

            case PlayMode.Taiko:
                oldAcc = Accuracy.GetAccuracy(
                    oldStd.Count300Taiko,
                    oldStd.Count100Taiko,
                    oldStd.Count50Taiko,
                    oldStd.Count300Taiko, 0, 0,
                    PlayMode.Taiko
                    );

                newAcc = Accuracy.GetAccuracy(
                    newStd.Count300Taiko,
                    newStd.Count100Taiko,
                    newStd.Count50Taiko,
                    newStd.Count300Taiko, 0, 0,
                    PlayMode.Taiko
                    );

                oldRankedScore = oldStd.RankedScoreTaiko;
                newRankedScore = newStd.RankedScoreTaiko;

                oldPP = oldStd.PerformancePointsTaiko;
                newPP = newStd.PerformancePointsTaiko;
                break;

            case PlayMode.Ctb:
                oldAcc = Accuracy.GetAccuracy(
                    oldStd.Count300Ctb,
                    oldStd.Count100Ctb,
                    oldStd.Count50Ctb,
                    oldStd.Count300Ctb, 0, 0,
                    PlayMode.Ctb
                    );

                newAcc = Accuracy.GetAccuracy(
                    newStd.Count300Ctb,
                    newStd.Count100Ctb,
                    newStd.Count50Ctb,
                    newStd.Count300Ctb, 0, 0,
                    PlayMode.Ctb
                    );

                oldRankedScore = oldStd.RankedScoreCtb;
                newRankedScore = newStd.RankedScoreCtb;

                oldPP = oldStd.PerformancePointsCtb;
                newPP = newStd.PerformancePointsCtb;
                break;

            case PlayMode.Mania:
                oldAcc = Accuracy.GetAccuracy(
                    oldStd.Count300Mania,
                    oldStd.Count100Mania,
                    oldStd.Count50Mania,
                    oldStd.Count300Mania, 0, 0,
                    PlayMode.Mania
                    );

                newAcc = Accuracy.GetAccuracy(
                    newStd.Count300Mania,
                    newStd.Count100Mania,
                    newStd.Count50Mania,
                    newStd.Count300Mania, 0, 0,
                    PlayMode.Mania
                    );

                oldRankedScore = oldStd.RankedScoreMania;
                newRankedScore = newStd.RankedScoreMania;

                oldPP = oldStd.PerformancePointsMania;
                newPP = newStd.PerformancePointsMania;
                break;

            default:
                return(Ok(""));
            }

            if (NewScore?.Position == 1 && (oldScore == null || oldScore.TotalScore < NewScore.TotalScore))
            {
                _sora.SendMessage(
                    $"[http://{_config.Server.Hostname}/{scores.ScoreOwner.Id} {scores.ScoreOwner.Username}] " +
                    $"has reached #1 on [https://osu.ppy.sh/b/{bm.BeatmapID} {sets?[0].Title} [{bm.DiffName}]] " +
                    $"using {ModUtil.ToString(NewScore.Mods)} " +
                    $"Good job! +{NewScore.PeppyPoints:F}PP",
                    "#announce",
                    false
                    );
            }

            Logger.Info(
                $"{L_COL.RED}{scores.ScoreOwner.Username}",
                $"{L_COL.PURPLE}( {scores.ScoreOwner.Id} ){L_COL.WHITE}",
                $"has just submitted a Score! he earned {L_COL.BLUE}{NewScore?.PeppyPoints:F}PP",
                $"{L_COL.WHITE}with an Accuracy of {L_COL.RED}{NewScore?.Accuracy * 100:F}",
                $"{L_COL.WHITE}on {L_COL.YELLOW}{sets?[0].Title} [{bm.DiffName}]",
                $"{L_COL.WHITE}using {L_COL.BLUE}{ModUtil.ToString(NewScore?.Mods ?? Mod.None)}"
                );

            var bmChart = new Chart(
                "beatmap",
                "Beatmap Ranking",
                $"https://osu.ppy.sh/b/{bm.BeatmapID}",
                oldScore?.Position ?? 0,
                NewScore?.Position ?? 0,
                oldScore?.MaxCombo ?? 0,
                NewScore?.MaxCombo ?? 0,
                oldScore?.Accuracy * 100 ?? 0,
                NewScore?.Accuracy * 100 ?? 0,
                (ulong)(oldScore?.TotalScore ?? 0),
                (ulong)(NewScore?.TotalScore ?? 0),
                oldScore?.PeppyPoints ?? 0,
                NewScore?.PeppyPoints ?? 0,
                NewScore?.Id ?? 0
                );

            cg.SetBMSet(bm.ParentSetID);

            var overallChart = new Chart(
                "overall",
                "Global Ranking",
                $"https://osu.ppy.sh/u/{scores.ScoreOwner.Id}",
                (int)oldStdPos,
                (int)newStdPos,
                0,
                0,
                oldAcc * 100,
                newAcc * 100,
                oldRankedScore,
                newRankedScore,
                oldPP,
                newPP,
                NewScore?.Id ?? 0,
                AchievementProcessor.ProcessAchievements(
                    _factory, scores.ScoreOwner, scores, bm, cg.GetSets()[0], oldStd, newStd
                    )
                );

            pr.LeaderboardStd = newStd;
            await _ev.RunEvent(
                EventType.BanchoUserStatsRequest,
                new BanchoUserStatsRequestArgs { userIds = new List <int> {
                                                     scores.ScoreOwner.Id
                                                 }, pr = pr }
                );

            return(Ok(
                       $"beatmapId:{bm.BeatmapID}|beatmapSetId:{bm.ParentSetID}|beatmapPlaycount:0|beatmapPasscount:0|approvedDate:\n\n" +
                       bmChart.ToOsuString() + "\n" + overallChart.ToOsuString()
                       ));
        }