public static void index() { Test test = Test.findById(1L); Account account = Account.find("byEmail", Security.connected()).first(); TestResult testResult = TestResult.find("test = ? and account = ? order by resultDate desc", test, account).first(); List<TestResultAttr> lastRes = TestResultAttr.find("byTestResult", testResult).fetch(); List<String[]> last = getTappingData(lastRes); List<TestResultAttr> allRes = TestResultAttr.find("testResult.test = ? and testResult.account = ?", test, account) .fetch(); List<String[]> all = getTappingData(allRes); @SuppressWarnings("JpaQlInspection") Query query = JPA.em() .createQuery( "select t.sortOrder - 1, avg(a.val) " + "from TestResult r, TestResultAttr a, TestAttr t " + "where a.testResult = r and a.testAttr = t and r.test = :test and r.account = :account group by t.sortOrder order by t.sortOrder"); query.setParameter("test", test); query.setParameter("account", account); List<String[]> avg = query.getResultList(); render(account, last, avg, all); }
@Util public static List<String[]> getTappingData(Collection<TestResultAttr> attrs) { List<String[]> results = new ArrayList<>(); for (TestResultAttr attr : attrs) { results.add( new String[] { String.valueOf(attr.getTestAttr().getSortOrder() - 1), String.valueOf(attr.getVal()) }); } return results; }