Example #1
0
        public async Task <int> AddMetricsAsync(Metrics metrics)
        {
            //var metrics = _mapper.Map<Metrics>(metricsAddDTO);
            await _repository.AddMetricsAsync(metrics);

            return(metrics.Id);
        }
Example #2
0
        public async Task <VerdictName> JudgeSolution(SubmissionWithInput submission)
        {
            int         verdictId;
            bool        isPlagiat;
            string      submissionToken;
            Verdict     verdict     = new Verdict();
            VerdictName verdictName = new VerdictName();

            var task = await _repository.GetAlgorithmTasksForSolveAsync(submission.algorithmTaskId);



            if (submission.stdin != "")
            {
                submissionToken = await createSubmissionWithInputAsync(submission);
            }
            else
            {
                Submission submissionWithNoInput = new Submission();
                submissionWithNoInput.language_id = submission.language_id;
                submissionWithNoInput.source_code = submission.source_code;
                submissionToken = await createSubmissionAsync(submissionWithNoInput);
            }

            JsonCompilationResult result;

            result = await GetResultAsync(submissionToken);

            while (result.stdout == null && result.compile_output == null)
            {
                result = await GetResultAsync(submissionToken);
            }
            if (result.compile_output != null)
            {
                verdictName.Verdict       = Verdicts.CompilationError.ToString();
                verdict.VerdictName       = verdictName.Verdict;
                verdict.AlgorithmTaskName = submission.algorithmTaskName;
                verdict.Solution          = submission.source_code;
                verdict.UserId            = submission.userId;
                verdict.AlgorithmTaskId   = task.Id;
                verdict.IsCopied          = null;
                verdict.SimilarTaskId     = null;
                await _verdictRepository.AddVerdictAsync(verdict);
            }
            else
            {
                JsonAfterCompilationResult submissionResult = await GetFinalResultAsync(submissionToken);

                string time = submissionResult.time.Replace(".", ",");
                submissionResult.time = time;

                verdictName.Verdict = Judge(submissionResult, task, submission);
                var copyResult = await AnalyzeSolutionCopyRatio(submission.source_code, submission.algorithmTaskId);

                if (copyResult.Count >= 1)
                {
                    isPlagiat = true;
                }
                else
                {
                    isPlagiat = false;
                }
                var metrics = _codeAnalyzeService.GetMetricsAsync(submission.source_code);

                // verdict.VerdictName = verdictName.Verdict;
                verdict.Solution          = submission.source_code;
                verdict.AlgorithmTaskName = submission.algorithmTaskName;
                verdict.Time                 = Convert.ToDecimal(time);
                verdict.Memory               = Convert.ToDecimal(submissionResult.memory);
                verdict.LinesOfCode          = metrics.LinesOfCode;
                verdict.CyclomaticComplexity = metrics.CyclomaticComplexity;
                verdict.NumberOfDecision     = metrics.NumberOfDecision;
                verdict.NumberOfAssignment   = metrics.NumberOfAssignment;
                verdict.UserId               = submission.userId;
                verdict.AlgorithmTaskId      = task.Id;

                // nadanie werdyktu plagiat
                if (isPlagiat == true)
                {
                    verdict.IsCopied    = 1;
                    verdict.VerdictName = "Plagiat";
                    var mappedVerdict = _mapper.Map <VerdictAddDTO>(verdict);
                    verdictId = await _verdictService.AddVerdictAsync(mappedVerdict);
                }
                else
                {
                    verdict.IsCopied    = 0;
                    verdict.VerdictName = verdictName.Verdict;
                    var mappedVerdict = _mapper.Map <VerdictAddDTO>(verdict);
                    verdictId = await _verdictService.AddVerdictAsync(mappedVerdict);
                }
                // dodanie informacji o pracach które są podobne do tej pracy
                foreach (var copy in copyResult)
                {
                    copy.VerdictId = verdictId;

                    var mappedCopy = _mapper.Map <CopiedSolution>(copy);
                    await _verdictRepository.AddCopySolutionAsync(mappedCopy);
                }

                // if (verdictName.Verdict == "Accepted" || verdictName.Verdict == "Plagiat")
                // {
                var mappedMetrics = _mapper.Map <Metrics>(metrics);
                mappedMetrics.VerdictId = verdictId;
                await _verdictRepository.AddMetricsAsync(mappedMetrics);

                // }
            }
            verdictName.Verdict = verdict.VerdictName;
            return(verdictName);
        }