I want to export data of two different arrays in a single excel document.
The data of two different arrays should be exported in two different sheets.
$scope.details= {
"boys": [
{"name":"Jeet", "age":25},
{"name":"John", "age":24}
],
"girls":[
{"name":"Gita", "age":25},
{"name":"Sima", "age":24}
]
}
Now if I write
alasql('SELECT * INTO XLSX("Details.xlsx",{headers:true}) FROM ?',[$scope.details.boys]);
It will export the details of boys only in the excel sheet.
How do I export for both boys and girls in a single excel document in two different sheets? Thanks in advance.
You need to create two different sheets with two different arrays holding boys and girls information and then export like below
$scope.details= {
"boys": [
{"name":"Jeet", "age":25},
{"name":"John", "age":24}
],
"girls":[
{"name":"Gita", "age":25},
{"name":"Sima", "age":24}
]
}
var boys = $scope.details.boys;
var girls = $scope.details.girls;
var opts = [{ sheetid: 'Boys', headers: true }, { sheetid: 'Girls', headers: true }];
alasql('SELECT INTO XLSX("Details.xlsx",?) FROM ?', [opts, [boys, girls]]);
Related
I have the following two lists:
['value1', 'value1', 'value1', 'value2', 'value2', 'value2', 'value3', 'value3', 'value3']
['value1_link1', 'value1_link2', 'value1_link3', 'value2_link1', 'value2_link2',
'value2_link3', 'value3_link1', 'value3_link2', 'value3_link3']
I am trying to populate json objects in the following manner:
[
{
"timestamp":"string",
"ext":"value1",
"discoveredlinks":['value1_link1', 'value1_link2', 'value1_link3']
},
{
"timestamp":"string",
"ext":"value2",
"discoveredlinks":['value2_link1', 'value2_link2', 'value2_link3']
},
{
"timestamp":"string",
"ext":"value3",
"discoveredlinks":['value3_link1', 'value3_link2', 'value3_link3']
}
]
Any help would be appreciated !
Thanks !
Looks to me like you don't need the first list, as all the info is in the second list. I can't guarantee that my solution is the most optimised, but one way you can do it is as follows:
import json
from collections import defaultdict
links = [
"value1_link1",
"value1_link2",
"value1_link3",
"value2_link1",
"value2_link2",
"value2_link3",
"value3_link1",
"value3_link2",
"value3_link3",
]
temp_dict = defaultdict(list)
for link in links:
ext = link.split("_")[0]
temp_dict[ext].append(link)
output = json.dumps(
[
{"timestamp": "string", "ext": ext, "discoveredlinks": discovered_links}
for ext, discovered_links in temp_dict.items()
]
)
print(output)
you can remove the the json.dumps if you'd rather have it as a list rather than a json string
I'm trying to merge two arrays into one array consisting of objects created from the corresponding array items from the two original arrays:
Ex:
words = ['Toolbar', 'Vamoose', 'Arcade'];
clues = ['Strip of buttons', 'Get lost', 'Pinball wizards hangout'];
What I want:
output = [{'Toolbar', 'Strip of buttons'}, {'Vamoose', 'Get lost'}, {'Arcade', 'Pinball wizards hangout'}]
Any suggestions?
Figured it out:
let words = ['Toolbar', 'Vamoose', 'Arcade'];
let clues = ['Strip of buttons', 'Get lost', 'Pinball wizards hangout'];
let data = [];
words.forEach((obj, index) => {
obj = {
word: words[index],
clue: clues[index]
};
data.push(obj)
})
console.log(data)
[{
"word": "Toolbar",
"clue": "Strip of buttons"
},
{
"word": "Vamoose",
"clue": "Get lost"
},
{
"word": "Arcade",
"clue": "Pinball wizards hangout"
}]
I want to create a resource for many regions, environments, apps, etc at once.
I'd like to do something like this:
param apps array = [
'app1'
'app2'
'app3'
]
param environments array = [
'alpha'
'beta'
]
param regions array = [
'ne'
'we'
'uks'
]
resource origin_group 'Microsoft.Cdn/profiles/origingroups#2021-06-01' = [ for region in regions: {
[ for env in environments: {
[ for app in apps: {
parent: profiles_global_fd_name_resource
name: '${env}-${region}-${app}-origin-group'
properties: {
loadBalancingSettings: {
sampleSize: 4
successfulSamplesRequired: 3
additionalLatencyInMilliseconds: 50
}
healthProbeSettings: {
probePath: '/'
probeRequestType: 'HEAD'
probeProtocol: 'Http'
probeIntervalInSeconds: 100
}
sessionAffinityState: 'Disabled'
}
}]
}]
}]
All docs mentioning nested loops talk about looping inside a resource to create many sub-resources. Not what I'm after. Perhaps another way would be to somehow merge all these arrays into a single array of objects of every possible iteration. Not sure where to start with that either.
Any help much appreciated.
This is not supported for the moment but it will (see Is there plans to support nested loop on resources?).
Using a little bit of math, you could achieve what you'd like (Not sure if you should):
param environments array = [ 'alpha', 'beta' ]
param regions array = [ 'ne', 'we', 'uks' ]
param apps array = [ 'app1', 'app2', 'app3' ]
// Setting some variables for clarity
var envCount = length(environments)
var regionCount = length(regions)
var appCount = length(apps)
// Setting the total number of combination
var originGroupCount = envCount * regionCount * appCount
// Iterate all possible combinations
output originGroupNames array = [for i in range(0, originGroupCount): {
name: '${environments[i / (regionCount * appCount) % envCount]}-${regions[i / appCount % regionCount]}-${apps[i % appCount]}-origin-group'
}]
this will output all possible combinations (I think) for origin group name.
I have this job test task where I am need some help.
I have to somehow dynamically access the value in the data stucture below, through references. To this point I used loops and indexOf() in an ordered alphabet and numbers. indexOf("B") in alphabet is [[ 1 ]], indexOf(1) is [0] for the two dimensional array.
Here "B1" is referencing "C1", "C1" references "D1" .. to "H1" and when "H1" points to the text "Last", all of the formulas should turn into the same value - the text "Last".
But how? Been breaking my head for a couple of hours and remembered linked lists, but so far have no clue how to implement them. How can I achieve this?
{
data: [
[
{ reference: "B1" },
{ reference: "C1" },
{ reference: "D1" },
{ reference: "E1" },
{ reference: "F1" },
{ reference: "G1" },
{ reference: "H1" },
{ text: "Last" },
]
],
id: "job-20"
}
It looks like you need to work with a spreadsheet type of data structure, and need to recalculate cells based on the formulas they have.
You can use recursion for that.
The base case happens when you arrive at a cell that has no reference. In that case the text of that cell can be returned to the caller. And that caller will assign that text to the cell it was looking at, and also returns that to their caller...etc.
function get(reference) { // return the cell object at the given reference
return data[reference.slice(1)-1][reference.charCodeAt() - "A".charCodeAt()];
}
function resolve(cell, visited=new Set) {
// Have we found a cell with just text? Then return that to caller
if (!("reference" in cell)) return cell.text;
// Did we already meet this cell before? Then we are running in circles!
if (visited.has(cell)) return "Circular Reference!";
// Make a recursive call to know what the text should be
cell.text = resolve(get(cell.reference), visited.add(cell));
delete cell.reference;
return cell.text; // Return this value also to the caller
}
function calculate(data) {
// Get to each cell object...
for (let row of data) {
for (let cell of row) {
resolve(cell); // And update its text property by following references
}
}
}
let data = [
[
{reference: "B1"}, {reference: "C1"}, {reference: "D1"}, {reference: "E1"},
{reference: "F1"}, {reference: "G1"}, {reference: "H1"}, {text: "Last"},
]
];
calculate(data);
console.log(data);
It should be noted that in a real spreadsheet the references (formulas) are not deleted during such a recalculation. The cell will have both the text and the reference, so that when a cell's text is updated, all other dependent cells get their own text updated accordingly again.
I have 2 api responses and want to compare only one of the column values 'logline'. How can I do it?
I have tried the following, but the Test Result is always Failed.
pm.test("status Check", function () {
var jsonData = pm.response.json();
var resp_arr = jsonData.results[0].series[0].values;
_.each(jsonData, (arrItem) => {
pm.expect(arrItem.status).to.be.oneOf(resp_arr);
})
});
Basically, I want to compare 2 JSON responses which are in array format and only the second column.
My API Response: Both response are in same format & structure
{
"results":[
{
"statement_id":0,
"series":[
{
"name":"process_log",
"columns":[
"time",
"logline"
],
"values":[
[
"2020-09-21T12:41:01.199552139Z",
"9/10/2020 15:57:31.073\t abc"
],
[
"2020-09-21T12:41:01.199824076Z",
"9/10/2020 15:57:31.078\t xyz"
]
]
}
]
}
]
}