Datetime and numbers localization in adreportstats async query - facebook-ads-api

Is there any way to set datetime and numbers format based on locale info in adreportstats asynchronous queries? I've tried to fetch data with request parameter "locale" but it fails.
UPD:
There is no code for this issue. I just want to get in response localized json data. Here is response example:
{
'data': [
{
'adgroup_id': 1,
'country': 'US',
'gender': 'female',
'date_start': 2013-09-01,
'date_stop': 2013-09-02,
'reach': 2000,
'ctr': 0.42333333333333
},
{
'adgroup_id': 2,
'country': 'UK',
'gender': 'male',
'date_start': 2013-09-01,
'date_stop': 2013-09-02,
'reach': 1500,
'ctr': 0.33333333333333
},
...
]}
I want to get it for "de_DE" locale:
{
'data': [
{
'adgroup_id': 1,
'country': 'US',
'gender': 'female',
'date_start': 01.09.2013, <------ de_DE localized date
'date_stop': 02.09.2013,
'reach': 2000,
'ctr': 0,42333333333333 <------ de_DE localized number
},
{
'adgroup_id': 2,
'country': 'UK',
'gender': 'male',
'date_start': 01.09.2013,
'date_stop': 02.09.2013,
'reach': 1500,
'ctr': 0,33333333333333
},
...
]}

By design: "The Ads API does not support the "locale" parameter. The supported parameters for Ad Report Stats are documented here: https://developers.facebook.com/docs/reference/ads-api/adreportstats/"

Related

elasticsearch 5: returning same document multiple times if multiple array items of one document fit condition

We are using elastic search 5 (yes I know it is EOL but it is what it is)
Elastic newbie here with a rather complicated task:
Let's imagine we have an event index filled with multiple event documents. Those event documents might have n speakers attached in a speakers object array. A speaker has a gender attribute.
How can I achieve the following query?
"return event for each speaker whose gender is x "
returning query result:
{
page: 1,
pageSize: 20,
total: 3
items: [
{
id: 1,
speakers: [
{
name: 'Sascha',
gender: 'x'
}
]
},
{
id: 1,
speakers: [
{
name: 'Leo',
gender: 'x'
}
]
},
{
id: 2,
speakers: [
{
name: 'Rue',
gender: 'x'
}
]
},
]
}
event index filled with three event documents
event 1
{
id: 1,
speakers: [
{
name: 'Sascha',
gender: 'x'
},
{
name: 'Leo',
gender: 'x'
},
]
}
event 2
{
id: 2,
speakers: [
{
name: 'Thomas',
gender: 'm'
},
{
name: 'Rue',
gender: 'x'
},
]
}
event 3
{
id: 2,
speakers: [
{
name: 'Nicole',
gender: 'f'
}
]
}
I didn't even start to code or write a query because I am not sure if elastic is built to give me a result like the one I want to achieve.
I don't even know how to articulate the type of query I am trying to achieve :/
Or do I have to create a new index which combines event and speaker index in a way I can work with?

Elasticsearch how to get objects from a nested structure

Here is the structure of my document:
{
'parent_list': [
{
'child_list': [
{
'name': 'A',
'score': 0.86
},
{
'name': 'B',
'score': 0.92
},
{
'name': 'C',
'score': 0.77
}
]
},
{
'child_list': [
{
'name': 'B',
'score': 0.41
},
{
'name': 'D',
'score': 0.66
}
]
},
]
}
What I want is to get the object with maximum score property from each child_list, i.e. From the document above i would like to get something like this:
[
{
'name': 'B',
'score': 0.92
},
{
'name': 'D',
'score': 0.66
}
]
Or, it would also be plenty to just receive the name property of these objects.
I use nested mapping type for both parent_list and child_list, name is text, and score is float.
So far i have tried using nested aggregation/queries and I am able to get max score from each of the child_list lists, so that would be: 0.92, 0.66. But i cannot figure out how to get the corresponding name property. Any help is welcome.

nativescript-couchbase-plugin querying

I'm trying to use nativescript-couchbase-plugin.
Here is my code:
whereArray.push({ property: "type_id", comparison: "equalTo", value: typeId });
return itemsDb.query({
select: [],
where: whereArray,
order: [{property: "rating", direction: "desc"}],
limit: this.PAGE_SIZE,
offset: page * this.PAGE_SIZE
});
Everything works fine: condition in where clause, ordering, limit and offset.
But I want to add something new to my condition and I'm trying to do this:
whereArray.push({ property: "title", comparison: "like", value: "some name"});
or
whereArray.push({ property: "filters", comparison: "in", value: [1,2,3]});
And these cases don't work. Neither of them. The only one that works is the first one with type_id
So the question is - how to use where array to query corresponding data?
Data Sample:
{
"type_id": 2,
"title": "some name",
"regionId": 372,
"uid": 16177,
"filters": [
1,
2,
3
]
},
P.S. There is an issue inside original repository. But it has no activity at all.
I must agree the plugin documentation could be better. But if you go through the TypeScript declaration, you will find the issue with your code.
When you are adding multiple where conditions, you must include a logical operator.
import {
Couchbase,
QueryLogicalOperator,
QueryComparisonOperator
} from "nativescript-couchbase-plugin";
const database = new Couchbase("my-database");
// Insert docs for testing
const documentId = database.createDocument({
type_id: 2,
title: "some name",
regionId: 372,
uid: 16177,
filters: [1, 2, 3]
});
console.log(documentId);
// Query
const results = database.query({
select: [],
where: [
{
property: "type_id",
comparison: "equalTo",
value: 2,
logical: QueryLogicalOperator.AND
},
{
property: "filters",
comparison: "in",
value: [1, 2, 3]
}
],
order: [{ property: "rating", direction: "desc" }],
limit: 10
});
console.log(results);

AmCharts serial multiple data sets

Taking a look at different examples on the documentation, I found that the only way to include multiple graphs (or lines) on a serial chart would be to do so by placing the data in one array as such:
[{
category: 1,
value1: .8,
value2: .64,
},
{
category: 2,
value1: .75,
value2: -.4,
}];
However, this is rather tedious if you have multiple data sets you are trying to display at once; is there an alternative way to do this, where you would pass multiple arrays at once (this is what I figured an implementation would look like, but it is not the case):
[
// First set of data
{ category: 0, value: .5},
{ category: 1, value: .5},
{ category: 2, value: .5},
{ category: 3, value: .5},
{ category: 4, value: .3},
{ category: 5, value: 1}
],
// Second set of data
[
{ category: 0, value: .5 },
{ category: 1, value: .3 },
{ category: 2, value: .25 },
{ category: 3, value: .6 },
{ category: 4, value: .79 },
{ category: 5, value: .81 }
]],
Any ideas on how this may be done? Or would I need to do switch to a different type of chart?
This isn't possible in the regular AmCharts JavaScript Charts library. The only supported format is a single array of objects with the values consolidated by category as you've noticed. You'll have to preprocess your data beforehand.
The AmCharts Stock Chart library supports separate arrays of data in the dataSets array, however it only supports date-based data.
AmCharts.makeChart("chartdiv", {
"type": "stock",
"dataSets": [{
// other properties omitted
"dataProvider": [{
category: "2017-08-01,
value: 3
}, {
category: "2017-08-02,
value: 2
}, {
category: "2017-08-03,
value: 1
}, // ...
]
}, {
// other properties omitted
"dataProvider": [{
category: "2017-08-01,
value: 10
}, {
category: "2017-08-02,
value: 9
}, {
category: "2017-08-03,
value: 5
}, // ...
]
},
// ...
]
// ...
});
You can see this in action in the any of the stock chart demos.

Ruby, unique hashes in array based on multiple fields

I'd like to get back an array of hashes based on sport and type combination
I've got the following array:
[
{ sport: "football", type: 11, other_key: 5 },
{ sport: "football", type: 12, othey_key: 100 },
{ sport: "football", type: 11, othey_key: 700 },
{ sport: "basketball", type: 11, othey_key: 200 },
{ sport: "basketball", type: 11, othey_key: 500 }
]
I'd like to get back:
[
{ sport: "football", type: 11, other_key: 5 },
{ sport: "football", type: 12, othey_key: 100 },
{ sport: "basketball", type: 11, othey_key: 200 },
]
I tried to use (pseudocode):
[{}, {}, {}].uniq { |m| m.sport and m.type }
I know I can create such array with loops, I'm quite new to ruby and I'm curious if there's a better (more elegant) way to do it.
Try using Array#values_at to generate an array to uniq by.
sports.uniq{ |s| s.values_at(:sport, :type) }
One solution is to build some sort of key with the sport and type, like so:
arr.uniq{ |m| "#{m[:sport]}-#{m[:type]}" }
The way uniq works is that it uses the return value of the block to compare elements.
require 'pp'
data = [
{ sport: "football", type: 11, other_key: 5 },
{ sport: "football", type: 12, othey_key: 100 },
{ sport: "football", type: 11, othey_key: 700 },
{ sport: "basketball", type: 11, othey_key: 200 },
{ sport: "basketball", type: 11, othey_key: 500 }
]
results = data.uniq do |hash|
[hash[:sport], hash[:type]]
end
pp results
--output:--
[{:sport=>"football", :type=>11, :other_key=>5},
{:sport=>"football", :type=>12, :othey_key=>100},
{:sport=>"basketball", :type=>11, :othey_key=>200}]

Resources