Skip to content
Snippets Groups Projects
Commit 21a06be4 authored by Janis Daniel Dähne's avatar Janis Daniel Dähne
Browse files

- fixed result enum issue

parent 5f796da4
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,8 @@ using ClientServer.Models.Users;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace ClientServer.Controllers.Core.Testing.ThirdParty
{
......@@ -26,6 +28,7 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
//TODO fragen submissionId immer > 0 ?
//TODO soll das ergebnis gespichert werden???
//TODO handle exceptions
//TODO vor alle enum namen RESULT_???
public SqlCheckerHelper(YapexDbContext context) : base(context)
{
......@@ -194,7 +197,7 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
: systemSettings.MaxNumberOfTestsWithOneRequest)
.ToList();
//the user as access to the tests (tests are the correct ones) because he/she got a participation for the exercise
//and the tests are attached to the exercise
var tests = await _context.Tests
......@@ -292,10 +295,12 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
return;
}
List<SubmissionRequestAnswerFromBackend> sqlCheckerPreResults =
var sqlCheckerPreResults =
await RequestSubmitTestToSqlChecker(systemSettings, userId, userSolution.MainFile.Content, allTests);
var responseList = new List<TestAnswerFromBackend>();
foreach (var testResult in sqlCheckerPreResults)
{
var test = tests.FirstOrDefault(p => p.Id == testResult.TestId);
......@@ -329,7 +334,6 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
{
//change old result
reInitTestResultFromSubmissionRequest(oldResult, userSolution, testResult);
}
try
......@@ -341,13 +345,32 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
await base.HandleDbError(ex);
return;
}
responseList.Add(new TestAnswerFromBackend()
{
TestId = oldResult.TestId,
ProgramExitCode = oldResult.ProgramExitCode ?? -1,
Passed = oldResult.Passed ?? false,
Protocol = new List<string>() {oldResult.Protocol},
HasCompiled = false,
RunnerVersion = oldResult.RunnerVersion,
CharacterLimitExceeded = oldResult.CharacterLimitExceeded,
CharacterLimitUsed = oldResult.CharacterLimitUsed,
TestResultCode = oldResult.TestResultCode ?? -1,
TestServerCode = -1,
TestServerVersion = oldResult.TestServerVersion,
TestServerMessage = null,
TimeForCompiling = oldResult.TimeForCompiling,
TimeForUserProgram = oldResult.TimeForCompiling,
TimeoutInMsUsed = oldResult.TimeoutInMsUsed,
CompileTimeoutInMsUsed = oldResult.CompileTimeoutInMsUsed,
});
}
await Response.WriteAsync(
Jc.Serialize(new BasicResponseWithData<List<SubmissionRequestAnswerFromBackend>>(ResponseCode.Ok,
Jc.Serialize(new BasicResponseWithData<List<TestAnswerFromBackend>>(ResponseCode.Ok,
"",
sqlCheckerPreResults)));
responseList)));
}
/// <summary>
......@@ -357,10 +380,11 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
/// <param name="userId"></param>
/// <param name="sqlQuery"></param>
/// <param name="allTests"></param>
private async Task<List<SubmissionRequestAnswerFromBackend>> RequestSubmitTestToSqlChecker(SystemSetting systemSettings,
private async Task<List<SubmissionRequestAnswerBackendOnly>> RequestSubmitTestToSqlChecker(
SystemSetting systemSettings,
int userId, string sqlQuery, List<AllTest> allTests)
{
var results = new List<SubmissionRequestAnswerFromBackend>();
var results = new List<SubmissionRequestAnswerBackendOnly>();
foreach (var allTest in allTests)
{
......@@ -420,7 +444,7 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
contentResult = await jsonResponse.Content.ReadAsStringAsync();
SubmissionRequestAnswer answerFromTestServer;
SqlCheckerSubmissionRequestAnswer answerFromTestServer;
tokenSource.Dispose();
......@@ -431,7 +455,7 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
try
{
answerFromTestServer = Jc.Deserialize<SubmissionRequestAnswer>(contentResult);
answerFromTestServer = Jc.Deserialize<SqlCheckerSubmissionRequestAnswer>(contentResult);
}
catch (Exception e)
{
......@@ -440,7 +464,7 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
throw;
}
results.Add(new SubmissionRequestAnswerFromBackend()
results.Add(new SubmissionRequestAnswerBackendOnly()
{
TestId = allTest.Id,
SubmissionId = answerFromTestServer.SubmissionId,
......@@ -453,7 +477,6 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
}
[HttpPost("status")]
public async Task RequestSqlCheckerStatus([FromBody] GetSqlCheckerStatusCommandForBackend command)
{
......@@ -621,10 +644,10 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
$"only 1 submission is supported (for now)")));
return;
}
var firstTestId = command.TestIds.First();
var tests = await _context.Tests
.Include(p => p.TestSettings)
.Include(p => p.TestType)
......@@ -632,8 +655,8 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
p.Id == firstTestId)
.ToListAsync()
;
bool areAllSqlCheckerTests = AreAllThirdPartySqlCheckerTests(tests);
......@@ -645,9 +668,9 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
new BasicResponse(ResponseCode.ServerError, "some tests are not sql checker tests")));
return;
}
//ensure the user gets only results for him/her not from another user...
//do not include solution files here ... it might be too many data to load...
//just find the correct version then start another query to get the solution version + files
......@@ -668,7 +691,7 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
var checkedSubmissionIds = new List<Tuple<int, int>>();
var testResults = new List<TestWithSingleSolutionAsTestResult>();
foreach (var test in tests)
{
//get the old result
......@@ -676,39 +699,63 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
.FirstOrDefault(
p => p.TestId == test.Id
&& p.Solution == userSolution);
if (oldResult == null) continue;
if (IsPendingSqlCheckerSubmission(oldResult) == false || oldResult.ProgramExitCode.HasValue == false) continue;
checkedSubmissionIds.Add(new Tuple<int, int>(oldResult.TestId, oldResult.ProgramExitCode.Value));
testResults.Add(oldResult);
//not double get results...
// if (IsPendingSqlCheckerSubmission(oldResult) == false ||
// oldResult.ProgramExitCode.HasValue == false) continue;
checkedSubmissionIds.Add(new Tuple<int, int>(oldResult.TestId, oldResult.ProgramExitCode ?? -1));
testResults.Add(oldResult);
}
//--- get test test result
var sqlCheckerRresponses = await RequestResultFromSqlChecker(systemSettings, checkedSubmissionIds);
var response = new List<GetSqlCheckerStatusResponseFromBackend>();
//save the result...
foreach (var oldResult in testResults)
{
if (oldResult.ProgramExitCode == null) continue;
var sqlCheckerRresponse = sqlCheckerRresponses.Find(p => p.Item1.TestId == oldResult.TestId);
if (sqlCheckerRresponse.Item1 == null)
{
//TODO error
continue;
}
finishTestResult(oldResult, sqlCheckerRresponse.Item1.SqlCheckerSubmissionInfo);
finishTestResult(oldResult, sqlCheckerRresponse.Item1.submissionInfo);
response.Add(new GetSqlCheckerStatusResponseFromBackend()
{
testResult = new TestAnswerFromBackend()
{
TestId = oldResult.TestId,
ProgramExitCode = oldResult.ProgramExitCode ?? -1,
Passed = oldResult.Passed ?? false,
Protocol = new List<string>() {oldResult.Protocol},
HasCompiled = false,
RunnerVersion = oldResult.RunnerVersion,
CharacterLimitExceeded = oldResult.CharacterLimitExceeded,
CharacterLimitUsed = oldResult.CharacterLimitUsed,
TestResultCode = oldResult.TestResultCode ?? -1,
TestServerCode = -1,
TestServerVersion = oldResult.TestServerVersion,
TestServerMessage = null,
TimeForCompiling = oldResult.TimeForCompiling,
TimeForUserProgram = oldResult.TimeForCompiling,
TimeoutInMsUsed = oldResult.TimeoutInMsUsed,
CompileTimeoutInMsUsed = oldResult.CompileTimeoutInMsUsed,
}
});
}
try
......@@ -722,17 +769,13 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
}
var response = sqlCheckerRresponses.Select(p => p.Item1).ToList();
await Response.WriteAsync(
Jc.Serialize(new BasicResponseWithData<List<GetSqlCheckerStatusResponseFromBackend>>(ResponseCode.Ok, "",
Jc.Serialize(new BasicResponseWithData<List<GetSqlCheckerStatusResponseFromBackend>>(ResponseCode.Ok,
"",
response)));
}
/// <summary>
///
/// </summary>
......@@ -740,14 +783,13 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
/// <param name="userId"></param>
/// <param name="testIdAndSubmissionIds"></param>
/// <returns>[0] null or the info, [1] null or the error message</returns>
private async Task<List<Tuple<GetSqlCheckerStatusResponseFromBackend, string>>> RequestResultFromSqlChecker(SystemSetting systemSettings, List<Tuple<int, int>> testIdAndSubmissionIds)
private async Task<List<Tuple<GetSqlCheckerStatusResponseBackendOnly, string>>> RequestResultFromSqlChecker(
SystemSetting systemSettings, List<Tuple<int, int>> testIdAndSubmissionIds)
{
var results = new List<Tuple<GetSqlCheckerStatusResponseFromBackend, string>>();
var results = new List<Tuple<GetSqlCheckerStatusResponseBackendOnly, string>>();
foreach (var submissionId in testIdAndSubmissionIds)
{
HttpResponseMessage jsonResponse = null;
var tokenSource = new CancellationTokenSource();
......@@ -778,7 +820,7 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
contentResult = await jsonResponse.Content.ReadAsStringAsync();
SubmissionInfo answerFromTestServer;
SqlCheckerSubmissionInfo answerFromTestServer;
tokenSource.Dispose();
......@@ -787,37 +829,35 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
//timeout...
}
try
{
answerFromTestServer = Jc.Deserialize<SubmissionInfo>(contentResult);
}
catch (Exception e)
answerFromTestServer = Jc.Deserialize<SqlCheckerSubmissionInfo>(contentResult);
if (answerFromTestServer == null)
{
//TODO
Console.WriteLine(e);
throw;
//could not deserialize...
throw new NotImplementedException();
}
var response = new GetSqlCheckerStatusResponseFromBackend()
var response = new GetSqlCheckerStatusResponseBackendOnly()
{
TestId = submissionId.Item1,
submissionInfo = answerFromTestServer
SqlCheckerSubmissionInfo = answerFromTestServer
};
results.Add(new Tuple<GetSqlCheckerStatusResponseFromBackend, string>(response, null));
results.Add(new Tuple<GetSqlCheckerStatusResponseBackendOnly, string>(response, null));
}
return results;
}
//---------- helper functions ------------
private bool AreAllThirdPartySqlCheckerTests(List<AllTest> tests)
{
return tests.All(p => p.TestType.InternalName == Constants.IntegrationSqlCheckerTestInternalName);
}
private bool AreAllThirdPartySqlCheckerTests(List<Test> tests)
{
return tests.All(p => p.TestType.InternalName == Constants.IntegrationSqlCheckerTestInternalName);
......@@ -830,7 +870,7 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
private TestWithSingleSolutionAsTestResult createInitialTestResultFromSubmissionRequest(Test test,
Solution userSolution,
SubmissionRequestAnswerFromBackend submissionRequestAnswerFromChecker)
SubmissionRequestAnswerBackendOnly submissionRequestAnswerFromChecker)
{
var initialTestResult = new TestWithSingleSolutionAsTestResult()
{
......@@ -857,7 +897,7 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
private void reInitTestResultFromSubmissionRequest(TestWithSingleSolutionAsTestResult oldTest,
Solution userSolution,
SubmissionRequestAnswerFromBackend submissionRequestAnswerFromChecker)
SubmissionRequestAnswerBackendOnly submissionRequestAnswerFromChecker)
{
oldTest.Passed = null;
oldTest.Protocol = "";
......@@ -875,14 +915,11 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
}
private void finishTestResult(TestWithSingleSolutionAsTestResult oldResult,
SubmissionInfo responseFromSqlChecker)
SqlCheckerSubmissionInfo responseFromSqlChecker)
{
Console.WriteLine(responseFromSqlChecker.Result);
Console.WriteLine(responseFromSqlChecker.Result);
Console.WriteLine(responseFromSqlChecker.Result);
oldResult.Passed = responseFromSqlChecker.Result == SubmissionInfoResult.EQUAL;
oldResult.Passed = (responseFromSqlChecker.Result == SubmissionInfoResult.RESULT_EQUIVALENT ||
responseFromSqlChecker.Result == SubmissionInfoResult.EQUIVALENT);
oldResult.Protocol = Jc.Serialize(responseFromSqlChecker);
oldResult.HasCompiled = true;
oldResult.ProgramExitCode = responseFromSqlChecker.SubmissionId; //already set
......@@ -897,8 +934,6 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
// oldResult.CharacterLimitExceeded = testResult.CharacterLimitExceeded;
// oldResult.CharacterLimitUsed = testResult.CharacterLimitUsed;
}
}
/// <summary>
......@@ -912,12 +947,21 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
}
public class GetSqlCheckerStatusResponseFromBackend
public class GetSqlCheckerStatusResponseBackendOnly
{
public int TestId { get; set; }
public SubmissionInfo submissionInfo { get; set; }
public SqlCheckerSubmissionInfo SqlCheckerSubmissionInfo { get; set; }
}
public class GetSqlCheckerStatusResponseFromBackend
{
/// <summary>
/// the protocol contains SqlCheckerSubmissionInfo
/// </summary>
public TestAnswerFromBackend testResult { get; set; }
// public SqlCheckerSubmissionInfo SqlCheckerSubmissionInfo { get; set; }
}
//see
//https://gitlab.informatik.uni-halle.de/sql/sql-checker/blob/master/webapp/src/main/java/servlets/SubmissionInfoServlet.java
......@@ -966,17 +1010,18 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
}
}
public class SubmissionRequestAnswer
public class SqlCheckerSubmissionRequestAnswer
{
public int SubmissionId { get; set; }
}
public class SubmissionRequestAnswerFromBackend
public class SubmissionRequestAnswerBackendOnly
{
public int TestId { get; set; }
/// <summary>
/// null on the submission id
/// null (on error) or the submission id
/// </summary>
public int? SubmissionId { get; set; }
......@@ -993,7 +1038,7 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
/// see https://gitlab.informatik.uni-halle.de/sql/sql-checker/blob/master/webapp/src/main/java/servlets/SubmissionInfoServlet.java
/// see for data type https://gitlab.informatik.uni-halle.de/sql/sql-checker/blob/master/webapp/src/main/java/helpers/SubmissionInfoDatatype.java
/// </summary>
public class SubmissionInfo
public class SqlCheckerSubmissionInfo
{
public int SubmissionId { get; set; }
public string SubmissionSql { get; set; }
......@@ -1008,6 +1053,8 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
/// <summary>
/// see https://gitlab.informatik.uni-halle.de/sql/sql-checker/blob/master/worker/src/main/java/helpers/OperatorDatatype.java
/// </summary>
// see https://bytefish.de/blog/enums_json_net/
[JsonConverter(typeof(StringEnumConverter))]
public SubmissionInfoResult Result { get; set; }
......@@ -1020,16 +1067,47 @@ namespace ClientServer.Controllers.Core.Testing.ThirdParty
/// <summary>
/// see https://gitlab.informatik.uni-halle.de/sql/sql-checker/blob/master/worker/src/main/java/helpers/OperatorDatatype.java
/// TODO these are not the real values...
/// see https://gitlab.informatik.uni-halle.de/sql/sql-checker/blob/master/worker/src/main/sql/init_problem_db/problem-database.sql > CREATE VIEW result ...
/// NOT the check_result enum !!
/// </summary>
public enum SubmissionInfoResult
{
EQUAL,
NOT_EQUAL,
PARSABLE,
/// <summary>
/// manually_assessed
/// </summary>
EQUIVALENT_BY_CONTROLLER,
/// <summary>
/// manually_assessed
/// </summary>
NOT_EQUIVALENT_BY_CONTROLLER,
/// <summary>
/// syntactically_correct is unknown
/// </summary>
ERROR,
/// <summary>
/// syntactically_correct is false and check_queryresult_checker is null
/// </summary>
NOT_PARSABLE,
/// <summary>
/// syntactically_correct is false and check_queryresult_checker is set
/// </summary>
NOT_EXECUTABLE,
TIMEOUT,
UNKNOWN,
ERROR
/// <summary>
/// result is equivalent by some internal checker
/// </summary>
EQUIVALENT,
/// <summary>
/// result is not equivalent by some internal checker
/// </summary>
NOT_EQUIVALENT,
/// <summary>
/// result is equivalent by some internal checker
/// </summary>
RESULT_EQUIVALENT,
/// <summary>
/// this can happen when we have a timeout or unknown in at least one qrec state
/// </summary>
UNKNOWN
}
}
......@@ -50,7 +50,7 @@ namespace ClientServer.Models.Exercises.Solution
/// <summary>
/// null: not ran yet, the exit code of the user program
///
/// this is the <see cref="SubmissionRequestAnswerFromBackend.SubmissionId"/> if the <see cref="Test.TestType"/> was <see cref="Constants.IntegrationSqlCheckerTestInternalName"/>
/// this is the <see cref="SqlCheckerSubmissionRequestAnswerFromBackend.SubmissionId"/> if the <see cref="Test.TestType"/> was <see cref="Constants.IntegrationSqlCheckerTestInternalName"/>
/// we then use this id to ask the checker for the actual
/// if <see cref="Passed"/> is null and this is an int, then we need to aks the test server (we don't have the result yet)
/// <see cref="SqlCheckerHelper.IsPendingSqlCheckerSubmission"/>
......@@ -67,7 +67,7 @@ namespace ClientServer.Models.Exercises.Solution
/// the conversation protocol between the user program and the test runner
///
/// if the <see cref="Test.TestType"/> was <see cref="Constants.IntegrationSqlCheckerTestInternalName"/>
/// then this is the json serialized <see cref="SubmissionInfo"/>
/// then this is the json serialized <see cref="SqlCheckerSubmissionInfo"/>
///
/// </summary>
[MaxLength(YapexDbContext.TestProtocolMaxStringLength)]
......
......@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Threading;
using ClientServer.Controllers.Core.Testing.ThirdParty;
using ClientServer.Db;
using ClientServer.Helpers;
using ClientServer.Schedulers;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment