diff options
| author | Szymon Szukalski <szymon@skas.io> | 2024-07-26 11:23:52 +1000 |
|---|---|---|
| committer | Szymon Szukalski <szymon@skas.io> | 2024-07-26 11:23:52 +1000 |
| commit | 40fd0f10181909719f2541d62965dbcbc8e91078 (patch) | |
| tree | 2d44e9069370dd3565cc5ecc15110d497047fa99 /src/main/java/com/stileeducation | |
| parent | 198bebb7afca165beeab289da3a0976b6039aa54 (diff) | |
Re-order methods for readability
Diffstat (limited to 'src/main/java/com/stileeducation')
| -rw-r--r-- | src/main/java/com/stileeducation/markr/service/TestResultsService.java | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/src/main/java/com/stileeducation/markr/service/TestResultsService.java b/src/main/java/com/stileeducation/markr/service/TestResultsService.java index 976687b..8dba13f 100644 --- a/src/main/java/com/stileeducation/markr/service/TestResultsService.java +++ b/src/main/java/com/stileeducation/markr/service/TestResultsService.java @@ -40,6 +40,34 @@ public class TestResultsService { .toArray(); } + public AggregateResponseDTO aggregateTestResults(String testId) { + AggregateResponseDTO aggregateResponseDTO = new AggregateResponseDTO(); + + testService.findTest(testId).ifPresent(test -> { + List<TestResult> testResults = findAllByTestId(testId); + if (!testResults.isEmpty()) { + populateAggregateResponse(aggregateResponseDTO, test, testResults); + } + }); + + return aggregateResponseDTO; + } + + public ImportResponseDTO processTestResults(MCQTestResultsDTO testResults) { + ImportResponseDTO.ImportData importData = new ImportResponseDTO.ImportData(); + boolean isValid = true; + + for (MCQTestResultDTO mcqTestResult : testResults.getMcqTestResults()) { + try { + processTestResult(mcqTestResult, importData); + } catch (Exception e) { + isValid = false; + } + } + + return createImportResponse(importData, isValid); + } + public TestResult findOrCreateTestResult(Student student, Test test, Integer marksAwarded) { Optional<TestResult> optionalTestResult = testResultRepository.findByStudentAndTest(student, test); if (optionalTestResult.isPresent()) { @@ -145,19 +173,6 @@ public class TestResultsService { return new Percentile().evaluate(percentages, 75.0); } - public AggregateResponseDTO aggregateTestResults(String testId) { - AggregateResponseDTO aggregateResponseDTO = new AggregateResponseDTO(); - - testService.findTest(testId).ifPresent(test -> { - List<TestResult> testResults = findAllByTestId(testId); - if (!testResults.isEmpty()) { - populateAggregateResponse(aggregateResponseDTO, test, testResults); - } - }); - - return aggregateResponseDTO; - } - private void populateAggregateResponse(AggregateResponseDTO dto, Test test, List<TestResult> results) { dto.setMean(calculateMeanOfTestResults(test, results)); dto.setStddev(calculateStandardDeviationOfTestResults(test, results)); @@ -169,21 +184,6 @@ public class TestResultsService { dto.setCount(results.size()); } - public ImportResponseDTO processTestResults(MCQTestResultsDTO testResults) { - ImportResponseDTO.ImportData importData = new ImportResponseDTO.ImportData(); - boolean isValid = true; - - for (MCQTestResultDTO mcqTestResult : testResults.getMcqTestResults()) { - try { - processTestResult(mcqTestResult, importData); - } catch (Exception e) { - isValid = false; - } - } - - return createImportResponse(importData, isValid); - } - private void processTestResult(MCQTestResultDTO mcqTestResult, ImportResponseDTO.ImportData importData) { Student student = studentService |
