How to filter crossfilter dimension of array - crossfilter

How to filter crossfilter dimension of array
I have created following dimension
var typeSeriesDimension = data.dimension(function(d)
{
return [d.user_code, d.count];
});
If I apply filter as typeSeriesDimension.filter([5,10]).top(1)
I should get an object having user_code=5 and count=10 but crossfilter consider [5,10] as a range and returns different object.

Related

Difference between two maps when updating field in cloud firestore

var data = {
'key.number': 1,
};
var data = {
'key' : {
'number': 1,
}
};
Is there any difference between the two Maps when updating number on the cloud firestore using
var ref = Firestore.instance.document('users/id');
ref.updateData(data);
If the document didn't already have a "key" field, there is no difference.
If the document did already have a "key" field, the first one would just overwrite any existing value for key.field, preserving any other fields in the key object, and the second one would completely overwrite the key object and all of its existing fields.

Selecting Item in Array

I'm trying to run a query by using a user input. The query is run in a database which has multiple columns (practically a vlookup). The query is run and the output is an array of values.
How do I get the value of only one value (scalar output to put in alert)?
Thanks
I've tried to use methods familiar to java in order to call one field in an array without any success.
i.e. output_array[0]
// define input
// var custno = app.pageFragments.Add_SalesOrder.children.Form1.children.Form1Body.children.CustomerNo_Input;
var custno = 'ENC';
// define location of output
var outputWidget = app.pageFragments.Add_SalesOrder.children.Form1.children.Form1Body.children.CustomerName_Input;
// define datasource
var datasource = app.datasources.SalesOrder;
// query
datasource.query.filters.CustomerNo._startsWith = custno.value;
// load query
datasource.load();
alert(datasource[0]);
I expect to get the first entry in the array but instead I get 'Undefined'.
If you look at the datasource documentation, you'll find out that the datasource is NOT an array, but instead an object. Since you are looking for the first result of the query, then you should access the items property of the datasource. That is an array and you can then just access the zero index of the array to get what you need.
alert(datasource.items[0]);

Populating Array Data from Data Layer into GTM

I have a Data Layer that is giving me information like this from Drupal
dataLayer = [{
"entityType":"node",
"entityBundle":"article",
"entityTaxonomy":
{"funnel_path":{"2":"Find a Park"},
"byline":{"4":"Name1","5":"Name2"}},"drupalLanguage":"en",
"userUid":"1"}
];
</script>
I can easily use GTM's Data Layer variable to pull in entityBundle. How do I set it to pull in the information in byline? I tried entityTaxonomy.byline, but that give me an array. I can set to do entityTaxonomy.byline.4 to get Name1, but that would be silly since the editors would be regularly adding things.
I am planning to add the byline, ultimately, into Custom Dimension 2 in Google Analytics.
I am looking to have the data that goes to Custom Dimension 2 to be Name1, Name2 . Sometimes this will be just one value. Sometimes it can be up to 20 values.
What do I need to do in GTM to get it to register that information?
entityTaxonomy.byline actually gives you an object. You would need to do a bit of processing to get an array that you can join into a string. One possible way would be
temp = [];
Object.keys(test.entityTaxonomy.byline).map(function(key, index) {
temp.push(test.entityTaxonomy.byline[key]);
});
bylines = temp.join(",")
(I'm sure that could be done much more concise). In GTM you would need to create a variable that contains the objects with the bylines, then you could do the processing in a custom javascript variable (which is by definition an anonymous function with a return value)
function() {
var byLineObject = {{bylines}} // created as datalayer var beforehand
temp = [];
Object.keys(byLineObject).map(function(key, index) {
temp.push(byLineObject[key]);
});
return temp.join(",")
}

How can i get the Complement of the filtered data using crossfilter

I am using crossfilter to filter data. Here is my code
var ndt=crossfilter(unique);
var dimt=ndt.dimension(function(d){
return d.etime;
});
var dimtd=dimt.filterFunction(function(d)
{
if(seconds(d.etime)<seconds(ctime)-100)
{
return d;
}
});
var problemdata=dimtd.top(Infinity);
My question is how can i get the complement of problem data. Is there any function or shortcut way. My goal is to get
{unique}-{problemdata}. That means the rows in unique which are not in problemdata.
Try this Crossfilter's method called crossfilter.remove().
crossfilter.remove()
Removes all records that match the current filters from this
crossfilter.

LatLng from Google Maps Polygon getPath()

Based on the Google Maps JavaScript API v3 documentation, google.maps.Polygon class's getPath() function returns an MVCArray. In a straightforward case, a Polygon's path can be a single array of LatLngs that are converted to the MVCArray type upon being passed into the google.maps.Polygon class's setPath() function.
The above case is what I'm dealing with currently. I pass in an array of LatLngs, and return (what I assume is) an MVCObject when I call getPath() on my Polygon object. My question is: How do I convert this MVCObject back into a single array of LatLngs that form the Polygon's shape? Is there some built in Google Maps API v3 way that I'm missing? I feel like there has to be some sort of obvious built in conversion function or something in the API that's eluding me.
Any help would be appreciated.
When you call Polygon.getPath()api-doc, the return is an MVCArrayapi-doc of LatLng instances that represent the first path of the Polygon. You can directly get to the members of the MVCAarray in two ways:
Call MVCAarray.getArray, which will return the underlying JavaScript Array that contains LatLng members.
Use MVCArray.getAt( index ), which will return whatever is at that index in the MVCArray (a LatLng in this case). This provides you a way to setup a JavaScript for loop to iterate over the members of the array.
You can also indirectly work with the members of the MVCArray by using the forEach(callback:function(*, number)) function. In this case, you must pass a callback function that accepts two parameters:
The actual member element of the MVCArray.
The array index where that element is located.
var polygonBounds = polygon.getPath();
var bounds = [];
for (var i = 0; i < polygonBounds.length; i++) {
var point = {
lat: polygonBounds.getAt(i).lat(),
lng: polygonBounds.getAt(i).lng()
};
bounds.push(point);
}

Resources