Azure Time series Insights visualization in html web application using javascript - azure-web-app-service

I have IoT sensor Data in IoT Hub connected I can see Azure Time Series Insights where i can Query Data by DeviceId and avg and sum .
How can i make it available in my HTML website show data in as web-socket continuously.
I have designed the chart in D3 and Angular . How can i feed this data into App. any examples if you have .
I see it has very limited documentation
var aggregateExpressions4 = [];
var startDate = new Date('2017-04-19T13:00:00Z');
var endDate = new Date(startDate.valueOf() + 1000*60*60*1);
aggregateExpressions4.push(new
tsiClient.ux.AggregateExpression({predicateString: "Factory = 'Factory3'"},
{property: 'Temperature', type: "Double"}, ['avg', 'min', 'max'],
{ from: startDate, to: endDate, bucketSize: '2m' }, {property: 'Station', type: 'String'}, 'green', 'Factory3Temperature'));
https://learn.microsoft.com/en-us/azure/time-series-insights/tutorial-explore-js-client-lib
If I could get this as results of dat i can push them to my D3 charts . but it tries to push its own charts
by its own bar and pie charts .
var barChart = new
tsiClient.ux.BarChart(document.getElementById('chart4'));
barChart.render(transformedResult, {grid: true, timestamp: '2017-04-19T13:00:00Z', legend: 'compact'}, aggregateExpressions4);

Microsoft have given this i have try this
https://learn.microsoft.com/en-us/rest/api/time-series-insights/time-series-insights-reference-queryapi

Related

how can I convert react-native data?

// i have to change my data to this form
items={{
'2021-04-20': [{name: 'item 1 - any js object'}],
'2012-04-21': [{name: 'item 2 - any js object'}]
}}
I am trying to show data below using react-native calendar library's agenda. And agenda needs the form of data like above.
['20210420': 'work', '20210421': 'sleep'] //the data i have
how can i convert my data by using react-native code?
Maybe this can help you!
const data = {'20210420': 'work', '20210421': 'sleep'}
const formattedData = {}
Object
.entries(data)
.forEach(([key, value]) => formattedData[`${key.substr(0, 4)}-${key.substr(4, 2)}-${key.substr(6)}`]= [{ name: value }])
console.log(formattedData)

How can I get Google API to return a distance between two points on node.js and store it in a variable?

I am trying to get a distance between two locations with Google API, coding in node.js. I would like to store the value in a variable, how do I do this?
If you know their names,You can try the following example which requests the distance matrix data between Washington, DC and New York City, NY, in JSON format
var request = require('request');
request.get('https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=Washington,DC&destinations=New+York+City,NY&key=YOUR_API_KEY'
, function (error, response) {
if(error){
//Error handling
}else{
/*
the response will be in a "JSON" format, you can see it in
details by entering the previous URL into your web browser
(be sure to replace YOUR_API_KEY with your actual API key)
*/
}
})
or you can use this module node-googlemaps which wrap the apis.
if you know their longitudes and latitudes, i think there are no npm packages include the needed google libraries needed for that so i suggest you to calculate the distance by Haversine formula by using this npm module Haversine formula and this is a simple example:
var haversine = require('haversine-distance')
var a = { latitude: 37.8136, longitude: 144.9631 }
var b = { latitude: 33.8650, longitude: 151.2094 }
// 714504.18 (in meters)
console.log(haversine(a, b))

Pubnub EON chart rendering multiple data in the chart

I am following the follwoing example to publish my data using pubnub and eon charts. When I publish just one data stream i.e 'checkpointsize' the chart renders fine but the minute I enter data2 i.e 'checkpointlength' it gives me error
Uncaught Error: Source data is missing a component at (1,1)!
I can see the data in pubnub console, means that I am getting a data stream but the it cannot be rendered into the chart.
var pubnub = PUBNUB({
subscribe_key : 'YOUR_SUBSCRIBE_KEY_HERE'
});
eon.chart({
pubnub : pubnub,
history : false,
channel : 'orbit_channel',
flow : true,
generate : {
bindto : '#chart',
data : {
x : 'x',
labels : true
},
axis : {
x : {
type : 'timeseries',
tick : {
format : '%H:%M:%S'
},
zoom: {
enabled: true
}
}
}
},
transform : function(m) {
return { columns : [
['x', new Date().getTime()],
['Checkpoint Size', m.checkpointsize],
['Checkpoint length', m.checkpointlength]
] };
}
});
here is the pubnub console
Combine Two Data Streams into One Chart with PubNub Eon
Looks like you are trying to plot two vectors on the same graph. This is possible for you to do by transmitting the values together at the same time in the same published message object. I think you are publishing twice in your example. Your publish message needs to contain both data points. Here is an example
pubnub.publish({
"checkpointsize" : 75.0,
"checkpointlength" : 5000.0
})

Limit posts from Instagram API on a Google Map based on radius in current window

So I have the code below which is the front end on a node.js app which pulls Instagram posts with a certain hashtag. Right now it posts all over the world. Is there a way to limit the radius on the posts and if possible, limit to the window that is currently visible to the user? I'm using the Instagram Real Time tag subscription.
function initialize() {
var styles = [{
"featureType": "landscape",
"stylers": [{
"color": "#808080"
}, {
"visibility": "simplified"
}]
}, {
"featureType": "administrative",
"elementType": "labels.text.fill",
"stylers": [{
"weight": 0.1
}, {
"lightness": 100
}, {
"visibility": "off"
}]
}, {}];
var mapOptions = {
center: new google.maps.LatLng(32.71533, -117.15726),
zoom: 4,
scrollwheel: false,
scaleControl: true,
styles: styles
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
var socket = io.connect();
socket.on('photo', function (data) {
var icon = {
url: data.img, // url
size: new google.maps.Size(80, 80), // size
};
marker = new google.maps.Marker({
position: new google.maps.LatLng(data.lat, data.long),
draggable: true,
animation: google.maps.Animation.DROP,
icon: icon,
map: map,
title: data.caption
});
});
// Try HTML5 geolocation
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map.setCenter(pos);
}, function () {
handleNoGeolocation(true);
});
} else {
// Browser doesn't support Geolocation
handleNoGeolocation(false);
}
}
function handleNoGeolocation(errorFlag) {
if (errorFlag) {
var content = 'Error: The Geolocation service failed.';
} else {
var content = 'Error: Your browser doesn\'t support geolocation.';
}
var options = {
map: map,
position: new google.maps.LatLng(60, 105),
content: content
};
var infowindow = new google.maps.InfoWindow(options);
map.setCenter(options.position);
}
// Finally, call map
google.maps.event.addDomListener(window, 'load', initialize);
As far as I'm aware, there is no way to combine endpoints, ie Geographies and Tags into one search. I would think you have 2 options and both will be fairly labour intensive on your end, depending on the popularity of the hashtag/s, and the radius of your geography. I'm interested to see more opinions on this.
Option 1
Keep your realtime Tag subscription
Process the results manually to filter by the location information provided with each photo
Example from doc:
...
"location": {
"latitude": 37.780885099999999,`
"id": "514276",
"longitude": -122.3948632,
"name": "Instagram"
}
...
Pros:
You've already got a tag subscription.
You are not restricted to any radius
Cons:
Figuring out what photos fall into your desired radius sounds pretty complicated.
Option 2
Create a realtime Geography subscription
Process the results manually to filter by the tag information provided with each photo
Example from doc:
...
"tags": ["expobar"],
...
Pros:
Manually filtering by tag is likely going to be much easier
Cons:
You're restricted to a max radius of 5000m in your geography subscription
UPDATED ANSWER:
I think you're confused between Locations and Geographies, what you describe in your last comment (thinking out loud) is exactly what I was trying to suggest in option 2. Locations are places where you can tag a photo when uploading, for instance 'Starbucks Downtown', and are not terribly useful IMO, whereas Geographies use latitude, longitude & a radius, and are perfect for what you want to achieve - finding and displaying photos taken in close proximity, no matter where the user is.
Check out the "Geography Subscriptions" section of http://instagram.com/developer/realtime/
Creating a Geography Subscription is very similar to a Tag subscription so it shouldn't take much to tinker with what you've already got. As you guessed, you will just need to use a javascript library to grab the users lat/longitude first
The Instagram real-time API has a Geography Subscription as per the documentation which allows you to specify a position and a radius.
To create a subscription to a geography, specify a center latitude and longitude and a radius of the area you'd like to capture around that point (maximum radius is 5000 meters).
We don't really know from your question where the issue is, so let's hope this helps.

How to track iteration progress using Rally's Web Services API

I am writing a custom app to track iteration progress by day. Is there a builtin way in Rally to get the number of user stories that are in the "Accepted" state for a specific date, and the number of points (or do I have to get all user stories and parse their revision histories)?
There is IterationCumulativeFlowData object in WS API, which is populated at midnight of the Workspace Timezone when the Data Collection runs on workdays specified in the Workspace Setup screen.
Data is stored for each day of the Iteration and a corresponding state. There is CumulativeFlowData object for Day 1 of the Iteration for everything in a Defined state, Day 1 of Release for everything in an In-Progress state, etc.
The CumulativeFlowData object also stores CardEstimateTotal which is the sum of the estimates of cards in every state.
Here is a example of an app written with rally-node that returns iteration data for specific state (Accepted) as of the last day of the iteration.
In this examle the CreationDate of the last result is '2013-08-27T06:00:00.000Z, while the EndDate of the iteration in question was 2013-08-27 11:59:59 PM America/Denver (which is 2013-08-28T05:59:59.000Z), so I had to manipulate a date in order to make this query condition return the data for the last day of the iteration:
query = query.and('CreationDate', '>', endDateMinusOneDay);
Here is the full js file of the example:
var rally = require('rally'),
queryUtils = rally.util.query,
restApi = rally({
user: 'user#co.com',
pass: 'secret',
apiVersion: 'v2.0',
server: 'https://rally1.rallydev.com',
requestOptions: {
headers: {
'X-RallyIntegrationName': 'My cool node.js program',
'X-RallyIntegrationVendor': 'My company',
'X-RallyIntegrationVersion': '1.0'
},
}
});
function findIteration() {
return restApi.query({
type: 'Iteration',
start: 1,
pageSize: 2,
limit: 10,
fetch: ['ObjectID', 'EndDate'],
scope: {
project: '/project/12352608219',
up: false,
down: false
},
query: queryUtils.where('Name', '=', 'i777')
});
}
function queryIterationData(result) {
var endDate = result.Results[0].EndDate,
oid = result.Results[0].ObjectID;
console.log('endDate',endDate);
var date1 = new Date(endDate);
var ms = date1.getTime() - 86400000; //86400000 is the number of milliseconds in a day
var date2 = new Date(ms);
var endDateMinusOneDay = date2.toISOString();
console.log('date2 ISO', date2.toISOString());
var query = queryUtils.where('IterationObjectID', '=',oid );
query = query.and('CardState', '=', 'Accepted');
query = query.and('CreationDate', '>', endDateMinusOneDay);
return restApi.query({
type: 'IterationCumulativeFlowData',
fetch: ['CardCount', 'CardEstimateTotal', 'CardState', 'CardState', 'CreationDate'],
query: query,
});
}
function onSuccess(result) {
console.log('Success!', result);
}
function onError(errors) {
console.log('Failure!', errors);
}
findIteration()
.then(queryIterationData)
.then(onSuccess)
.fail(onError);
It returns:

Resources