I have items endpoint which contains a list of embedded images. The scheme looks like:
_schema = {
'name': required_string, # group name
'description': {
'type': 'string',
'maxlength': 140,
},
'images': {
'type': 'list',
'scheme': {
'type': 'objectid',
'data_relation': {
'resource': 'images',
'embeddable': True,
'field': '_id',
}
},
}
}
So I'm trying to make a request to the items endpoint to get embedded objects
/items/549ae47f4fb9041305403292?embedded={"images":1}
But instead of embedded images I receive just the regular object with the list of images _ids.
Here is an example of object:
{
"_updated": "Wed, 24 Dec 2014 16:06:23 GMT",
"name": "New Item",
"images": [
"549ae47f4fb904130540328b",
"549ae47f4fb904130540328e",
"549ae47f4fb9041305403291"
],
"_created": "Wed, 24 Dec 2014 16:06:23 GMT",
"_id": "549ae47f4fb9041305403292",
"_etag": "949e3b731823bb2c08682ba4b6696b86856ef941",
"description": "The best item ever"
}
I tried to convert images ids in list to objectids, but it doesn't help. Any ideas why it doesn't work? Thanks
You have an incorrect schema definition. Replace scheme with schema when defining the images list:
_schema = {
'name': required_string, # group name
'description': {
'type': 'string',
'maxlength': 140,
},
'images': {
'type': 'list',
'schema': { # this was 'scheme' in your def
'type': 'objectid',
'data_relation': {
'resource': 'images',
'embeddable': True,
'field': '_id',
}
},
}
}
It will then properly embed your list of images.
Related
I'm using faust-streaming and python-schema-registry-client to serialize faust.Record classes to avro.
When I try to deserialize a Union of two complex types however faust cannot reconstruct the correct records and only presents a dictionary instead of a faust.Record class.
I have the following code and schema:
schema_union = schema.AvroSchema({
'type': 'record',
'name': 'UnionRecord',
'fields': [
{
'name': 'entity',
'type': [
'null',
{
'name': 'company',
'type': 'record',
'fields': [
{'name': 'name_company', 'type': 'string'},
]
},
{
'name': 'person',
'type': 'record',
'fields': [
{'name': 'name_person', 'type': 'string'},
]
}
]
}
]
})
client = SchemaRegistryClient(url='http://localhost:8081')
faust_serializer_union = FaustSerializer(client, 'schema-union', schema_union)
class Company(faust.Record):
name_company: str
class Person(faust.Record):
name_person: str
class UnionRecord(
faust.Record,
validation=True,
serializer=faust_serializer_union
):
entity: Optional[Union[Company, Person]] # Union is typing.Union
record = UnionRecord(entity=Company(name_company='name'))
If I now try to serialize record and then deserialize it:
out = record.dumps() # == b'\x00\x00\x00\x00\x13\x02\x08name'
UnionRecord.loads(out)
I get this:
<UnionRecord: entity={'name_company': 'name'}>
Whereas I expect to get this:
<UnionNoneRecord: entity=<Company: name_company='name'>>
If I remove the Union type and alter the schema so that I can have a faust.Record that has only this field: Optional[Company], I do get the correct deserialization.
I have a device that get some telemetry data via REST API. Some of the data that it received is in the following format:
{
...
parameters: [
{
'name': 'parameter1',
'grade': '2',
'info': 'some informtion'
},
{
'name': 'parameter2',
'grade': '1',
'info': 'some informtion'
},
...
]
}
what I want to do is to visualize the data in the following way:
name | grade | info
---------------------------------------
parameter1 | 2 | some information
parameter2 | 1 | some information
... | ... | ...
now if I break down each parameter and send it to the device separately it will override the previous one.
How can I make that?
Figured out a way to do this:
Go to 'Widget Bundle' and create a new widget bundle.
Create a new widget of type 'Latest values'.
Here we have CSS/HTML section and a Javascript section.
HTML section:
<div class="my-data-table">
</div>
Javascript section:
self.defaultList = [
{
'id': 1,
'name': 'name 1',
'grade': 123,
'description': 'This is a description'
},
{
'id': 2,
'name': 'name 2',
'grade': 456,
'description': 'More description'
},
{
'id': 3,
'name': 'name 3',
'grade': 789,
'description': 'Even more description'
}
];
self.createTable = function(data) {
const columnNames = Object.keys(data[0]);
let tableHeadContent = $('<tr></tr>');
columnNames.forEach((columName) => {
tableHeadContent.append('<td>' + columName + '</td>');
});
let tableHead = $('<thead></thead>').append(tableHeadContent);
let tableBody = $('<tbody></tbody>');
data.forEach((currentElement, index) => {
const vals = Object.values(currentElement);
let currentRow = $('<tr></tr>');
vals.forEach((val) => {
currentRow.append('<td>' + val + '</td>');
});
tableBody.append(currentRow);
});
return $('<table></table>').append(tableHead).append(tableBody);
}
self.onInit = function() {
let currentList = [...self.defaultList];
if(self.ctx.defaultSubscription.data[0].data.length !== 0) {
currentList = JSON.parse(self.ctx.defaultSubscription.data[0].data[0][1]);
}
let currentTable = self.createTable(currentList);
$('.my-data-table', self.ctx.$container).append(currentTable);
}
self.onDataUpdated = function() {
self.ctx.detectChanges();
}
What you need to pay attention to and understand is self.ctx.defaultSubscription.data, when you visualize your data with a certain widget you subscribe the data to the widget. self.ctx.defaultSubscription.data give you access to the data, you can console.log() it to see how it is structured.
The self.defaultList is for the preview and when you set this widget to a specific data it will use that data.
There may be other way to do this but this is how I did it.
I have the following list with phone numbers:
listofnumbers = ['01225','03933']
and a list of map objects as:
List mapofobjects = [
{
'name': 'John Doe',
'phone': {
'numbers': ['03323', '02333'],
'verified': true
},
'uid': '2BDNDD',
'createdat': 'today..'
},
{
'name': 'Mary Doe',
'phone': {
'numbers': ['03933', '39939'], // matches 03933 in listofnumbers
'verified': true
},
'uid': '1BDNDD',
'createdat': 'today..'
},
{
'name': 'Vincin Doe',
'phone': {
'numbers': ['01225', '59939'], // matches 01225 in listofnumbers
'verified': true
},
'uid': 'XBDNDD',
'createdat': 'today..'
}
];
How can I convert the listofnumbers into a list of map objects using each listofnumbers item as join.
I should get something like this for the listofnumbers of two numbers:
finalList = List mapofobjects = [
{
'name': 'John Doe',
'phone': {
'numbers': ['03323', '02333'],
'verified': true
},
'uid': '1BDNDD',
'createdat': 'today..'
},
{
'name': 'Vincin Doe',
'phone': {
'numbers': ['01225', '59939'],
'verified': true
},
'uid': 'XBDNDD',
'createdat': 'today..'
}
];
With each object matching/replacing a listofnumbers of item when phone['numbers'] contains the item.
You can use two forEach to get this result, like this:
List finallist = [];
listofnumbers.forEach((element) {
mapofobjects.forEach((e) => {
if (e['phone']['numbers'].contains(element))
finallist.add(e)
});
});
print(finallist.length.toString());
the result is: 2
You can do something like this:
final finalList = [
...mapofobjects.where((dynamic object) =>
object['phone']['numbers'].any((phone) => listofnumbers.contains(phone)))
];
finalList.forEach(print);
// {name: Mary Doe, phone: {numbers: [03933, 39939], verified: true}, uid: 1BDNDD, createdat: today..}
// {name: Vincin Doe, phone: {numbers: [01225, 59939], verified: true}, uid: XBDNDD, createdat: today..}
I am working on an adwords script to grab a list of all AD Groups which have a specified label, and are in the status PAUSED. My code is working, however I am running into one issue, which is that I am getting ad groups which belong to campaigns that have been REMOVED.
Is there any way to filter on campaign status as part of the adgroup service?
ad_group_service = client.GetService('AdGroupService', version='v201806')
selector = {
'fields': ['Id', 'Name', 'Status', 'Labels'],
'predicates': [
{
'field': 'Labels',
'operator': 'EQUALS',
'values': 'MY LABEL'
},
{
'field': 'Status',
'operator': 'EQUALS',
'values': 'PAUSED'
}
],
'paging': {
'startIndex': str(0),
'numberResults': str(9999)
}
}
adgroups = ad_group_service.get(selector)
Through testing, I found out there is an undocumented field 'CampaignStatus' that can be used to achieve this.
selector = {
'fields': ['Id', 'Name', 'Status', 'Labels'],
'predicates': [
{
'field': 'Labels',
'operator': 'EQUALS',
'values': 'MY LABEL'
},
{
'field': 'Status',
'operator': 'EQUALS',
'values': 'PAUSED'
},
{
'field': 'CampaignStatus',
'operator': 'NOT_EQUALS',
'values': 'REMOVED'
}
],
'paging': {
'startIndex': str(0),
'numberResults': str(9999)
}
}
I am using webix to show some tree table data.
webix.ready(function () {
grida = webix.ui({
container: "testB",
view: "treetable",
columns: [
{ id: "id", header: "", css: { "text-align": "right" } },
{
id: "SerialNo", header: "Serial No", width: 250,
template: "{common.treetable()} #SerialNo#"
}
],
url: "/Test/GetTreeItem",
autoheight: true,
});
});
This loads the items perfectly.
Parents;
[{"id":11583,"Id":11583,"SerialNo":"12476127654","webix_kids":1},{"id":11584,"Id":11584,"SerialNo":"125235463","webix_kids":1},{"id":11585,"Id":11585,"SerialNo":"21385423348956","webix_kids":1},{"id":11586,"Id":11586,"SerialNo":"253346346346","webix_kids":1},{"id":11587,"Id":11587,"SerialNo":"123123","webix_kids":1},{"id":11588,"Id":11588,"SerialNo":"52354263","webix_kids":1},{"id":11589,"Id":11589,"SerialNo":"12344444","webix_kids":1},{"id":11590,"Id":11590,"SerialNo":"12344444","webix_kids":1},{"id":11591,"Id":11591,"SerialNo":"12344444","webix_kids":1},{"id":11592,"Id":11592,"SerialNo":"151515","webix_kids":1}]
However when I click the plus button, server returns (I can see the json string when I debug the code) the json but webix not appending the data underneath the parent.
Kids of parent "id":11587;
[{"id":11583,"Id":11583,"SerialNo":"12476127654","webix_kids":1},{"id":11592,"Id":11592,"SerialNo":"151515","webix_kids":1}]
id of data object must be unique per component.
Currently, you have for top level
{
"id": 11583,
"Id": 11583,
"SerialNo": "12476127654",
"webix_kids": 1
},
and in kids data you have
{
"id": 11583,
"Id": 11583,
"SerialNo": "12476127654",
"webix_kids": 1
},
both items share the same id, so treetable doesn't add a new item.
Correcting the JSON output solved my problem.
For the parents;
{
"parent":"0",
"data":[
{
"Id":11584,
"id":11584,
"SerialNo":"125235463",
"webix_kids":1
},
{
"Id":11599,
"id":11599,
"SerialNo":"3444",
"webix_kids":1
}
]
}
For the kids;
{
"parent":11599,
"data":[
{
"id":11583,
"Id":11583,
"SerialNo":"12476127654",
"webix_kids":1
},
{
"id":11592,
"Id":11592,
"SerialNo":"151515",
"webix_kids":1
}
]
}