I've a API that returns this data for me.
I need to access the datas inside this. I've tried some response.SOAP-Env:Envelope but got error because of two points.
Can't debug it more because Im using react native.
http://myjson.com/14veid
{
"SOAP-ENV:Envelope": {
"$": {
"SOAP-ENV:encodingStyle": "http://schemas.xmlsoap.org/soap/encoding/",
"xmlns:SOAP-ENV": "http://schemas.xmlsoap.org/soap/envelope/",
"xmlns:xsd": "http://www.w3.org/2001/XMLSchema",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"xmlns:SOAP-ENC": "http://schemas.xmlsoap.org/soap/encoding/"
},
"SOAP-ENV:Body": [
{
"Entidade.dadosEntidadeResponse": [
{
"return": [
{
"$": {
"xsi:nil": "true",
"xsi:type": "xsd:int"
}
}
],
"msgResult": [
{
"_": "Ok",
"$": {
"xsi:type": "xsd:string"
}
}
],
"rsEntidade": [
{
"_": "ASSOCIAÃÃO PRO MELHORAMENTOS DA VILA PREL",
"$": {
"xsi:type": "xsd:string"
}
}
],
"enderecoEntidade": [
{
"_": "RUA THEREZA MAIA PINTO",
"$": {
"xsi:type": "xsd:string"
}
}
],
"telEntidade": [
{
"_": "1158126849",
"$": {
"xsi:type": "xsd:string"
}
}
],
"emailEntidade": [
{
"_": "xxx#uol.com.br",
"$": {
"xsi:type": "xsd:string"
}
}
],
"telPresidente": [
{
"_": "5222682-2716",
"$": {
"xsi:type": "xsd:string"
}
}
],
"emailPresidente": [
{
"$": {
"xsi:type": "xsd:string"
}
}
]
}
]
}
]
}
I need to access the emailEntidade, telEntidade proprieties of this response.
Tried many wat to do this but without success.
Using javascript, react native
Related
I've stored documents within my elasticsearch service that are similar to this:
[
{
"first_name": "John",
"last_name": 'Dow',
"statuses": [
{
"name": "STAT1",
"start_date":"2022-10-21T21:03:06",
"happy": false
},
{
"name": "STAT2",
"start_date":"2022-10-21T21:03:06",
"happy": true
},
]
}
...
]
I've a component within my UI where the user can select the required filters that he wants to apply on the data.
For example give me the docs where:
first_name == "John" & last_name== 'Doe'
After the user selecting the desired filters, i'm creating a query similar to this one:
"query": {
"bool": {
"must": [
{
"regexp": {
"first_name": {
"value": ".*John.*"
}
},
"regexp": {
"last_name": {
"value": ".*Doe.*"
}
},
}
],
"should": []
}
}
Now I've a new requirement where i need to allow to filter the documents as follow:
Show me the document where:
statuses.name === STAT1 & statuses.happy === false
and
statuses.name === STAT2 & statuses.happy === true
and
first_name === Jhon
I didn't found any example how to achieve that requirement, any help would be appreciated
You can start with this query. Read more about nested queries.
{
"query": {
"bool": {
"must": [
{
"match": {
"first_name": "john"
}
}
],
"filter": [
{
"nested": {
"path": "statuses",
"query": {
"bool": {
"must": [
{
"match": {
"statuses.name": "STAT1"
}
},
{
"term": {
"statuses.happy": {
"value": "false"
}
}
}
]
}
}
}
},
{
"nested": {
"path": "statuses",
"query": {
"bool": {
"must": [
{
"match": {
"statuses.name": "STAT2"
}
},
{
"term": {
"statuses.happy": {
"value": "true"
}
}
}
]
}
}
}
}
]
}
}
}
How do I group the date field one to the next one in each document?
{
_id: ObjectId('...'),
date: [ISODate('2022-05-27T00:00:00.000+00:00'), ISODate('2022-05-28T00:00:00.000+00:00') ...]
}
The desired document would like this:
{
_id: ObjectId('...'),
date1: ISODate('2022-05-27T00:00:00.000+00:00'),
date2: ISODate('2022-05-28T00:00:00.000+00:00')
}
Here's one way to do it.
db.collection.aggregate([
{ "$replaceWith": {
"$mergeObjects": [
{ "_id": "$_id" },
{ "$arrayToObject": {
"$map": {
"input": { "$range": [ 0, { "$size": "$date" } ] },
"as": "dateNum",
"in": {
"k": {
"$concat": [
"date",
{ "$toString": { "$add": [ "$$dateNum", 1 ] } }
]
},
"v": { "$arrayElemAt": [ "$date", "$$dateNum" ] }
}
}
}
}
]
}
}
])
Try it on mongoplayground.net.
I'm working on a custom function for Google Sheets, that receives a cell value as input and spits out the response from an API call. Knowing thatin the current stage Google Analytics Reporting API can't be directly used with the custom function, I'm following this and this workaround.
The function that runs the API call to the Google Analytics Reporting API includes a JSON-formatted request with metrics, dimensions, filters, etc. The problem is that the dimension filter is variable and I want that to be the input from Google Sheets. However, I keep getting this error message:
GoogleJsonResponseException: API call to analyticsreporting.reports.batchGet failed with error: Field request.dimensionFilterClauses.filters.expressions is required. (line 2, file "Code")
function plateToCampaign(plate) {
globalThis.r = AnalyticsReporting.Reports.batchGet({
"reportRequests":
[
{
"viewId": {"my_viewId"},
"pageSize": 1,
"dateRanges": [
{"endDate": "today", "startDate": "30daysAgo"}
],
"metrics": [
{"expression": "ga:pageValue"}
],
"dimensions": [{"name": "ga:sourceMedium"}, {"name": "ga:campaign"}, {"name": "ga:dateHourMinute"}],
"orderBys": {"fieldName": "ga:dateHourMinute","sortOrder": "DESCENDING"},
"dimensionFilterClauses": [
{
"filters": [
{
"dimensionName": "ga:pagePath",
"operator": "PARTIAL",
"expressions": [plate]
}
]
}
]
}
]
});
globalThis.c = r.reports[0].data.rowCount > 0? r.reports[0].data.rows[0].dimensions[0] : null
if (c === "google / cpc") {
globalThis.x = r.reports[0].data.rows[0].dimensions[1]
console.log(x)
return(x)
} else {
console.log(c);
return(c)
}
}
function doGet(e) {
const res = plateToCampaign(e.parameter.plate)
return ContentService.createTextOutput(JSON.stringify(res));
}
function test(plate) {
const url = {"my_web_app_url"}
return UrlFetchApp.fetch(url).getContentText();
}
If I change the variable plate to a single value then it works, ie function plateToCampaign(plate = {"fixed_value"}). However this value will be different every time. How do I fix this?
After correcting your json as follows
var reportRequests =
[
{
"viewId": "my_viewId",
"pageSize": 1,
"dateRanges": [
{"endDate": "today", "startDate": "30daysAgo"}
],
"metrics": [
{"expression": "ga:pageValue"}
],
"dimensions": [{"name": "ga:sourceMedium"}, {"name": "ga:campaign"}, {"name": "ga:dateHourMinute"}],
"orderBys": {"fieldName": "ga:dateHourMinute","sortOrder": "DESCENDING"},
"dimensionFilterClauses": [
{
"filters": [
{
"dimensionName": "ga:pagePath",
"operator": "PARTIAL",
"expressions": ["plate"]
}
]
}
]
}
]
you will be able to change plate for instance this way
function myfunction(item) {
var reportRequests =
[
{
"viewId": "my_viewId",
"pageSize": 1,
"dateRanges": [
{ "endDate": "today", "startDate": "30daysAgo" }
],
"metrics": [
{ "expression": "ga:pageValue" }
],
"dimensions": [{ "name": "ga:sourceMedium" }, { "name": "ga:campaign" }, { "name": "ga:dateHourMinute" }],
"orderBys": { "fieldName": "ga:dateHourMinute", "sortOrder": "DESCENDING" },
"dimensionFilterClauses": [
{
"filters": [
{
"dimensionName": "ga:pagePath",
"operator": "PARTIAL",
"expressions": [""]
}
]
}
]
}
]
reportRequests[0].dimensionFilterClauses[0].filters[0].expressions[0] = item
// include reportRequests in your own script ...
}
application
try this
function plateToCampaign(item = 'plate') {
var myRequest =
[
{
"viewId": "my_viewId",
"pageSize": 1,
"dateRanges": [
{ "endDate": "today", "startDate": "30daysAgo" }
],
"metrics": [
{ "expression": "ga:pageValue" }
],
"dimensions": [{ "name": "ga:sourceMedium" }, { "name": "ga:campaign" }, { "name": "ga:dateHourMinute" }],
"orderBys": { "fieldName": "ga:dateHourMinute", "sortOrder": "DESCENDING" },
"dimensionFilterClauses": [
{
"filters": [
{
"dimensionName": "ga:pagePath",
"operator": "PARTIAL",
"expressions": [""]
}
]
}
]
}
]
myRequest[0].dimensionFilterClauses[0].filters[0].expressions[0] = item
globalThis.r = AnalyticsReporting.Reports.batchGet({
"reportRequests": myRequest
});
globalThis.c = r.reports[0].data.rowCount > 0 ? r.reports[0].data.rows[0].dimensions[0] : null
if (c === "google / cpc") {
globalThis.x = r.reports[0].data.rows[0].dimensions[1]
console.log(x)
return (x)
} else {
console.log(c);
return (c)
}
}
I am trying an aggregation in MongoDB in order to convert:
[
{
"_id": ObjectId("5a934e000102030405000000"),
"acronym": "MC",
"tickers": [
{
"name": "Sensor1-front",
"symbol": "s1f"
},
{
"name": "Sensor1-back",
"symbol": "s1b"
}
]
}
]
into something like this:
['s1f.MC','s1b.MC']
Where each symbol in tickers is concat to acronym.
I am trying it with $concat, $group, etc but I am not going anywhere.
Thanks!
You can use reduce
db.collection.aggregate([
{
$addFields: {
newField: {
"$reduce": {
"input": "$tickers",
"initialValue": [],
"in": {
"$concatArrays": [
[
{
"$concat": [
"$$this.symbol",
".",
"$acronym"
]
}
],
"$$value"
]
}
}
}
}
}
])
Working Mongo playground
I'm trying to loop through all the conditions for a form logic system utilizing the json-logic-js library and having issues going into the infinite nested conditions. It works when there is no additional nested operations but can't figure out away to loop through and detect if the condition contains additional conditions infinitely..
What I'm needing is this output
{
"or": [
{
"==": [
"0hxsj03jab9pjsu1",
"Rig 15"
]
},
{
"or": [
{
"==": [
"5l12cnsnxe1911bm",
"Corporate"
]
},
{
"==": [
"5l12cnsnxe1911bm",
"Pumping"
]
}
]
},
{
"and": [
{
"==": [
"69vsm5bkfb101n2n",
"Unsafe"
]
},
{
"or": [
{
"==": [
"b09ivo9r1aldu6jf",
"Yes"
]
},
{
"==": [
"0hxsj03jab9pjsu1",
"Rig 44"
]
},
{
"==": [
"0hxsj03jab9pjsu1",
"Other"
]
}
]
}
]
}
]
}
I currently have this much.
var item = {
"id":"8wj4xhwe3pd9aage",
"showif": {
"operator": "or",
"conditions": [
{
"operator": "and",
"conditions": [
{
"data": {
"fieldId": "69vsm5bkfb101n2n",
"settings": {
"values": [
"Unsafe"
]
}
}
},
{
"operator": "or",
"conditions": [
{
"data": {
"fieldId": "b09ivo9r1aldu6jf",
"settings": {
"values": [
"Yes"
]
}
}
},
{
"data": {
"fieldId": "0hxsj03jab9pjsu1",
"settings": {
"values": [
"Rig 44",
"Other"
]
}
}
}
]
}
]
},
{
"data": {
"fieldId": "0hxsj03jab9pjsu1",
"settings": {
"values": [
"Rig 15"
]
}
}
},
{
"data": {
"fieldId": "5l12cnsnxe1911bm",
"settings": {
"values": [
"Corporate",
"Pumping"
]
}
}
}
]
}
};
var condition = [];
item.showif.conditions.forEach(element => {
var orC = []
if(element.data){
element.data.settings.values.forEach(values => {
if(element.data.settings.values.length <= 1){
condition.push({"==": [element.data.fieldId,values]})
}else{
orC.push({"==": [element.data.fieldId,values]})
}
});
if(orC.length >= 1){
condition.push({"or":orC})
}
}
});
var Logic = {[item.showif.operator]: condition}
console.log(Logic)
I cant wrap my brain around this without getting lost..
I figured it out. For anyone else with this here is my code :)
var item = {
"id": "8wj4xhwe3pd9aage",
"showif": {
"operator": "or",
"conditions": [
{
"operator": "and",
"conditions": [
{
"data": {
"fieldId": "69vsm5bkfb101n2n",
"settings": {
"values": [
"Unsafe"
]
}
}
},
{
"operator": "or",
"conditions": [
{
"data": {
"fieldId": "b09ivo9r1aldu6jf",
"settings": {
"values": [
"Yes"
]
}
}
},
{
"data": {
"fieldId": "0hxsj03jab9pjsu1",
"settings": {
"values": [
"Rig 44",
"Other"
]
}
}
}
]
}
]
},
{
"data": {
"fieldId": "0hxsj03jab9pjsu1",
"settings": {
"values": [
"Rig 15"
]
}
}
},
{
"data": {
"fieldId": "5l12cnsnxe1911bm",
"settings": {
"values": [
"Corporate",
"Pumping"
]
}
}
}
]
}
};
function loopThrough(obj) {
var operator = obj.operator
var condition = [];
obj.conditions.forEach(element => {
var orC = []
if (element.data) {
element.data.settings.values.forEach(values => {
if (element.data.settings.values.length <= 1) {
condition.push({
"==": [element.data.fieldId, values]
})
} else {
orC.push({
"==": [element.data.fieldId, values]
})
}
});
if (orC.length >= 1) {
condition.push({
"or": orC
})
}
} else if (element.operator) {
condition.push(this.loopThrough(element))
}
});
return ({
[operator]: condition
})
}
console.log(loopThrough(item.showif));