I have a collection of data in the following format:
[[timestamp, jobid, time to completion],[..]]
This data is sourced from a SQL database and is grouped by timestamp and jobid. The array looks like this:
[
[1, 30, 400],
[1, 31, 200],
[2, 29, 300],
..
]
My goal is to rearrange this data into a new array where each row corresponds to a timestamp and each column represents a specific jobid.
To achieve this, I initially attempted iterating through the existing array and populating a new one. However, the resulting array ended up being variable in width, making it difficult to identify which values corresponded to each job ID.
What I desire is an output that resembles the following structure:
timestamp, jobid29, jobid30, jobid31
[
[1, 0, 400, 200],
[2, 300, 0, 0],
..
]
Unfortunately, outputting as a map is not an option for me.
How would you suggest achieving this? My current plan involves first identifying all distinct jobids within the input and then mapping each jobid to a specific position in the output array. Is there a better approach?
Appreciate your insights.