public async Task EvaluateAsync(IProgress <int> progress = null) { ClearEvaluationState(); await CacheInfosAsync(); AssignmentInfo.StudentNameIdPairs = _csvManager.LoadStudentInfosFromCsv(AssignmentInfo.StudentsCsvFile); await CreateEvaluationContextsAsync(); var assignmentInfoFromSavefile = await _jsonManager.LoadAsync <AssignmentInfo>(AssignmentInfo.SaveFilePath, false); if (assignmentInfoFromSavefile == null) { await EvaluateInternalAsync(progress); await SaveAsJsonAsync(); await ExportCsvAsync(); } else { var evaluationContext = AssignmentInfo.EvaluationContexts; //This overrides existing evaluationContext. AssignmentInfo = assignmentInfoFromSavefile; AssignmentInfo.EvaluationContexts = evaluationContext; progress.Report(100); } }
private void InitializeContext() { _assignmentInfo = _evaluationManager.AssignmentInfo; Students = _assignmentInfo.Students; StudentCount = Students.Count; CompletedStudentNum = Students.Where(x => x.IsEvaluationCompleted).Count(); CurrentStudentIndex = 0; }
public MainViewModel(IEvaluationManager evaluationManager, IRegionManager regionManager, IDialogService dialogService) { _assignmentInfo = evaluationManager.AssignmentInfo; _evaluationManager = evaluationManager; _regionManager = regionManager; _dialogService = dialogService; SelectLabFolderCommand = new DelegateCommand(SelectLabFolder); SelectStudentFile = new DelegateCommand(SelectStudentListFile); StartEvaluationCommand = new DelegateCommand(StartEvaluation, CanStartEvaluation); LoadLastAssignmentInfoCommand = new DelegateCommand(LoadLastAssignmentInfo); ConfigureProblemIdsCommand = new DelegateCommand(ConfigureProblemIds); }
public static bool IsAssignment(string line, out AssignmentInfo assignment) { assignment = null; string[] split = line.Split(new[] { ' ' }, 2); string[] type_name = split[0].Trim().Split(); AssignmentInfo i = new AssignmentInfo(); if (!IsType(type_name[0], out Type t)) { return(false); } i.Type = t; i.VariableName = type_name[1]; i.Value = split[1].TrimEnd(';'); assignment = i; return(true); }
/// <summary> /// A readonly field or property may be re-assigned in constructors. /// This method finds all assignments of the field/property. /// </summary> /// <param name="memberSymbol">The field/property to search for</param> /// <param name="initializer">The initialization with the declaration</param> /// <returns>An immutable list of assignments</returns> private IEnumerable <AssignmentInfo> GetAssignments( ISymbol memberSymbol, ExpressionSyntax initializer ) { // Retrieve a list of assignment expressions from any constructors // within the class var assignmentExpressions = (memberSymbol.ContainingSymbol as INamedTypeSymbol) ! .Constructors .Where(constructorSymbol => !constructorSymbol.IsImplicitlyDeclared) .Where(constructorSymbol => constructorSymbol.IsStatic == memberSymbol.IsStatic) .Select(constructorSymbol => constructorSymbol.DeclaringSyntaxReferences.Single()) .Select(sr => sr.GetSyntax()) .SelectMany(constructorSyntax => constructorSyntax.DescendantNodes()) .OfType <AssignmentExpressionSyntax>() .Where(assignmentSyntax => IsAnAssignmentTo(assignmentSyntax, memberSymbol)) .Select(assignmentSyntax => assignmentSyntax.Right) .Select(expr => AssignmentInfo.Create( model: m_compilation.GetSemanticModel(expr.SyntaxTree), isInitializer: false, expression: expr )); if (initializer != null) { assignmentExpressions = assignmentExpressions.Append( AssignmentInfo.Create( model: m_compilation.GetSemanticModel(initializer.SyntaxTree), isInitializer: true, expression: initializer ) ); } return(assignmentExpressions); }
/// <summary> /// For a field/property assignment, figure out what needs to be checked for it. /// </summary> /// <param name="assignment">The assignment syntax for the field/property (possibly null)</param> /// <param name="query">The query to do (if the return value is AssignmentQueryKind.ImmutabilityQuery.)</param> /// <param name="diagnostic">A diagnostic to report (if the return value is AssignmentQueryKind.Hopeless.)</param> /// <returns>The details about what to check for this assignment</returns> private AssignmentQueryKind GetQueryForAssignment( AssignmentInfo assignment, out ImmutabilityQuery query, out Diagnostic diagnostic ) { // When we have an assignment we use it to narrow our check, e.g. // // private readonly object m_lock = new object(); // // is safe even though object (the type of the field) in general is not. query = default; diagnostic = null; // Easy cases switch (assignment.Expression.Kind()) { case SyntaxKind.NullLiteralExpression: // Sometimes people explicitly (but needlessly) assign null in // an initializer... this is safe. return(AssignmentQueryKind.NothingToCheck); case SyntaxKind.SimpleLambdaExpression: case SyntaxKind.ParenthesizedLambdaExpression: if (assignment.IsInitializer) { // Lambda initializers for readonly members are safe // because they can only close over other members, // which will be checked independently, or static // members of another class, which are also analyzed. return(AssignmentQueryKind.NothingToCheck); } // But for assignments inside a constructor we're in more // trouble. They could capture arbitrary state from their // lexical scope. // static functions can't capture state. if (assignment.Expression.IsStaticFunction()) { return(AssignmentQueryKind.NothingToCheck); } // In general we must panic. diagnostic = Diagnostic.Create( Diagnostics.AnonymousFunctionsMayCaptureMutability, assignment.Expression.GetLocation() ); return(AssignmentQueryKind.Hopeless); case SyntaxKind.InvocationExpression: // Some methods are known to have return values that are // immutable (such as Enumerable.Empty()). // These should be considered immutable by the Analyzer. SemanticModel semanticModel = m_compilation.GetSemanticModel(assignment.Expression.SyntaxTree); if (semanticModel .GetSymbolInfo(assignment.Expression) .Symbol is not IMethodSymbol methodSymbol ) { break; } if (m_context.IsReturnValueKnownToBeImmutable(methodSymbol)) { return(AssignmentQueryKind.NothingToCheck); } break; } // If nothing above was caught, then fallback to querying. if (assignment.Expression is BaseObjectCreationExpressionSyntax _) { // When we have a new T() we don't need to worry about the value // being anything other than an instance of T. query = new ImmutabilityQuery( ImmutableTypeKind.Instance, type: assignment.AssignedType ); } else { // In general we need to handle subtypes. query = new ImmutabilityQuery( ImmutableTypeKind.Total, type: assignment.AssignedType ); } return(AssignmentQueryKind.ImmutabilityQuery); }
//TODO : Refactor this class public LabScanner(AssignmentInfo assignmentInfo, PythonExecuter pythonExecuter) { _assignmentInfo = assignmentInfo; _pythonExecuter = pythonExecuter; }
public async Task ExportCsvAsync(AssignmentInfo assignmentInfo) { StringBuilder builder = new StringBuilder(); builder.AppendLine(CreateHeader(assignmentInfo.EvaluationContexts.Values)); double maxScore = 0; foreach (var context in assignmentInfo.EvaluationContexts.Values) { maxScore += context.MaxScore; } foreach (var student in assignmentInfo.Students) { List <string> contents = new List <string>(); if (student.Name.Contains(",")) { contents.Add($"\"{student.Name}\""); } else { contents.Add(student.Name); } contents.Add(student.Id.ToString()); //TODO : Optimize this. contents.Add(student.NormalizeScore(assignmentInfo.EvaluationContexts.Count).ToString()); string feedback = ""; var evaluationContexts = assignmentInfo.EvaluationContexts; foreach (var problem in student.Problems) { contents.Add(problem.NormalizedScore.ToString()); for (int i = 0; i < evaluationContexts[problem.Id].TestCaseInputs.Count; i++) { if (problem.TestCases.Count == 0) { contents.Add("Not Submitted"); } else { contents.Add(problem.TestCases[i].IsPassed.ToString()); } } if (!string.IsNullOrWhiteSpace(problem.Feedback)) { feedback += $"p{problem.Id}-{problem.Feedback} "; } contents.Add($"\"{problem.Feedback}\""); } contents.Add($"\"{feedback}\""); builder.AppendLine(string.Join(',', contents.ToArray(), 0, contents.Count)); } string csvPath = Path.Combine(assignmentInfo.LabFolderPath, $"{assignmentInfo.SavefileName}.csv"); await File.WriteAllTextAsync(csvPath, builder.ToString()); }