Names Default To Here(1);
file_path = "$DOWNLOADS\Test.json";
aa_all = Load Text File(file_path, JSON);
// separate prediction to it's own AA as it is only we need to loop over, rest are constants
aa_pred = Remove From(aa_all, "prediction");
// from each prediction, we need to collect:
// data.points (multiple rows), score, type
// Note - we don't add points columns yet, because we don't how many we will have.
dt_pred = New Table("preds",
Add Rows(0),
New Column("name", Character, Continuous),
New Column("score", Numeric, Continuous),
New Column("type", Character, Nominal)
);
// calculate max points and create points columns
max_points = 0;
For Each({{pred_key, pred_data}}, aa_pred,
For Each({aa_data}, pred_data,
If(Contains(aa_data, "data"),
If(Contains(aa_data["data"], "points"),
points_list = aa_data["data"]["points"];
m_points = Matrix(points_list);
new_max_points = N Rows(m_points) * N Cols(m_points);
If(new_max_points > max_points,
max_points = new_max_points;
);
);
);
);
);
point_cols = {};
For(i = 1, i <= max_points, i++,
Insert Into(point_cols, dt_pred << New Column("Points", Numeric, Continuous));
);
point_cols[1] << Set Name("Points 1");
For Each({{pred_key, pred_data}}, aa_pred,
If(N Items(pred_data) == 0,
new_row = {};
new_row = Eval List({pred_key, ., ""});
Insert Into(new_row, AsList(J(1, max_points, .)`));
dt_pred << Add Rows(1);
dt_pred[N Rows(dt_pred), 0] = new_row;
,
For Each({aa_data}, pred_data,
new_row = Eval List({pred_key, aa_data["score"], aa_data["type"]});
Insert Into(new_row, As List(Shape(Matrix(aa_data["data"]["points"]), max_points, 1)));
dt_pred << Add Rows(1);
dt_pred[N Rows(dt_pred), 0] = new_row;
);
);
);
For Each({{key, val}}, aa_all,
dt_pred << New Column(key, Character, Nominal, << Set Each Value(char(aa_all[key])));
);