I have an array of arrays, the length of the array is 17672, each array contains 7 elements. Looks like that:
id| product | client | reward | tariff | Threshold ------------------------------------------------------ 1 | guitar | john | 0.2 | 0.5 | 500 1 | guitar | john | 0.3 | 0.6 | 1000 1 | guitar | john | 0.4 | 0.7 | 2000 2 | drums | ringo | 0.2 | 0.5 | 2 | drums | ringo | 0.3 | 0.6 | 2 | drums | ringo | 0.7 | 0.8 | 3 | cello | george | 0.1 | 0.2 | 500 3 | cello | george | 0.2 | 0.4 | 800 3 | cello | george | 0.4 | 0.6 | 3000 There are still columns here, but I removed them with no problems.
From this table I want to get the following JSON
[ { "limit": { "max": "10000", "min": "2" }, "thesholds": [ { "reward": 0.25653, "tariff": 0.41186, "threshold": "500" }, { "reward": 0.58445, "tariff": 0.31421, "threshold": "1000" }, { "reward": 6.71413, "tariff": 0.2757, "threshold": "2000" } ], "client": "john", "product": "guitar" }, { "limit": { "max": "100", "min": "2" }, "thesholds": [], "product": "drums", "client": "ringo" } ] My previous code that takes data from two different data, products and thresholds. There are now 11514 products and 9237 thresholds. But this code works for a very long time. More than 6 minutes, which is not very good. Now I have combined the two tables into one by key, and the table in the example above is obtained.
Question: how to group 3 rows into one, and add a column to an array in the array?
I thought, if a table is merged into one, there will be faster conversions to JSON and give it to the client
The tags do not have these technologies, I will write here
linqjs - http://neue.cc/reference.htm
google fusion table - data storage from google
function getClientsProducts() { // indexes var prdInx = clientsProductsIndex(SHEET_ID, "clientsProducts"); // Fusion Table query var sql = 'SELECT * FROM ' + tables["clientsProducts"]; var fClientsProducts = FusionTables.Query.sqlGet(sql, { hdrs: false }).rows; return Enumerable.From(ClientsProducts).Select(function(prd) { return { limit: { max: prd[prdInx.limit.max], min: prd[prdInx.limit.min] }, threshold: getClientsProductsThreshold(prd[prdInx.id]), client: prd[prdInx.client], product: prd[prdInx.product] } }) .Take(2) .ToJSON(null, 4) } function getClientsProductsThreshold(id) { var sql = 'SELECT * FROM ' + tables["clientsProductsThreshold"] + " WHERE id = '" + id + "' LIMIT 3"; var rows = FusionTables.Query.sqlGet(sql, { hdrs: false }).rows; return Enumerable.From(rows).Select(function(row) { return { reward: row[1], tariff: row[2], threshold: row[3] } }).ToArray() }