fetch geometries of a composite object - autodesk-forge

How can one fetch geometries of composite objects?
Steps :
Load a model in viewer.
Select an composite-object(icon: Composite Object, dbid: 1234) of viewer.
Now, How can I get geometries(icon: Geometry) of this composite objects?
Note: The current solution I have is to iterate the following ids incrementally until I find a next composite-object, which is generally the case.
json-file for properties

It seems you want to search for elements where displayName=="Icon" and displayValue=="Composite Object". If so, I would suggest:
viewer.search('"Composite Object"', onSuccessCB, onFailCB, ['Icon']);
This will search and the onSuccessCB function will receive an array of dbIds that matches the criteria.

Related

NEO4j Return a nested, hierarchical JSON from a DB

I have a Tree Model on db like it's shown on the picture
City node is linked to Region node by IS_A_City_BELONGING_TO
Sector node is linked to Region node by IS_A_SECTOR_BELONGING_TO_THAT_REGION
Sector node is linked to City node by IS_A_SECTOR_BELONGING_TO_THAT_CITY
The hierarchical nested json ideal output is as follows
Indexes
ON :TTL(ttl) ONLINE
ON :City(cityName) ONLINE (for uniqueness constraint)
ON :Region(region) ONLINE (for uniqueness constraint)
ON :Sector(sectorName) ONLINE (for uniqueness constraint)
Constraints
ON ( city:City ) ASSERT city.cityName IS UNIQUE
ON ( region:Region ) ASSERT region.region IS UNIQUE
ON ( sector:Sector ) ASSERT sector.sectorName IS UNIQUE
How to generate the json file from db using cypher request.
THANK YOU very much.
So... Your Hierarchy is kinda hard to read... so I'll focus on the JSON response part. While Neo4j doesn't have Map as a property type, it is valid inside Cypher.
To aggregate results into a map, you can use this format
MATCH (c:City)<--(s:Sector)
RETURN {city_node:c, city_properties:PROPERTIES(c) name:c.name, sectors:COLLECT(s)} as city
Basically {} as varname defines your map, and the contents of {} define the key-value pairs.
And you can merge 2 maps with the + operator like WITH map1 + map2 as mymap. In the case of conflict, the value in the second map takes priority.
If you only want the properties of a node, and not the whole node, you can use the PROPERTIES(c) function instead of passing in the node.
One thing you will quickly notice, is this will not work recursively. It looks like in your case, it's fixed at 2 nest levels deep. So that limitation shouldn't be a problem.
On a side note, if this is meant to scale, you may want to make your Cypher paged (LIMIT+SKIP) to improve response times. (Only return what you need as you need it) On that note, it may be better to aggregate this client side, as you will probably be returning some sectors frequently for each city.

clojure.data.json/write-str: specifying a key function for placing values into aggregate arrays

Suppose I have a simple map, example-map:
(def example-map {"s" {"f" "g"}
"m" {"r" "q"}})
I can use clojure.data.json/write-str to JSON-ify this map as such:
(clojure.data.json/write-str example-map) =>
"{\"s\":{\"f\":\"g\"},\"m\":{\"r\":\"q\"}}"
I'd like to conditionally place some of the values into lists according to the value of their keys.
write-str provides an optional :key-fn, which applies some function to key value pairs. For example, the desired function might specify that all values associated with entries that match "s" are placed in lists.
(clojure.data.json/write-str example-map :key-function desired-function) =>
"{\"s\":[{\"f\":\"g\"}],\"m\":{\"r\":\"q\"}}"
Does anyone know how to specify such a key function that checks for membership of a key in a set and places the values associated with members into an array rendered in the output JSON?
Like your previous question, this is not a job for the JSON parser. You don't need to rely on write-time features of your JSON library to adjust the shape of your JSON maps. Instead, you have a fully functional Turing complete language at your disposal: Clojure! If the maps don't already look the way you want them to be output, then write a function that takes one Clojure map as input and produces a different one as output; then ask your JSON library to write the output map, without any special rules for fiddling with the output.
Now, as it happens this particular JSON library does provide an option named value-fn (not key-function as you claim) to let you modify a value in a map based on its key. So you could use that, in which case you simply need to write a function with a signature like:
(fn [k v]
(...compute new value...))
There are many ways you could write such a function, but they are all entirely divorced from your JSON parser. If you need help writing it, mention some specific things you need help with, so you can get a clear explanation for the part of the process that is actually giving you trouble.

Change resultset structure elasticsearch

is it possible to change the resultset structure when retrieving data from elastic search?
the problem ist, the timeseries data are sometimes from 3000-8000 records which are a json array with json objects in it ... parsing it in this case not really efficient or necessary so i thought - could a resultset be transformed to just lets say a simple json object with an array of time and array of values? nothing more?
i could do this in java or php but since we want to have an efficent way of dealing with large datasets we are currently evaluating our options.
You can control what elasticsearch returns using source filtering:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html
It can let you pick which part of the indexed document it will return, which, depending on your index structure could be an array of times and values, or at least, very easily mapped to it using the language of your choice.
Another possibility is to use scripting to control the results. If you map the result in this way, you should be able to get the hits object to be a JSON array of key: value.

JSON members order in ActionScript 3.0

I'm using built-in functionality to create JSON string in Flash app.
Here example of my source code
objStr = JSON.stringify(
{
version:"1.0",
skin:"white",
palette:{dataColor:"#0397d6",negativeDataColor:"#d40000",toolbarColor:"#056393"}
});
I have a problem. Every time I've started my app (not executing createJSON function), I have different member order in JSON string as result.
For example:
{"version":"1.0","palette":{"negativeDataColor":"#d40000","dataColor":"#0397d6","toolbarColor":"#056393"},"skin":"white"}
or
{"palette":{"negativeDataColor":"#d40000","toolbarColor":"#056393","dataColor":"#0397d6"},"version":"1.0","skin":"white"}
How can I fix it.
JSON objects are unordered, see JSON.org:
JSON is built on two structures:
A collection of name/value pairs. In various languages, this is
realized as an object, record, struct, dictionary, hash table, keyed
list, or associative array. An object is an unordered set of name/value pairs
An ordered list of values. In most languages, this is realized as an
array, vector, list, or sequence. An array is an ordered collection of values.
Order really doesn't matter since you should be retrieving the values by the key rather than iterating over them.

Best way to map Object ID References?

I'm writing an application where I have many objects (data models) that are identified by a unique String ID that every such object possesses and these objects can refer to each other by their IDs.
So far so good but now I need to keep track of which object keeps a reference to another object and of course there are cases where an object references (or is referenced by) more than one other object and I was wondering what would be the best method to store these references? In a simple map data structure I could just map one object's ID to another but as mentioned there are cases where an object can hold a ref to an arbitrary amount of other objects. Or I could map another map or an Array that hold more than one reference but I'd like to prevent iteration and maybe somebody knows a much better solution for this.
I guess it depends a lot in the particular use, but I think a Dictionary is the way to go, unless you need the order of the references, in which case I think an Array (or Vector) should work...
//Array:
object1.references.push(object2);
for each(var o in object1.references) trace(o);
object1.references.pop();
//Dictionary:
object1.references[object2] = 1;
for (var o in object1.references) trace(o);
delete object1.references[object2];
Whenever you have a dynamic arbitrary set of objects, I think you will necessarily need to iterate through them, whether its an array, object or dictionary.