Add custom metadata to highchart series - highcharts

I am plotting trends for which data is coming from different SQL servers.
This is the JSON I receive,
{
"tag": "Temperature01",
"server": "SQL01",
"data": [
{
"time": 1377003660000,
"value": 10.1
},
{
"time": 1377003760000,
"value": 10.2
}
.
.
.
.
]
}
I use tag for series name and data for series data.
I need to be able to store server property to the series. How do I do that ?
The series is added dynamically.

Use something like this:
var data = {
"tag": "Temperature01",
"server": "SQL01",
"data": [ .. ]
}; //received from AJAX
chart.addSeries({
data: someData,
name: data.tag,
server: data.server
});
Then you have access to this option via series.options.server.

Related

Avro Records with Unknown Key Names and Quantity but Known Values

I am looking to convert JSON to Avro without altering the shape of the data
A nested field in the JSON contains a variable number of keys, which are never known in advance. The record that branches off of each of these unknown nodes however is of known, well-defined shape.
An example of this input data is as shown below
{
"customers": {
"paul_ince": {
"name": "Mr Paul Ince",
"age": 54
},
"kim_kardashian": {
"name": "Ms Kim Kardashian",
"age": 41
},
"elon_musk": {
"name": "Elon Musk, Technoking of Tesla",
"age": 50
}
}
Now it would be more avro friendly of course to have customers lead to an array of the form
{
"customers": [
{
"customer_name": "paul_ince",
"name": "Mr Paul Ince",
"age": 54
},
{
...
}
]
}
But this would violate my constraint that the shape of the input data be unchanged.
This problem seems to manifest itself frequently if I rely on data from external sources or scrapes, or preexisting data that was never created for Avro.
In my head, the schema would look something like the below,
{
"fields": [
{
"name": "customers",
"type": {
"type": "record",
"name": "customers",
"fields": [
{
"name": $customer_name,
"type": {
"type": "record",
"name": $customer_name,
"fields": [
{
"name": "name",
"type": "string",
},
{
"name": "age",
"type": "int"
}
]
}
}
]
}
}
]
}
where $customer_name is an assignment value, defined on read. Just asking the question it feels like this violates fundamental avro but I must use Avro and I strongly desire to maintain the input shape of the data. It would be highly impractical to modify this, not least given how frequently this problem appears and how large and varied the data I need to transfer from JSON to Avro is

Graph Pagination in Logic Apps

I'm trying to fetch all users from a specific group via an HTTP connector, a registered app, and Microsoft Graph.
The registered app has Directory.Read.All permissions.
My idea is that I'm calling the nextLink as long as it's there while appending all of the fetched users' userPrincipalName to an array eventually filling the array with all users of the group.
My Logic App looks like this:
Unfortunately, I'm just 1 reputation short of posting images, please forgive. The 3 links should provide an overview of the structure of my app.
First, nextLink is initialized to the first Graph API endpoint. This variable is set to the current nextLink through each iteration of the until loop.
Second, For the purpose of this exercise, I only get the top 5. I know there are only 9 users:
Lastly, I call the union method on the "users" array that I initialized earlier and the "value" array from the HTTP get method, to get one single array consisting of all users:
The issue is that the HTTP action always returns the same top 5 users. I've checked that the nextLink provided in the first HTTP GET call to Graph, is correct by copying it from the Runs history and pasting it into Microsoft Graph Explorer and there the next 4 users are correctly returned.
I also made sure that, for each iteration in the until loop, I call the Graph API with the nextLink from the previous iteration as expected.
The nextLink returned inside of the Logic App is exactly the same when I test it in Graph Explorer, but the same nextLink returns 2 different results when called from Graph Explorer and inside my Logic App.
Why is the result always the same top 5 users and not the next 4 users as expected?
If not sure about the reason why you will get this issue, but based on your requirement, I did a sample below:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "GetGroupUrl",
"type": "string",
"value": "https://graph.microsoft.com/v1.0/groups/<your group id>/members?$select=userPrincipalName&$top=5"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Initialize_variable_2": {
"inputs": {
"variables": [
{
"name": "users",
"type": "array"
}
]
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Until": {
"actions": {
"Compose": {
"inputs": "#union(variables('users'),body('HTTP')['value'])",
"runAfter": {
"HTTP": [
"Succeeded"
]
},
"type": "Compose"
},
"HTTP": {
"inputs": {
"authentication": {
"audience": "https://graph.microsoft.com",
"clientId": "<app id>",
"secret": "<app secret>",
"tenant": "<your secret>",
"type": "ActiveDirectoryOAuth"
},
"method": "GET",
"uri": "#variables('GetGroupUrl')"
},
"runAfter": {},
"type": "Http"
},
"Set_variable": {
"inputs": {
"name": "GetGroupUrl",
"value": "#{if(equals(body('HTTP')?['#odata.nextLink'], null),null,body('HTTP')['#odata.nextLink'])}"
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "SetVariable"
}
},
"expression": "#equals(variables('GetGroupUrl'), '')",
"limit": {
"count": 60,
"timeout": "PT1H"
},
"runAfter": {
"Initialize_variable_2": [
"Succeeded"
]
},
"type": "Until"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"method": "GET",
"schema": {
"properties": {
"text": {
"type": "string"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
You can just replace the params with your own and paste it into your logic app code view and test it .
It works for me, as you can see , each request results are different :
Hope it helps .
This issue solved by OP self, this issue is due to queries in request URL , copy OP's comment as an answer :
After fiddling a bit more around with what each of you providing I
found a solution. It seems that when the query arguments are passed to
the HTTP GET outside of the endpoint itself (meaning in the "queries"
field inside of the block) it seems to keep overriding the nextLink.
When writing the endpoint URL out entirely with the odata parameters,
it works as intended.

InfluxDB write points with same timestamp but different measurement

Requirement:
I want to create an influxDB database to store time-series data from multiple sensors reporting temperatures from different locations.
Problem:
When I write points to the database with same timestamp but different tags (example : location) and field (temperature) value , influx overwrites both tags and fields values with the latest timestamp
I followed the documentation available on their website and they show a sample db with above requirement but am not able find the schema used.
Example Table with duplicate timestamps
Additional Information :
Sample Input :
json_body_1 = [
{
"measurement": "cpu_load_short",
"tags": {
"host": "server02",
"region": "us-west"
},
"time": "2009-11-10T23:00:00Z",
"fields": {
"Float_value": 0.7,
"Int_value": 6,
"String_value": "Text",
"Bool_value": False
}
},
{
"measurement": "cpu_load_short",
"tags": {
"host": "server01",
"region": "us-west"
},
"time": "2009-11-10T23:00:00Z",
"fields": {
"Float_value": 1.0,
"Int_value": 2,
"String_value": "Text",
"Bool_value": False
}
}]
I used the example given in official documentation , still instead of 2 records , I get only one. Please note host tag is different which should ideally make each point unique.
Documentation
Today I too faced the same issue and now I come to the solution. :)
from influxdb import InfluxDBClient
client = InfluxDBClient(host='host name', port=8086, database='test_db',username='writer', password=Config.INFLUXDB_WRITE_PWD)
points = [{
"measurement": "cpu_load_short",
"tags": {
"host": "server02",
"region": "us-west"
},
"time": "2009-11-10T23:00:00Z",
"fields": {
"Float_value": 0.7,
"Int_value": 6,
"String_value": "Text",
"Bool_value": False
}
},
{
"measurement": "cpu_load_short",
"tags": {
"host": "server01",
"region": "us-west"
},
"time": "2009-11-10T23:00:00Z",
"fields": {
"Float_value": 1.0,
"Int_value": 2,
"String_value": "Text",
"Bool_value": False
}
}]
status = client.write_points(json_body_1, database='test_db', batch_size=10000, protocol='json')
Here is the output
> select * from cpu_load_short;
name: cpu_load_short
time Bool_value Float_value Int_value String_value host region
---- ---------- ----------- --------- ------------ ---- ------
1257894000000000000 false 1 2 Text server01 us-west
1257894000000000000 false 0.7 6 Text server02 us-west

Get the exact highcharts data which was used to render a chart

Is there any way in High Charts to get the exact data which was used to render a chart?
I have already tried using "options" but it returns the whole JSON structure. I only need the data with which the chart was rendered.
{
"chart": {
"marginRight": 80
},
"xAxis": {
"categories": [
"Jan",
"Feb"
],
"title": {
"text": "xAxisName"
}
},
"series": [
{
"data": [
29.9,
71.5
]
},
{
"data": [
144,
176
]
}
]
}
For example, if I had rendered a chart using the above object, I need to retrieve the same object after the chart has rendered.
You can get those options via chart.userOptions.
http://jsfiddle.net/zd3q8t2L/

PouchDB not able to insert multiple json files

I am trying to store 3 different JSON Object's using PouchDB,
devices.json:
[
{"id":"001","name":"iPhone","brand":"Apple","tags":["Apple","IOS"],"os":"IOS","Description":"...."},
{"id":"002","name":"galaxy","brand":"Samsung","tags":["Samsung","android"],"os":"android","Description":"...."},
{"id":"003","name":"nexus","brand":"Google","tags":["Google","android"],"Description":"...."},
{"id":"004","name":"galaxy
s4","brand":"Samsung","tags":["Samsung","android"],"os":"android","Description":"...."}
]
brand.json:
[
{ "id": "001", "name": "Apple" },
{ "id": "002", "name": "Samsung" },
{ "id": "003", "name": "Google" } ]
And tags.json as
[
{ "id": "001", "name": "Apple" },
{ "id": "002", "name": "Samsung" },
{ "id": "003", "name": "Google" },
{ "id": "004", "name": "IOS" },
{ "id": "005", "name": "android" } ]
Here when i am inserting using db.bulkDocs() devices.json it's creating 7 tables in one database. Now am trying the same function to insert brands.json & tags.json. But its not able to insert to database.
My javascript code is
var db = new PouchDB('dev');
var toinsert = ["devices","brands","tags"];
toinsert.forEach(function(json){
insert(json);
})
function insert(json){
var param2 = {
url: json + '.json',
dataType: 'json',
cache: false,
type: 'GET'
};
$.ajax(param2)
.done(function(data){
db.bulkDocs(data).then(function (result) {
console.log('Row inserted Successfully');
}).catch(function (err) {
console.log('Unable to insert into DB. Error: ' + err.name + ' - ' + err.message);
});
});
}
Here when i am checking indexedDB i am getting only devices.json data, Others are missing. Here I am not sure weather PouchDB can insert multiple json files or not? If it's Possible using PouchDB, Please helm me to get it.
It seems that the second and third objects are not a valid json object. This could be the issue, check http://jsonlint.com/ to validate your json objects.

Resources