crossfilter filter does not apply on update data. Is it by design? - crossfilter

I am managing a large dateset using crossfilter in my recent project, in which I will need ability to change the data value (a bool). However after the value changed, the filter on this property does not filter out changed item. For instance I have large dataset whose data has a property of Boolean named as 'Ignore'; I create a dimension for this property to filer out the data have ignore= true. In app, user has a capability to change this value from false to true. after value changed true, clear filters and refilter the data on this dimension, I am still getting the data item which supposed being filterred out. Is it by design or there is way to around it?

From the API Docs and source it appears this behaviour is not supported.
https://github.com/square/crossfilter/wiki/API-Reference

Related

Sorting a Calculated datasource in AppMaker

I have a Calculated datasource that's populated via an appscript function. When I display this datasource in a table, it works great but I can't click on the headers to sort them. I'd like to implement sorting.
I can see that sorting is specified in the Query object using Query.sorting.<fieldname>._ascending() and descending(). What I can't figure out is how to read the value that was set by these functions so I can determine how the user wants me to sort the results.
How do I determine what the desired sort is from the appmaker Query object?
I can't find any documentation around this either, but by inspecting the Query object, I found I can do this:
query.sorting.._order: true - ascending; false - descending; null - no sorting by this column.
query.sorting.._priority: 0 based priority, null - no sorting.
So assuming I have a "Title" column, by inspecting query.sorting.Title._order and query.sorting.Title._priority, I can tell if I should or how to sort by it.

modify field value in a crossfilter after insertion

I need to modify a field value for all records in a crossfilter before inserting new records.
The API doesn't say anything about it. Is there a way to do that ?
Even if it's a hack that would be really useful to me.
Looking at the code, the data array is held as a private local variable inside the crossfilter function so there's no way to get at it directly.
With that said, it looks like Crossfilter really tries to minimize the number of copies of the data it makes. So callback functions like the ones passed into crossfilter.dimension or dimension.filter are passed the actual records themselves from the data array (using the native Array.map) so any changes to make to the records will be made to the main records.
With that said, you obviously need to be very careful that you're not changing anything that is relied on by the existing dimensions, filters or groups. Otherwise you'll end up with data that doesn't agree with the internal Crossfilter structures and chaos will ensue.
The cool thing about .remove is it only removes entries that match the currently applied filters. So if you create a 'unique dimension' that returns a unique value for every entry in your dataset (like an ID column), you can have a function like this:
function editEntry(id, changes) {
uniqueDimension.filter(id); // filter to the item you want to change
var selectedEntry = uniqueDimension.top(1)[0]; // get the item
_.extend(selectedEntry, changes); // apply changes to it
ndx.remove(); // remove all items that pass the current filter (which will just be the item we are changing
ndx.add([selectedEntry]); // re-add the item
uniqueDimension.filter(null); // clear the filter
dc.redrawAll(); // redraw the UI
}
At the least you could do a cf.remove() then readd the adjusted data with cf.add().

Building A Global Object in Titanium to be written to sqlite3 database

This question is about implementation.
I'm building an android application with titanium.
There are multiple screens and i take data in each of them.
Each screen is a commonJS module
I want to write all the data i take to an sqlite3 database, but i suppose it would be inefficient to write them as i take inputs. Two ways come to my mind as to how to do this.
create an object and pass to each module to hold the data as i take them
create an object in the first module to hold the data and pass each data item to it by firing a custom event.
What i'm asking, is if there's a better approach to this or which of these two would be more efficient.
NB: I don't have a lot of screens, but that could change though.
Thanks.
Titanium.App.Properties are widely used for Global variable creation.
The following methods will help you to create global variable
setBool : Sets the value of a property as a Boolean data type
setDouble : Sets the value of a property as a double (double-precision, floating point) data type
setInt : Sets the value of a property as an integer data type
setList : Sets the value of a property as an array data type
setObject : Sets the value of a property as an object data type
setString : Sets the value of a property as a string data type
All the above methods will allow user to save corresponding type of data as gloabl. You may retrieve saved values using getBool, getDouble, getInt, getList, getObject, getString methods respectively.
i think Ti.App.properties set and get string would do fine for you here is example too
http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.App.Properties
Thanks

Qt error "persistent model indexes corrupted" why?

I've a problem with my Qt/interview application. I use QTreeView to display tree data. I implemented my own model based on QAbstractItemModel.
I get a following error prior to application crash. It happens often after I add new record.
Could You explain to me what is the meaning of this error. What is a QPersistentModelIndex ?
I'm not using QPersistentModelIndex in my code.
ASSERT failure in QPersistentModelIndex::~QPersistentModelIndex: "persistent model indexes corrupted"
Thanks.
QPersistentModelIndexes are (row, column, parent) references to items that are automatically updated when the referenced items are moved inside the model, unlike regular QModelIndex. For instance, if you insert one row, all existing persistent indexes positioned below the insertion point will have their row property incremented by one.
You may not use them directly, but QTreeView does, to keep track of expanded items and selected items, for example.
And for these persistent indexes to be updated, you have to call the functions QAbstractitemModel::beginInsertRows() and endInsertRows() around the actual row insertion(s) when you add new records.
See the end of the section about subclassing model classes for details: http://doc.trolltech.com/latest/qabstractitemmodel.html#subclassing
I found this method QAbstractItemModel::persistentIndexList and I'm
wondering what indexes it should return. All of them ?
Should this method return all nodes currently visible in the TreeView ?
That method returns only the indexes for which a QPersistentIndexModel was created and is still in scope (as a local variable, a class member, or in a QList<QPersistentIndexModel> for example).
Expanded or selected nodes are not necessarily currently visible, so you can't (and shouldn't anyway) assume anything about what these persistent indexes are used for.
You just have to keep them updated, and you only need to use persistentIndexList for big changes in the model, like sorting (see QTreeWidget internal model : QTreeModel::ensureSorted(link)), for smaller incremental changes you have all the beginXxxRows/beginXxxColumns and endXxxRows/endXxxColumns methods.

Flex DataGridColumn with array of objects as data provider

I have a datagrid that uses an array of objects as the data provider. The objects are essentially key/value pairs:
{ foo:"something"}
{ bar:"hello"}
{ caca:"lorem"}
The datagrid has 2 columns. The first column is the key and the second column is the value. Right now my grid looks like:
My dataFormatter function makes sure that depending on the column (i.e. the dataField value) the correct key or value gets printed out. This works fine for displaying. However, as soon as I try and edit the value field it essentially adds a new value into the object with a key of '1'. For example, if I edit the {caca:"lorem"} object it will then contain the value {caca:"lorem",1:"new value"}.
Is there any possible way I can set the DataGridColumn so that when I edit a value it will update the value associated with the key rather than inserting a new value? I've tried using a custom item editor but it still does the insert. It seems like I need to be able to update the 'dataField' with the actual key value but I'm not sure how to do that.
Looks like you need to think about where your data is going to be stored. I would recommend listening for a CollectionEvent.COLLECTION_CHANGE event on your data model. That event object will contain info about what change occurred, and you can make any updates you need to make.

Resources