Azure stream analytics custom output data with CASE statement - azure-stream-analytics

I have problem to counting user of each zone, each user will send locale of them to server. Can someone help me to achieve this, thank you.
Output stream analytics should be this:
{
"sessionId": "sessionId1", -->group by sessionId
"data": {
"North America": 0,
"South America": 0,
"Europe": 0,
"Russia": 1,
"Africa": 2,
"India": 0,
"China": 2,
"Oceania": 0,
}
},
{
"sessionId": "sessionId2", -->group by sessionId
"data": {
"North America": 0,
"South America": 0,
"Europe": 0,
"Russia": 0,
"Africa": 1,
"India": 0,
"China": 0,
"Oceania": 0,
}
}
input data:
[{"sessionId":"Session1","deviceId":"deviceTest1","locale":"Russia"},{"sessionId":"Session1","deviceId":"deviceTest2","locale":"China"},{"sessionId":"Session1","deviceId":"deviceTest3","locale":"China"},{"sessionId":"Session1","deviceId":"deviceTest4","locale":"Africa"},{"sessionId":"Session1","deviceId":"deviceTest5","locale":"Africa"},{"sessionId":"Session2","deviceId":"deviceTest6","locale":"Africa"}]

I have tried serval SQL query, but cant achieve your requirement. I think it is impossible because you need group by sessionId, but there is no Aggregate Functions can get this format.
"data": {
"North America": 0,
"South America": 0,
"Europe": 0,
"Russia": 0,
"Africa": 1,
"India": 0,
"China": 0,
"Oceania": 0,
}

Related

How do you fix an abnormal message_id return from Firebase Cloud Messaging or what does it mean?

I'm getting a return like below with notifications not being received:
{
"multicast_id": 339554596924119421,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [{
"message_id": "0:1593443824341654%c4860296c4860296"
}]
}
When I expect a return like this one below, and a delivered notification:
{
"multicast_id": 1714438464855660605,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [{
"message_id": "1593203838780899"
}]
}
This issue is arising after deleting the firebase instance in app and getting a new token. What does the difference between message_id's mean or how does someone fix it?

vuejs2 : reset variable when a event happened

I need reset a variable when a event happened in vuejs2
Here I have my code with 2 functions: "add" and "reset":
https://jsfiddle.net/uo19p71m/
var ggroupc = [
{id: 1, country: "Francia", pj: 0, pg: 0, pe: 0, pp: 0, gf: 0, gc: 0, dg: 0, pt: 0},
{id: 2, country: "Australia", pj: 0, pg: 0, pe: 0, pp: 0, gf: 0, gc: 0, dg: 0, pt: 0},
{id: 3, country: "Peru", pj: 0, pg: 0, pe: 0, pp: 0, gf: 0, gc: 0, dg: 0, pt: 0},
{id: 4, country: "Dinamarca", pj: 0, pg: 0, pe: 0, pp: 0, gf: 0, gc: 0, dg: 0, pt: 0}
];
var app = new Vue({
el: '#app',
data: {
challenges: [[1, 2], [3, 4], [1, 3], [2, 4], [1, 4], [2, 3]],
groupc: ggroupc
},
methods: {
add: function () {
this.groupc[0].pj++;
this.groupc[1].pg++;
this.challenges[0][0]++;
},
reset: function () {
this.groupc = ggroupc;
}
}
});
I want to reset the "groupc" variable but doesn't "challenges" variable.
Some idea?
because the variable is a link to a place in memory
you must clear the counters
see corrected fiddle https://jsfiddle.net/simati/h6dt3t6n/
*also I added create new object with Object.assign() maybe you need it
in example:
open conosle (chrome: ctr + shift + i)
click button log see result
click button add and next click button log see result
click button reset and next click button log see result
UPDATE:
method Object.assign() not working, has been changed to JSON.parse(JSON.stringify())
also method resetIndex() redesigned to reset on original counters
Arrays are not assigned by value in JavaScript, but by reference. This is important. Take the following example:
var array_original = ['a', 'b', 'c'];
var array_copy = array_original;
array_copy[0] = 'd';
What you're doing seems to assume that array_original will still contain ['a', 'b', 'c'], but it will actually contain ['d', 'b', 'c'] just like array_copy does!
If you want to fix your code, you're going to need to explicitly clone the array. Additionally, you'll need to be sure to make it a deep clone or you'll still have problems with the objects inside for the same reason!
Example of a deep clone using jQuery:
var array_original = ['a', 'b', 'c'];
var array_copy = $.extend(true, [], array_original);
If you don't want to use jQuery, do some additional research into deep cloning of arrays of objects. Alternatively, don't define your ggroupc globally--instead, assign these values locally and use the mounted lifecycle hook!
var app = new Vue({
el: '#app',
data: {
challenges: [[1,2],[3,4],[1,3],[2,4],[1,4],[2,3]],
groupc : ggroupc
},
mounted: function() {
this.reset();
},
methods: {
add : function() {
this.groupc[0].pj++;
this.groupc[1].pg++;
this.challenges[0][0]++;
},
reset : function() {
this.groupc = [
{id:1, country:"Francia", pj:0, pg:0, pe:0, pp:0, gf:0, gc:0, dg:0, pt:0},
{id:2, country:"Australia", pj:0, pg:0, pe:0, pp:0, gf:0, gc:0, dg:0, pt:0},
{id:3, country:"Peru", pj:0, pg:0, pe:0, pp:0, gf:0, gc:0, dg:0, pt:0},
{id:4, country:"Dinamarca", pj:0, pg:0, pe:0, pp:0, gf:0, gc:0, dg:0, pt:0}
];
}
}
});

How to customize czml datasource?

I have a CZML data that I extracted via python.
I have buildings, with their geometry, height, building ID, and intervals. each interval has a value.
After loading the czml data to Cesium, I'd like to access the attributes and then customize the color of the buildings according to the value given.
Here is a sample of my CZML:
[{
"id": "document",
"version": "1.0"
}, {
"id": 32,
"availability": "2014-01-01T00:00:00Z/2014-12-31T00:00:00Z",
"polygon": {
"positions": {
"cartographicDegrees": [54.7162360431897, 24.4519912715277, 0, 54.716219612921, 24.4519754832587, 0, 54.7162501395131, 24.4519488635358, 0, 54.7162465684811, 24.4519454316688, 0, 54.7162670831639, 24.4519275432238, 0, 54.7162707308589, 24.4519310439514, 0, 54.7163022563025, 24.4519035537608, 0, 54.7161962974502, 24.4518018819532, 0, 54.7161647729823, 24.4518293730395, 0, 54.7162035538772, 24.4520196028966, 0, 54.7162360431897, 24.4519912715277, 0]
},
"someProperty": [{
"interval": "2014-00-01T00:00:00Z/2014-01-01T00:00:00Z",
"En_C_need": 0.7
}, {
"interval": "2014-01-01T00:00:00Z/2014-02-01T00:00:00Z",
"En_C_need": 1.0
}, {
"interval": "2014-02-01T00:00:00Z/2014-03-01T00:00:00Z",
"En_C_need": 2.6
}, {
"interval": "2014-03-01T00:00:00Z/2014-04-01T00:00:00Z",
"En_C_need": 12.1
}, {
"interval": "2014-04-01T00:00:00Z/2014-05-01T00:00:00Z",
"En_C_need": 30.2
}, {
"interval": "2014-05-01T00:00:00Z/2014-06-01T00:00:00Z",
"En_C_need": 37.8
}],
"extrudedHeight": 6.0
}
}]
I have other GeoJSON data that I customized, I tried the same method but it didn't work.
Here is what I'm trying to do (this does not work):
var test2 = Cesium.CzmlDataSource.load ('Data/czml/TESTING/example_8.czml');
test2.then(function (dataSource) {
viewer.dataSources.add(test2);
viewer.zoomTo (test2);
var entities = dataSource.entities.values;
var colorHash = {};
var Energy = [];
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
Energy = entity.someProperty.En_C_need;
var color = colorHash [Energy];
if(!color ) {
if (Energy < 5 ) {
color = Cesium.Color.DARKSALMON.withAlpha (0.95);
} else if (Energy < 10) {
color = Cesium.Color.BURLYWOOD.withAlpha (0.95);
} else if (Energy < 20) {
color = Cesium.Color.RED.withAlpha (0.95);
} else {
color = Cesium.Color.PINK.withAlpha (0.95);
};
colorHash[Energy] = color;
};
entity.polygon.fill = true;
entity.polygon.material = color;
entity.polygon.outline = false;
};
});
To start with the solution - here's the working plnkr:
https://plnkr.co/edit/P1Cg4DNJYtK9r9XrLzxK?p=preview
I've changed several things in your code:
1) viewer.dataSources.add(test2); should be outside your promise (it doesn't really matter, but it's cleaner code - using the promise inside the promise feels strange).
2) According to the CZML properties spec, you need to place the properties in the right location in the CZML. It should not be inside the polygon, but in the "root":
var czml = [{"id": "document", "version": "1.0"},
{
"id": 32, "availability": "2014-01-01T00:00:00Z/2014-12-31T00:00:00Z", "properties": {
"someProperty": [
{"interval": "2014-00-01T00:00:00Z/2014-01-01T00:00:00Z", "En_C_need": 0.7},
{"interval": "2014-01-01T00:00:00Z/2014-02-01T00:00:00Z", "En_C_need": 1.0},
{"interval": "2014-02-01T00:00:00Z/2014-03-01T00:00:00Z", "En_C_need": 2.6},
{"interval": "2014-03-01T00:00:00Z/2014-04-01T00:00:00Z", "En_C_need": 12.1},
{"interval": "2014-04-01T00:00:00Z/2014-05-01T00:00:00Z", "En_C_need": 30.2},
{"interval": "2014-05-01T00:00:00Z/2014-06-01T00:00:00Z", "En_C_need": 37.8}
],
},
"polygon": {
"positions": {
"cartographicDegrees":
[54.7162360431897, 24.4519912715277, 0, 54.716219612921, 24.4519754832587, 0, 54.7162501395131, 24.4519488635358, 0, 54.7162465684811, 24.4519454316688, 0, 54.7162670831639, 24.4519275432238, 0, 54.7162707308589, 24.4519310439514, 0, 54.7163022563025, 24.4519035537608, 0, 54.7161962974502, 24.4518018819532, 0, 54.7161647729823, 24.4518293730395, 0, 54.7162035538772, 24.4520196028966, 0, 54.7162360431897, 24.4519912715277, 0]
},
"extrudedHeight": 6.0
}
}];
Then you can ask for the properties according to the interval (Energy = entity.properties.getValue(viewer.clock.currentTime).someProperty.En_C_need;) and get the Energy at viewer's current time.
Update after commentchatting:
Your code was not meant to change dynamically. You need to set the value either by callbackProperty as in this example: plnkr.co/edit/lm290uaQewEvfIOgXbDP?p=preview or by using timeIntervalCollection

JSON format in KnockoutJS

I am getting JSON format like below:
[
{
"moduleName": null,
"bundleKey": "title",
"bundleValue": "Manage cost code",
"id": 4,
"createdBy": 0,
"modifiedBy": 0,
"createdDate": "0001-01-01T00:00:00",
"modifiedDate": "0001-01-01T00:00:00",
"rowVersion": null,
"isDeleted": false
},
{
"moduleName": null,
"bundleKey": "name",
"bundleValue": "steve",
"id": 5,
"createdBy": 0,
"modifiedBy": 0,
"createdDate": "0001-01-01T00:00:00",
"modifiedDate": "0001-01-01T00:00:00",
"rowVersion": null,
"isDeleted": false
}]
I would like to format that as a key-value pair, like the following:
[{"title":"Manage cost code", "name":"steve"}]
Whether it is possible to format JSON like this.
Or is it possible to get data directly from a database in the format below?
I do not want to query the column name, only its values should be queried.
If you want to do it clientside, just use a simple reduce function
var src = [...];
var result = src.reduce( function(prev, current) {
prev[current.bundleKey] = current.bundleValue;
return prev;
}, {} );

Restify very simple JSONClient returns empty json

I just started using restify and tries to build a very simple JSONClient and fails on the first step.
var restify = require('restify');
var client = restify.createJsonClient({
url: 'http://api.bgm.tv'
});
client.get('/calendar', function(err, req, res, obj) {
console.log('%j', obj);
});
This pieces of code returns {} with a status code 200
If you check http://api.bgm.tv/calendar in browser or curl it seems to be a legit json GET Rest API and does not require auth or anything else.
I tried other API such as stackoverflow api it works perfectly, so I assume something wrong with the server side?
If anyone can try to run it and help me point out what might went wrong would be very appreciated.
I runned your example node code and got a proper response (the same you get when browsing).
You probably have some version problem or a console.log size limitation.
Try using: console.log(obj[0]); it should print only the first object in the json.
I'm using node v0.8.9 and restify v2.4.1 on a mac.
Yeah, when I use the Postman plugin for Chrome and do a GET request to http://api.bgm.tv/calendar I get:
[
{
"weekday": {
"en": "Mon",
"cn": "星期一",
"ja": "月耀日",
"id": 1
},
"items": [
{
"id": 46458,
"url": "http://bgm.tv/subject/46458",
"type": 0,
"name": "アイカツ! -アイドルカツドウ!-",
"name_cn": "偶像活动",
"summary": "",
"eps": 0,
"air_date": "2012-10-08",
"air_weekday": 1,
"images": {
"large": "http://lain.bgm.tv/pic/cover/l/db/7f/46458_8mM39.jpg",
"common": "http://lain.bgm.tv/pic/cover/c/db/7f/46458_8mM39.jpg",
"medium": "http://lain.bgm.tv/pic/cover/m/db/7f/46458_8mM39.jpg",
"small": "http://lain.bgm.tv/pic/cover/s/db/7f/46458_8mM39.jpg",
"grid": "http://lain.bgm.tv/pic/cover/g/db/7f/46458_8mM39.jpg"
},
"collection": {
"wish": 0,
"collect": 0,
"doing": 44,
"on_hold": 0,
"dropped": 0
}
},
{
"id": 57150,
"url": "http://bgm.tv/subject/57150",
"type": 0,
"name": "LINE OFFLINE ~サラリーマン~",
"name_cn": "离线LINE - 上班族 -",
"summary": "",
"eps": 0,
"air_date": "2013-01-07",
"air_weekday": 1,
"images": {
"large": "http://lain.bgm.tv/pic/cover/l/71/28/57150_Kz171.jpg",
"common": "http://lain.bgm.tv/pic/cover/c/71/28/57150_Kz171.jpg",
"medium": "http://lain.bgm.tv/pic/cover/m/71/28/57150_Kz171.jpg",
"small": "http://lain.bgm.tv/pic/cover/s/71/28/57150_Kz171.jpg",
"grid": "http://lain.bgm.tv/pic/cover/g/71/28/57150_Kz171.jpg"
},
"collection": {
"wish": 0,
"collect": 0,
"doing": 206,
"on_hold": 0,
"dropped": 0
}
},
{
"id": 58709,
"url": "http://bgm.tv/subject/58709",
"type": 0,
"name": "ハヤテのごとく! Cuties",
"name_cn": "旋风管家 Cuties",
"summary": "",
"eps": 0,
"air_date": "2013-04-08",
"air_weekday": 1,
"images": {
"large": "http://lain.bgm.tv/pic/cover/l/15/28/58709_H7uj8.jpg",
"common": "http://lain.bgm.tv/pic/cover/c/15/28/58709_H7uj8.jpg",
"medium": "http://lain.bgm.tv/pic/cover/m/15/28/58709_H7uj8.jpg",
"small": "http://lain.bgm.tv/pic/cover/s/15/28/58709_H7uj8.jpg",
"grid": "http://lain.bgm.tv/pic/cover/g/15/28/58709_H7uj8.jpg"
},
"collection": {
"wish": 0,
"collect": 0,
"doing": 219,
"on_hold": 0,
"dropped": 0
}
},
...and a bunch more, but the body limit to answers on SO is 30,000 characters.