Hi Keena,

The short answer is - write some Java code to transform the Cayenne result into 
a data structure appropriate for Thymeleaf display. 

I don't know anything about Thymeleaf, but from quick googling, it might look 
like this:

<table>
  <tr>
     <th>HOST</th>
     <th th:each="ts: ${timestamps}" th:text="${ts}"/>
  </tr>
  <tr th:each="hostData: ${valuesByHost}">
     <td th:each="ts: ${timestamps}" th:text="${hostData.get(ts)}"/>
  </tr>
</table>


Now you need to build "timestamps" and "valuesByHost" collections:

List<UtilizationData> result = ...
Set<LocalDateTime> timestampsUnsorted = new HashSet<>();
Map<String, Map<LocalDateTime , Integer>> valuesByHost = new HashMap<>();

// iterate over "result", populating "timestampsUnsorted" and "valuesByHost" 
from the object data
...

List<LocalDateTime> timestamps = new ArrayList<>(timestampsUnsorted);
Collections.sort(timestamps);

HTH,
Andrus

P.S. BTW, can you show your Cayenne query. You are saying that you have 
ObjectSelect.columnQuery (which normally returns a List<Object> or 
List<Object[]>), while your result seems to be a List<UtilizationData>, which 
would be the case if you ran a regular (not column) ObjectSelect query.


> On Aug 15, 2019, at 6:16 AM, Keena Grepo <keena.grepo...@gmail.com> wrote:
> 
> Hi, 
> 
> I have this data returned by ObjectSelect.columnQuery :
> 
> [{<ObjectId:UtilizationData, id=1>; committed; [hostname=>cc001; 
> percentagePerHour=>100; timestamp=>2019-07-09 00:00:00]}, 
> {<ObjectId:UtilizationData, id=2>; committed; [hostname=>cc001; 
> percentagePerHour=>50; timestamp=>2019-07-09 01:00:00]}, 
> {<ObjectId:UtilizationData, id=3>; committed; [hostname=>cc001; 
> percentagePerHour=>50; ; timestamp=>2019-07-09 02:00:00]}, 
> {<ObjectId:UtilizationData, id=4>; committed; [hostname=>cc001; 
> percentagePerHour=>83; timestamp=>2019-07-09 03:00:00]}, ...]
> 
> And I want to display the data in a table with "HOST", and timestamps as 
> table head. Then for the table data are the value of hostname and the 
> percentagePerHour for each respective timestamp (like the sample table 
> below). How can I achieve this? 
> -------------------------------------------------------------------------------------------------------------------------------
> | HOST  | 2019-07-09 00:00:00 | 2019-07-09 01:00:00 | 2019-07-09 02:00:00 | 
> 2019-07-09 03:00:00 |
> -------------------------------------------------------------------------------------------------------------------------------
> | cc001  | 100                            | 50                               
> | 50                              | 83                               |
> -------------------------------------------------------------------------------------------------------------------------------
> 
> By the way, I am using Springboot + Thymeleaf.
> 
> Thanks.

Reply via email to