patternjavascriptMinor
Detect multiple devices in Keen.io collection
Viewed 0 times
collectionkeendevicesmultipledetect
Problem
I'm trying to display data from Keen.io we're collecting from an iOS app where we report what devices of ours the app is used to communicate with. In particular I'm trying to find where there are more than one of our device.
An entry from the Keen collection looks like:
Most of this is adapted from various different examples and tutorials, and as far as I can tell, it works. Examples I remember using are:
I have no idea though if it's 'good' code or 'awful', so please give constructive criticism:
```
Multiple Devices
var Keen=Keen||{configure:function(e){this._cf=e},addEvent:function(e,t,n,i){this._eq=this._eq||[],this._eq.push([e,t,n,i])},setGlobalProperties:function(e){this._gp=e},onChartsReady:function(e){this._ocrq=this._ocrq||[],this._ocrq.push(e)}};(function(){var e=document.createElement("script");e.type="text/javascript",e.async=!0,e.src=("https:"==document.location.protocol?"https://":"http://")+"dc8na2hxrj29i.cloudfront.net/code/keen-2.1.0-min.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)})();
Keen.configure({
projectId: "REMOVED",
readKey: "REMOVED"
});
// From http://dreaminginjavascript.wordpress.com/2008/08/22/eliminating-duplicates/
function eliminateDuplicates(arr) {
var i,
len=arr.length,
out=[],
obj={};
for (i=0;i 1) {
// console.log(response.result[id]);
var query = "https://api.keen.io/3.0/projects/REMOVED/queries/extraction?api_key=DEVICES&event_collection=Devices&timezone=43200&target_property=Device.Model&group_by=Device.Model&filters=%5B%7B%22property_name%22%3A%22iOS_OpenUDID%22%2C%22
An entry from the Keen collection looks like:
{
"iOS_OpenUDID": "hexadecimal",
"iOS_CountryCode": "two-letter country code",
"Device": {
"SerialNumber": "numbers",
"Barcode": "numbers",
"IP": "IP address",
"Model": "string",
},
"iOS_Timezone": "name of timezone",
}Most of this is adapted from various different examples and tutorials, and as far as I can tell, it works. Examples I remember using are:
- Google Developers - Visualization: Table
- Dreaming In Javascript - Eliminating Duplicates
I have no idea though if it's 'good' code or 'awful', so please give constructive criticism:
```
Multiple Devices
var Keen=Keen||{configure:function(e){this._cf=e},addEvent:function(e,t,n,i){this._eq=this._eq||[],this._eq.push([e,t,n,i])},setGlobalProperties:function(e){this._gp=e},onChartsReady:function(e){this._ocrq=this._ocrq||[],this._ocrq.push(e)}};(function(){var e=document.createElement("script");e.type="text/javascript",e.async=!0,e.src=("https:"==document.location.protocol?"https://":"http://")+"dc8na2hxrj29i.cloudfront.net/code/keen-2.1.0-min.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)})();
Keen.configure({
projectId: "REMOVED",
readKey: "REMOVED"
});
// From http://dreaminginjavascript.wordpress.com/2008/08/22/eliminating-duplicates/
function eliminateDuplicates(arr) {
var i,
len=arr.length,
out=[],
obj={};
for (i=0;i 1) {
// console.log(response.result[id]);
var query = "https://api.keen.io/3.0/projects/REMOVED/queries/extraction?api_key=DEVICES&event_collection=Devices&timezone=43200&target_property=Device.Model&group_by=Device.Model&filters=%5B%7B%22property_name%22%3A%22iOS_OpenUDID%22%2C%22
Solution
Nice work, @parsley72! This is a really clever mashup, no reason to suspect it's "not good" or even "awful" :)
[Keen IO employee here, fwiw]
One characteristic worth considering is reusability, but since this seems to be a fairly specialized bit of code I wouldn't spend too much time there. If you do find yourself repeating operations, there might be the beginnings of a reusable utility hiding in there somewhere. And if that's the case, please let me know.. it may be handy enough for us to roll into the library.
[Keen IO employee here, fwiw]
One characteristic worth considering is reusability, but since this seems to be a fairly specialized bit of code I wouldn't spend too much time there. If you do find yourself repeating operations, there might be the beginnings of a reusable utility hiding in there somewhere. And if that's the case, please let me know.. it may be handy enough for us to roll into the library.
Context
StackExchange Code Review Q#48214, answer score: 2
Revisions (0)
No revisions yet.