new public Cell CellAt(int sheet, int row, int col)
        {
            Spreadsheet spreadsheet = null;
            Row         _row        = null;
            Cell        cell        = null;

            if (this.ContainsKey(sheet))
            {
                spreadsheet = this [sheet];
            }
            else
            {
                spreadsheet = this [sheet] = new Spreadsheet(sheet);
            }

            if (spreadsheet.ContainsKey(row))
            {
                _row = spreadsheet [row];
            }
            else
            {
                _row = spreadsheet [row] = new Row();
            }

            if (_row.ContainsKey(col))
            {
                cell = _row [col];
            }
            else
            {
                cell = _row [col] = new Cell();
            }

            return(cell);
        }
Esempio n. 2
0
    private static IEnumerator GradeSubmission(string studentName, string generator, string assignmentPath, TextWriter results, Spreadsheet grades, string studentId, string scoreColumnName)
    {
        var count    = 0;
        var passed   = 0;
        var errors   = new StringBuilder();
        var ontology = new Ontology(studentName, generator);

        try
        {
            var testLoadErrors = ontology.Parser.LoadDefinitions(Combine(assignmentPath, "tests.gen"), false);

            count = testLoadErrors.Count;
            foreach (var e in testLoadErrors)
            {
                errors.Append($"{e.Message}; ");
            }
        }
        catch (Exception e)
        {
            results.WriteLine($"{studentName},0,\"{e.Message.Replace("\"","\"\"")}\"");
        }

        // ReSharper disable once UnusedVariable
        foreach (var(test, success, example) in ontology.TestResults())
        {
            if (success)
            {
                passed++;
            }
            else
            {
                errors.Append(test.FailMessage);
                errors.Append("; ");
            }

            count++;
            Driver.SetOutputWindow($"{studentName}: {count} tests, {passed} passed; {100*passed/count}%");
            yield return(null);
        }

        var score = (count > 0)?(100 * passed) / count : 0;

        results.WriteLine($"{studentName},{score},{errors}");
        if (!grades.ContainsKey(studentId))
        {
            Debug.Log($"Student does not appear in spreadsheet: {studentName} {studentId}");
        }
        else
        {
            grades[studentId, scoreColumnName] = score;
        }
        Debug.Log($"{studentName}: {score}% passed");
        Driver.SetOutputWindow($"{studentName}: {score}% passed");
    }
        public void Process(Spreadsheet spreadsheet, Cell cell)
        {
            if (HasPredifinedValue(cell))
            {
                cell.Expression.IsFetched = true;
                cell.Value = double.Parse(cell.Expression.Content);
                return;
            }

            var matches = Regex.Matches(cell.Expression.Content, @"[A-Z]\d+");

            foreach (var match in matches)
            {
                var cellKey = match.ToString();
                if (!spreadsheet.ContainsKey(cellKey))
                {
                    cell.Expression.Content = Regex.Replace(cell.Expression.Content, cellKey, "0");
                    return;
                }

                var replacer = spreadsheet[cellKey];

                if (replacer == cell)
                {
                    cell.Value = 0;
                    cell.Expression.Content   = "0";
                    cell.Expression.IsFetched = true;
                    return;
                }

                if (replacer.Expression.IsFetched)
                {
                    cell.Expression.Content = Regex.Replace(cell.Expression.Content, cellKey, replacer.Expression.Content);
                }
                else
                {
                    Process(spreadsheet, replacer);
                    cell.Expression.Content = Regex.Replace(cell.Expression.Content, cellKey, replacer.Expression.Content);
                }
            }
        }