I have a Siddhi extension that return the next information for example:
{
"licenseKey": "WxyzChXjhJ-dgjfZfHnL9-bWd4e2vxjD-eIs5hDu0To-VOxL111BAj",
"siteUrl": "http://www.URL.net/",
"clientPublicId": "CLIENT1",
"host": "www.urlclient.net"
}
{
"licenseKey": "WxyzChXjhJ-dgjfZfHnL9-bWd4e2vxjD-eIs5hDu0To-VOxL111BAj",
"siteUrl": "http://www.URL2.net/",
"clientPublicId": "CLIENT2",
"host": "www.urlclient2.net"
}
I want store this information in a Stream and I want filter information using the atribute "clientPublicId".
I am using the next code, wlist:whitelist() is my extension Siddhi.
from sensorStream[temperature>98.6]
select wlist:whitelist() AS arreglo
insert into outputStream;
My problem is that outputStream is created with an attribute named "arreglo", so I cant filter by clientPublicId.
Can you help me, please.
If you want to process JSON or XML in Siddhi, Then you can use 'map' extension support in Siddhi for this. You can create a map using map:createFromJSON(<string> JSONstring) and then access the values via map:get(<Map> map, <Object> key). Note you have to cast the output of the map before using it, with cast(<object> toBeCasted, <string> castTo).
E.g : cast(map:get(dataMap, 'clientPublicId'),'string')
Hope this fixes the issue.
Related
I am creating an Azure deployment that will be used across the various regions. I am trying to keep the code agnostic to region and provide region specific info via a JSON file.
The JSON file will have the format of
{
"region1":
{
"key" : "value"
},
"region2":
{
"key" : "value"
}
}
I would like to import the JSON at deployment time and use the values for a specific region by taking an input of the target region to be deployed and storing it in the parameter called region. I then want to use the region parameter to index into the JSON object like the example below:
param _regions object = json(loadTextContent('<json_file_name>'))
param region string
var regionProperty = _regions.${region}.key
Using the syntax above for indexing into the JSON does not work, does anyone have ideas on how I can make this work?
Looking at the documentation:
You can use the [] syntax to access a property.
var regionProperty = _regions[region].key
I'm trying to find out which telemetry-producing sensors (aka singals/time series') are attached to a device using the REST API. The deviceTemplates endpoint has all this information but there is no JSON schema for it's response anywhere. The responses are highly variable and hard to parse. I need a robust solution for any kind of device.
Any help/advice? Could the IoT Hub SDK help?
I would recommend using Json.Net Schema framework. It lets you determine your own custom JSON schema that would fit your needs.
Please refer the following documentation that helps you on how to Load your schema. Once you have the schema determined you can validate it against a device template and confirm if it follows the same pattern.
You can then parse the JSON file using Json.Net to extract the data you may need. Here is sample of the code that extracts contents from a device template. I have used "RS40 Occupancy Sensor.json" device template in my case.
public static void LoadJson()
{
using (StreamReader r = new StreamReader(#"Path to your JSON device template file"))
{
string json = r.ReadToEnd();
try
{
dynamic? array = JsonConvert.DeserializeObject(json);
if (array != null)
{
foreach (var item in array)
{
var contents = item.contents;
//filter contents to get telemetry data or other information
}
}
}
catch (Exception ex) { Console.WriteLine(ex); }
}
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
To access a unique identifier for Bixby, I'm trying to access the contactId field within the contact library (which is also viv.self I think?). I tried using the code snippet found in the docs here, but I'm getting some errors.
Code Snippet (Source)
text (Name) {
extends (contact.StructuredName)
}
Errors
ERROR: invalid capsule alias contact
ERROR: unknown super-type: contact.contactId
I would ultimately like to do something like this
integer (Identifier) {
extends (contact.ContactId)
}
Would appreciate any help on accessing this data!
I ended up finding another way to get a device identifier from these docs. There's also a sample capsule here.
In your corresponding JavaScript file, access the $vivContext.locale parameter to return the locale information.
module.exports.function = function accessVivContext (dummyInput, $vivContext) {
var result = "Testing Access vivContext..."
// See docs for all the properties of $vivContext
result = $vivContext.userId
return result
}
You would then need to configure your endpoints for this action like below, including making sure that you set up the proper accepted-inputs for your endpoint:
action-endpoint (AccessVivContext) {
accepted-inputs (dummyInput, $vivContext)
local-endpoint ("AccessVivContext.js")
}
I'm working on a Photoshop script in JavaScript using ExtendScript. My script allows some user input, and I'd like to save it between uses. That is, I'm looking for a way to save a simple string or numeric value under a particular key so that I'll be able to access it on subsequent uses of the script. Simply put, I want to save a preference for my script. How do I do that?
Even better would be to be able to save at least some preferences on a per-document basis. Is that possible? That is, can I store an arbitrary bit of data with a document?
You can use put/get custom options to save preference parameters that persist across Photoshop launches:
const kMyFlag = app.stringIDToTypeID( "myFlag" );
const kMyNumber = app.stringIDToTypeID( "myNumber" );
const kMySettings = "mySettings";
function saveSettings()
{
var desc = new ActionDescriptor();
desc.putBoolean(kMyFlag, true);
desc.putInteger(kMyNumber, 42);
// "true" means setting persists across Photoshop launches.
app.putCustomOptions( kMySettings, desc, true );
}
function getSettings()
{
var desc = app.getCustomOptions( kMySettings );
return [desc.getBoolean( kMyFlag ), desc.getInteger( kMyNumber )];
}
You have some options. You can create a text file and write to it using the File object:
var prefs = new File("~/desktop/prefs.txt");
prefs.open("w"); // or "a" to append
prefs.writeln("user:lenny;favorite_color:ff6600;likes:sunsets;");
...if you wanted your preferences tied to the script itself.
If you want per-document preferences you could write a string to one of the metadata fields of the file your working on using Document.info like this (using the 'instructions' field but you could use any writable field):
var doc = app.activeDocument;
doc.info.instructions = "user:lenny;favorite_color:ff6600;likes:sunsets;";
//alert(doc.info.instructions); // see, it works!
As for how to actually format the string you could just do it like a simple config file or, if you have a complex user preferences object you could use the XML object to construct and serialize it. JSON would be great for this but there is no JSON object in Extendscript, unfortunately.
For per-document prefs I suggest the use of the XMP Metadata. You can find example snippet here: http://forums.adobe.com/thread/790973. You can leverage AdobeXMPScript library to create your own namespace like it is suggested in the link by Paul Riggott.