Is it possible to have a binding that combines more than one key path? - cocoa

Lets say I have an object which has a quantity value.
Also, I have an array controller which holds an array of these objects.
Furthermore, I have a table which has a percent of total column (i.e. the given row's quantity's percentage of the sum of the quantities for all rows), which needs to be populated with the proper value via bindings.
It would then seem that the idea way to do this would be to bind this column to arrayController.arrangedObjects.#sum.quantity divided by arrayController.arrangedObjects.quantity.
Is it possible to do this?
If not, can you suggest an alternative means of achieving this same end?

One way would be to implement a custom number formatter, with a custom binding for the divisor, programmatically bound to arrayController.arrangedObjects.quantity. In the formatter's setObjectValue: method, you would perform the division and pass the result to super.

Related

Is it possible to have a constant value in a calculated field in QuickSight?

In QuickSight, when you want to define a constant value to reuse it in visualizations later, you can try to set it as:
Calculated field: goalFor2020
Formula: 20000
But right now it doesn't allow you to put just a number in the formula.
Is there any way to do achieve having just a number in the formula of a calculated field?
The reason we need it is just to have a number that doesn't depend on any data, just manually defined by us.
Interesting, QuickSight lets me insert a number into a calculated field, just fine.
Since that isn't working for you, I'd recommend using a parameter with a default value. For example,
Parameters essentially has the same "rights" as a calculated field (it can be used in visuals, other calculated fields, etc...). It can also be passed via query parameters which may or may not be a feature that you'd find useful.
Another cool benefit of using parameters is that, if you're embedding QuickSight, you could retrieve this value dynamically and pass it to the dashboard. Then if you wanted to, say, generalize your for different yearly goals, the goal could be passed and dynamic (rather than hard-coded in a calculated field).
We could achieve it with a trick, just apply some function that returns a number to one of your columns, and make it 0, then add your constant number:
Calculated field: goalFor2020
Formula: count(email) * 0 + 20000
It does the trick, but there might be a better way to do it.
I have tried something like this:
distinct_countIf({dimension},{dimension}='xxx')*
+distinct_countIf({dimension},{dimension}='xxx')*
just makes the discount_countif meet the requirement, so it will return to 1. And use 1* the number you want to hardcode. If the requirement does not meet, it will return 0 so it won't add up the number

Is there a way to update sum of row in 2D array?

Let's say I have a 2D array in Java. Is there a way such that if I have calculated the sum of a row and I change a few values in that row, the value of the sum is updated automatically? Is it possible too in C ?
Build a listener which will listen to changes in the 2D array. If any value gets changed, the listener will trigger a method which will update the sum.
Take a look at the DefaultListModel. You can use the fireContentsChanged method to specify the actions you want to take when values get changed.
I don't know if C has something like this. Maybe you can write your own Listener.

Orbeon form builder - limit repeating element based on field value

I am using Orbeon Form Builder and have a form with a repeat section. The no. of repeats has been set to 3 however I want to vary this depending on the value set in another field. Do you know if this is possible?
The field and repeating element are in different sections on the form.
Thanks
Paul
I created a working example. The idea:
place an event handler reacting to a change of value of the count field
depending on whether the value is larger or smaller than the current number of iterations, remove or insert new iterations
this relies on the xxf:bind() function, and on knowledge of the grid repeat template
This said, as is I don't think it's a good user interface, as it can delete data upon tabbing out of the count field.

Query core data store based on a transient calculated value

I'm fairly new to the more complex parts of Core Data.
My application has a core data store with 15K rows. There is a single entity.
I need to display a subset of those rows in a table view filtered on a calculated search criteria, and for each row displayed add a value that I calculate in real time but don't store in the entity.
The calculation needs to use a couple of values supplied by the user.
A hypothetical example:
Entity: contains fields "id", "first", and "second"
User inputs: 10 and 20
Search / Filter Criteria: only display records where the entity field "id" is a prime number between the two supplied numbers. (I need to build some sort of complex predicate method here I assume?)
Display: all fields of all records that meet the criteria, along with a derived field (not in the the core data entity) that is the sum of the "id" field and a random number, so each row in the tableview would contain 4 fields:
"id", "first", "second", -calculated value-
From my reading / Googling it seems that a transient property might be the way to go, but I can't work out how to do this given that the search criteria and the resultant property need to calculate based on user input.
Could anyone give me any pointers that will help me implement this code? I'm pretty lost right now, and the examples I can find in books etc. don't match my particular needs well enough for me to adapt them as far as I can tell.
Thanks
Darren.
The first thing you need to do is to stop thinking in terms of fields, rows and columns as none of those structures are actually part of Core Data. In this case, it is important because Core Data supports arbitrarily complex fetches but the sqlite store does not. So, if you use a sqlite store your fetches are restricted those supported by SQLite.
In this case, predicates aimed at SQLite can't perform complex operations such as calculating whether an attribute value is prime.
The best solution for your first case would be to add a boolean attribute of isPrime and then modify the setter for your id attribute to calculate whether the set id value is prime or not and then set the isPrime accordingly. That will be store in the SQLite store and can be fetched against e.g. isPrime==YES &&((first<=%#) && (second>=%#))
The second case would simply use a transient property for which you would supply a custom getter to calculate its value when the managed object was in memory.
One often overlooked option is to not use an sqlite store but to use an XML store instead. If the amount of data is relatively small e.g. a few thousand text attributes with a total memory footprint of a few dozen meg, then an XML store will be super fast and can handle more complex operations.
SQLite is sort of the stunted stepchild in Core Data. It's is useful for large data sets and low memory but with memory becoming ever more plentiful, its loosing its edge. I find myself using it less these days. You should consider whether you need sqlite in this particular case.

Core Data calculation result at startup

Thanks for the help.
I have a doc based Core Data app consisting of a table with two columns. The column cells are populated with US Currency dollar values. I have two labels at the bottom of each column with Number formatters. Each label displays the sum of it's respective column. I'm doing this with bindings:
Bound to the arrayController
Controller Key - arrangedObjects
modelKey - #sum.regAmount, #sum.regAmount1
The label attribute Types are int 16 in the data model.
Anyway, these calculations work fine, and the resulting values are displayed at startup.
What I need to do is also display the difference between the two resulting sums at startup in a third label. For some reason I can't pick up the sum values to preform the calculation.
This action works using a sender:
(runningBalance.intValue = (theDeposits.intValue - theAmounts.intValue));
How can I automatically display the calculated difference of the two sums at startup without manually executing the action?
Thanks again.
Paul
You don't need an action, you need a model key you can bind to just as you do with the sums. Then you bind that to the label's display(?) property and it should be called automatically.

Resources