I have a scenario like below, need to get the 'Application' label vertex properties and also, the id or property of the 'work' vertex that is connected to it
I have written the gremlin glv query to get the path and the Application properties, but struggling to get the properties of the vertex connected to it, (using pyton)
the query is,
g.V().hasLabel('Company').outE().inV().hasLabel('Person').outE().inV().hasLabel('Work').outE().inV().hasLabel('Applications').path().unfold().dedup().filter('Applications').elementMap().toList()
this return me the application vertex values like
[{
id:'12159',label:'Applications', 'applicationname':'application1'
},
{
id:'12157',label:'Applications', 'applicationname':'application2'
},
{
id:'12155',label:'Applications', 'applicationname':'application3'
}
]
but we need to get the 'work' vertex details also along with the application details (applications can be connected to multiple work), like,
{
id:'12159',label:'Applications', 'applicationname':'application1', 'workcode':['workcode1', 'workcode2']
},
{
id:'12157',label:'Applications', 'applicationname':'application2', 'workcode':['workcode2']
}.
{
id:'12157',label:'Applications', 'applicationname':'application3', 'workcode':['workcode2']
}
is it possible to get this information in gremlin itself or do we need to use python after getting the path,
the query to add is,
g.addV('Company').as('1').
addV('Company').as('2').
addV('Person').as('3').
addV('Work').as('4').
property(single, 'workcode', 'workcode2').
addV('Work').as('5').
property(single, 'workcode', 'workcode1').
addV('Application').as('6').
property(single, 'applicationname', 'application3').
addV('Application').as('7').
property(single, 'applicationname', 'application2').
addV('Application').as('8').
property(single, 'applicationname', 'application1').
addE('Contractor').from('2').to('3').
addE('Contractor').from('1').to('3').
addE('work').from('3').to('5').addE('work').
from('3').to('4').addE('workingon').from('4').
to('7').addE('workingon').from('4').to('6').
addE('workingon').from('5').to('8').
addE('workingon').from('4').to('8')
thank you
I don't think you should use path step since you are only using the last vertex.
If you want to merge the element map with property from another vertex you can use project:
g.V().hasLabel('Company').outE().inV().
hasLabel('Person').outE().inV().
hasLabel('Work').outE().inV().
hasLabel('Application').dedup().local(union(
elementMap().unfold(),
project('workcose').
by(in().hasLabel('Work').
values('workcode').fold())
).
fold())
example: https://gremlify.com/d5wsk80nm2t/1
Related
I want to duplicate my GLTF models with different positions/colors dynamically, to do so I have done:
const L_4_G = new Object3D();
...
const multiLoad_4 = (result, position) => {
const model = result.scene.children[0];
model.position.copy(position);
model.scale.set(0.05, 0.05, 0.05);
//
L_4_G.add(model.clone())
scene.add(model);
};
...
function duplicateModel4() {
L_4_G.translateX(-1.2)
L_4_G.translateY(0.0)//0.48
L_4_G.translateZ(1.2)
L_4_G.rotateY(Math.PI / 2);
scene.add(L_4_G);
}
I didn't find out how can I change the Object3D color from the documentation, can you please tell me how can I do that? thanks in advance.
Here is the full code that I'm using, and here are the models
Update
I have seen this solution, to store a set of colors in the object's userData and choose the color later:
L_2_G.userData.colors = {green : #00FF00, red : ..., ...}
L_2_G.children[0].material.color(userData.colors["green"])
But I'm getting an error that children[0] undefined, but I can see that this object has a child and a material, and color via the console: console.log(L_2_G.children), console.log(L_2_G.children.length)--> 0
Also I have tried getObjectByName as explained here:
scene.getObjectByName(name).children[0].material.color.set(color);
which also reslts: children[0] is undefined, scene.getObjectByName(name).children.length is 0.
THREE.Object3D is a base class for anything that can go in a scene graph, including lights, cameras, and empty objects. Not all Object3D instances have geometry or materials. You may be looking for the THREE.Mesh subclass which does have materials and colors.
In general, code like getObjectByName(...) and model = result.scene.children[0] is very content-specific. The file might contain many nested objects, and .children[0] just grabs the first part. It's usually best to traverse the scene graph instead, looking for the objects you want to modify (e.g. looking for all Meshes, or Meshes with a particular name).
const model = result.scene;
model.traverse((object) => {
if (object.isMesh) {
object.material.color.setHex( 0x404040 );
}
});
Then you can either add the entire group to your scene (scene.add(model)), or just add parts of it. Keep in mind that adding meshes to a new parent removes them from their previous parent, and you shouldn't do that while traversing the previous parent. Instead you can make a list of meshes, and add them in a second step:
const meshes = [];
result.scene.traverse((object) => {
if (object.isMesh) {
meshes.push(object);
}
});
for (const mesh of meshes) {
scene.add(mesh);
}
Finally, the position of an object is inherited from its parents. By removing the object from its original parents you might change its position in the scene. If you are planing to assign a new position to the object anyway, that is fine.
I am working with Cosmos DB and I want to write a SQL query that returns different name of an key in document object.
To elaborate, imagine you have the following document in one container having "makeName" key in "make" object.
{
"vehicleDetailId":"38CBEAF7-5858-4EED-8978-E220D2BA745E",
"type":"Vehicle",
"vehicleDetail":{
"make":{
"Id":"B57ADAAD-C16E-44F9-A05B-AAB3BF7068B9",
"makeName":"BMW"
}
}
}
I want to write a query to display "vehicleMake" key in place of "makeName".
How to give alias name in the nested object property.
Output should be like below
{
"vehicleDetailId":"38CBEAF7-5858-4EED-8978-E220D2BA745E",
"type":"Vehicle",
"vehicleDetail":{
"make":{
"Id":"B57ADAAD-C16E-44F9-A05B-AAB3BF7068B9",
"vehicleMake":"BMW"
}
}
}
I have no idea how to query in Cosmosdb to get the above result.
Aliases for properties are similar to the way you'd create a column alias in SQL Server, with the as keyword. In your example, it would be:
SELECT c.vehicleDetail.make.makeName as vehicleMake
FROM c
This would return:
[
{
"vehicleMake": "BMW"
}
]
Try this:
SELECT c.vehicleDetailId, c.type,
{"make":{"Id":c.vehicleDetail.make.Id, "vehicleMake":c.vehicleDetail.make.makeName}} as vehicleDetail
FROM c
It uses the aliasing described in the following documentation. All of the aliasing examples I could find in the documentation or blog posts only show a single level of json output, but it happens that you can nest an object (make) within an object (vehichleDetail) to get the behavior you want.
https://learn.microsoft.com/en-us/azure/cosmos-db/sql-query-aliasing
I'm trying to get data from another table using a cloud function and it's telling me the snapshot is null.
I have a Firebase database that I have some IoT devices connected to. They update their respective tables(I hope that's the right word) in the database (device_001, device_002, device_003) and send on to the external API I am using, that works which are great.
Now I need to get the devices to look up where they are, I have set up another table which each contain their id, location, and timestamp.
Lookup table structure:
devices
device_001
id: ...
location: ...
timestamp: ...
Code:
exports.devices_Listener = functions.database.ref('/devices/{deviceId}/{entryId}').onWrite(snapshot => {
object = snapshot.after.val();
getCurrentLocation();
process();
return null
})
function getCurrentLocation() { functions.database.ref('locations/{deviceId}').limitToLast(1).once('value').then(function(snapshot) {
var o = snapshot.val();
})
}
I expected this to get the snapshot and allow me to get the location so I can store it with the processed data (that's all working so not included here).
When I try to get the location field I get can't read the property 'location'
and when I try to just log the snapshot to the console it tells me it is null.
I can't see what I've done wrong here but I'm sure it's small and simple.
Thanks for taking the time to read this nonsensical mess.
Consider following Employee document structure
{
"_id":...,
"rev":...,
"type":"Employee",
"fName":...,
"lName":...,
"designation":...,
"department":...,
"reportingTo":...,
"isActive":..,
more attributes
more attributes
}
And following map function in a View named "Employee"
function(doc) {
if (doc.type=="Employee") {
emit({
"EID":doc._id,
"FirstName":doc.fName,
"LastName":doc.lName,
"Designation":doc.designation,
"Department":doc.department,
"ReportingTo":doc.reportingTo,
"Active":doc.isActive
},
null
);
}
};
I want to query this view based on any combination & order of emitted attributes ( a query may include few random attributes may be like duck typing ). Is it possible? If so kindly let me know some samples or links.
Thanks
I've ran into the same problem a few times; you can, but you'll have to index each by itself (not all in one hash like you've done). But you could through the whole thing in the value for emit. It can be fairly inefficient, but gets the job done. (See this link: View Snippets)
I.e.:
function(doc) {
if (doc.type=="Employee") {
emit(["EID",doc.values.EID], doc.values);
emit(["FirstName", doc.fName], doc.values);
emit(["LastName", doc.lName], doc.values);
emit(["Designation", doc.designation], doc.values);
emit(["Department", doc.department], doc.values);
emit(["ReportingTo", doc.reportingTo], doc.values);
emit(["Active", doc.isActive], doc.values);
}
}
This puts all "EID" things in the same part of the tree, etc., I'm not sure if that is good or bad for you.
If you start needing a lot of functionality with [field name:]value searches, its probably worth it to move towards a Lucene-CouchDB setup. Several exist, but are a little immature.
I'm using mongodb to store application error logs as json documents. I want to be able to format the error logs as HTML rather than returning the plain json to the browser. The logs are properly schemaless - they could change at any time, so it's no use trying to do this (in Jade):
- var items = jsonResults
- each item in items
h3 Server alias: #{item.ServerAlias}
p UUID: #{item.UUID}
p Stack trace: #{item.StackTrace}
h3 Session: #{item.Session}
p URL token: #{item.Session.UrlToken}
p Session messages: #{item.Session.SessionMessages}
as I don't know what's actually going to be in the JSON structure ahead of time. What I want is surely possible, though? Everything I'm reading says that the schema isn't enforced by the database but that your view code will outline your schema anyway - but we've got hundreds of possible fields that could be removed or added at any time so managing the views in this way is fairly unmanageable.
What am I missing? Am I making the wrong assumptions about the technology? Going at this the wrong way?
Edited with extra info following comments:
The json docs look something like this
{
"ServerAlias":"GBIZ-WEB",
"Session":{
"urltoken":"CFID=10989&CFTOKEN=f07fe950-53926E3B-F33A-093D-3FCEFB&jsessionid=84303d29a229d1",
"captcha":{
},
"sessionmessages":{
},
"sessionid":"84197a667053f63433672873j377e7d379101"
},
"UUID":"53934LBB-DB8F-79T6-C03937JD84HB864A338",
"Template":"\/home\/vagrant\/dev\/websites\/g-bis\/code\/webroot\/page\/home\/home.cfm, line 3",
"Error":{
"GeneratedContent":"",
"Mailto":"",
"RootCause":{
"Message":"Unknown tag: cfincflude.",
"tagName":"cfincflude",
"TagContext":[
{
"RAW_TRACE":"\tat cfhome2ecfm1296628853.runPage(\/home\/vagrant\/dev\/websites\/nig-bis\/code\/webroot\/page\/home\/home.cfm:3)",
"ID":"CFINCLUDE",
"TEMPLATE":"\/home\/vagrant\/dev\/websites\/nig-bis\/code\/webroot\/page\/home\/home.cfm",
"LINE":3,
"TYPE":"CFML",
"COLUMN":0
},
{
"RAW_TRACE":"\tat cfdisplay2ecfm1093821753.runPage(\/home\/vagrant\/dev\/websites\/nig-bis\/code\/webroot\/page\/display.cfm:6)",
"ID":"CFINCLUDE",
"TEMPLATE":"\/home\/vagrant\/dev\/websites\/nig-bis\/code\/webroot\/page\/display.cfm",
"LINE":6,
"TYPE":"CFML",
"COLUMN":0
}
]
}
}
... etc, but is likely to change depending on what the individual project that generates the log is configured to trigger.
What I want to end up with is a formatted HTML page with headers for each parent and the children listed below, iterating right through the data structure. The Jade sample above is effectively what we need to output, but without hard-coding that in the view.
Mike's analysis in the comments of the problem being that of creating a table-like structure from a bunch of collections that haven't really got a lot in common is bang-on. The data is relational, but only within individual documents - so hard-coding the schema into anything is virtually impossible as it requires you to know what the data structure looks like first.
The basic idea is what #Gates VP described. I use underscore.js to iterate through the arrays/objects.
function formatLog(obj){
var log = "";
_.each(obj, function(val, key){
if(typeof(val) === "object" || typeof(val) === "array"){
// if we have a new list
log += "<ul>";
log += formatLog(val);
log += "</ul>";
}
else{
// if we are at an endpoint
log += "<li>";
log += (key + ": " + val);
log += "</li>";
}
});
return log;
}
If you call formatLog()on the example data you gave it returns
ServerAlias: GBIZ-WEBurltoken: CFID=10989&CFTOKEN=f07fe950-53926E3B-F33A-093D-3FCEFB&jsessionid=84303d29a229d1sessionid: 84197a667053f63433672873j377e7d379101UUID: 53934LBB-DB8F-79T6-C03937JD84HB864A338Template: /home/vagrant/dev/websites/g-bis/code/webroot/page/home/home.cfm, line 3GeneratedContent: Mailto: Message: Unknown tag: cfincflude.tagName: cfincfludeRAW_TRACE: at cfhome2ecfm1296628853.runPage(/home/vagrant/dev/websites/nig-bis/code/webroot/page/home/home.cfm:3)ID: CFINCLUDETEMPLATE: /home/vagrant/dev/websites/nig-bis/code/webroot/page/home/home.cfmLINE: 3TYPE: CFMLCOLUMN: 0RAW_TRACE: at cfdisplay2ecfm1093821753.runPage(/home/vagrant/dev/websites/nig-bis/code/webroot/page/display.cfm:6)ID: CFINCLUDETEMPLATE: /home/vagrant/dev/websites/nig-bis/code/webroot/page/display.cfmLINE: 6TYPE: CFMLCOLUMN: 0
How to format it then is up to you.
This is basically a recursive for loop.
To do this with Jade you will need to use mixins so that you can print nested objects by calling the mixin with a deeper level of indentation.
Note that this whole thing is a little ugly as you won't get guaranteed ordering of fields and you may have to implement some logic to differentiate looping on arrays vs. looping on JSON objects.
You can try util.inspect. In your template:
pre
= util.inspect(jsonResults)