Пример #1
0
        public bool SaveProgress(AnalysisTestStudentEntity entity, AnalysisEvaluationType type, EvaluationProgress status, Guid userId, string message = null)
        {
            var progressEntity = entity.EvaluationProgress.Single(x => x.Type == type);

            progressEntity.DateModified = DateTime.UtcNow;
            progressEntity.ModifiedBy   = userId;
            progressEntity.Progress     = status;
            progressEntity.Message      = message;

            var affectedRecords = _context.SaveChanges();

            return(affectedRecords == 1);
        }
Пример #2
0
        private async Task EvaluateAnalysisOutput(IServiceScopeFactory serviceScopeFactory, string jobId, int testId, Guid studentId, Guid userId, QueryExecuteRS actualOutput, AnalysisEvaluationType type, IEnumerable <string> solutionFormat)
        {
            using (var scope = serviceScopeFactory.CreateScope())
            {
                try
                {
                    var analysisRepository = scope.ServiceProvider.GetService <IAnalysisRepository>();
                    var ats = analysisRepository.GetEvaluationData(testId, studentId);

                    #region Record_Start
                    var setStatusSuccess = analysisRepository.SaveProgress(ats, type, EvaluationProgress.Evaluating, userId);
                    if (setStatusSuccess)
                    {
                        await _analysisSignalR.SendMessageAsync(jobId, "analysisEvaluationUpdate", new
                        {
                            id = studentId,
                            type,
                            status = (int)EvaluationProgress.Evaluating
                        });
                    }
                    else
                    {
                        throw new AnalysisEvaluationException(type, testId, studentId, $"Failed to set status to {EvaluationProgress.Evaluating}");
                    }
                    #endregion

                    #region Prepare_Data
                    var providedOutputTableName = "";
                    switch (type)
                    {
                    case AnalysisEvaluationType.QueryOutput:
                        providedOutputTableName = ats.StudentOutputNameOnServer;
                        break;

                    case AnalysisEvaluationType.CorrectOutput:
                        providedOutputTableName = ats.TeacherOutputNameOnServer;
                        break;

                    default:
                        throw new AnalysisEvaluationException(type, testId, studentId, $"Invalid type of test '{type}'");
                    }
                    #endregion

                    #region Evaluate
                    var conn           = _microsoftSQLService.GetReadOnlyAdminConnParams(_sqlServerAdmin.OutputTablesDbName);
                    var providedOutput = _microsoftSQLService.ReadTable("dbo", providedOutputTableName, conn);
                    if (providedOutput.Messages.Any())
                    {
                        throw new AnalysisEvaluationException(type, testId, studentId, $"Failed to read provided output table '{providedOutputTableName}'");
                    }

                    var result = _evaluatorService.EvaluateQueryOutputs(providedOutput, actualOutput, solutionFormat, true);
                    #endregion

                    #region Signal_End_And_Save_Result
                    var saveResultSuccess = analysisRepository.SaveProgress(ats, type, result.PassStatus, userId, result.Message);
                    if (saveResultSuccess)
                    {
                        await _analysisSignalR.SendMessageAsync(jobId, "analysisEvaluationUpdate", new
                        {
                            id = studentId,
                            type,
                            status = (int)(result.Pass ? EvaluationProgress.Passed : EvaluationProgress.Failed)
                        });
                    }

                    if (!saveResultSuccess)
                    {
                        throw new AnalysisEvaluationException(type, testId, studentId, "Failed to save evaluation result");
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    var logRepo = scope.ServiceProvider.GetService <ILogRepository>();
                    logRepo.Log(ex);
                }
            }
        }
 public AnalysisEvaluationException(AnalysisEvaluationType type, int testId, Guid studentId, string message) : base($"TestId:'{testId}', StudentId:'{studentId}', Type: '{type}'. Analysis Test Evaluation Error: '{message}'")
 {
 }
Пример #4
0
 public static string AnalysisTestEvaluation(Guid studentId, int testId, AnalysisEvaluationType type)
 {
     return($"ATE_{testId}_{studentId}");
 }