Core Data: split into sections based on custom logic - ios

I have a large data set of objects, made up of 2 large-ish subsets.
Set 1 has about 10,000 objects in it.
Set 2 has about 70,000 objects in it.
The object sets have many-to-many relationships between them.
There are also "favorites" subsets for both sets.
Before I display set 1 or set 2, I will have a subset from the other set to drive my query/fetch.
Let's say:
I have selected 10 objects from set 1.
I would like to display set 2.
I'd like set 2 to be grouped into 3 sections:
Section 1 would be objects in set 2 that have relationships with the 10 selected objects from set 1.
Section 2 would be objects in the "favorites" subset that are NOT in #1.
Section 3 would be the rest.
So, conceptually, I have the following steps (again, given 10 selected objects from set 1 and a "favorites" subset from set 2):
Figure out which objects in set 2 correspond to the selected objects from set 1.
Set #1 aside and remove them from the overall set (but only for this display).
Figure out which objects are left in set 2 that are also in the "favorites" subset.
Set #2 aside and remove them from the overall set (again, only for this display).
Figure out which objects are left.
At the end of this, I'd like to display the 3 sections in a UITableView.
I saw this question, but I wasn't sure whether the supplied answers were:
Still valid (it's been almost 7 years since the question was asked)
Valid for my use case. (Would the calculated method return a section number? If so, would I have to pass in both subsets on which I am doing my filtering? How is that going to perform with such large data sets?)

Related

How do I create a list of non-repeating cells/numbers in Google Sheets?

I’m trying to emulate Minesweeper in Google Sheets, and for this I want to create a second map adjacent to the first with all of the correct values already in it. To randomize bomb position, I need a list of random numbers or cells(cells would be preferable). However, I cannot figure out how to do this without ending up repeating numbers. The result would ideally be a vertical array of cell coordinates. Thank you!
Answer
The following formula should produce the result you desire:
=SORTN(FLATTEN(MAKEARRAY(10,10,LAMBDA(row,col,ADDRESS(row,col)))),20,,RANDARRAY(100),)
In =MAKEARRAY, change the first 10 to adjust how many rows to randomly choose from, or the second 10 to adjust how many columns to choose from. The value in =RANDARRAY must be equal to the product of the number of rows and the number of columns. (e.g. in the above example, 10*10=100).
Change the 20 to adjust how many randomly chosen values to return.
Explanation
=MAKEARRAY is used to generate an array of every possible row and column combination. It accepts a =LAMBDA, which in this case is just the =ADDRESS function. The first two arguments of =MAKEARRAY determine how large the array should be, which is why changing them adjusts how many rows/columns to randomly pick from.
Then, the result of =MAKEARRAY is squashed into a single column using the =FLATTEN formula.
Finally, the entire thing is sorted randomly using =SORTN combined with =RANDARRAY. =SORTN also limits the number of results that are returned dependent on its second argument, which is why changing it adjusts how many results are returned.
If you want information on how to "freeze" the value of =RANDARRAY so it doesn't recalculate each time you change something, check out this question by player0.
Functions used:
=MAKEARRAY
=LAMBDA
=ADDRESS
=FLATTEN
=SORTN
=RANDARRAY

Filter out entire row based on one result in Tableau

Learning Tableau through tutorials so bear with me.
I have a list I need to filter, but when I set up a calculated field, it only filters out a single cell, not the whole row.
Here's the example I made:
1
In this table, I want to filter out entire rows that have negative values. Alice and Bob would be hidden, but Cat and Dee would remain.
When I add a (IF SCORE <0 THEN 0 ELSE 1 END) filter, I only filter out that single value, not the whole row. Example:
2
How do I write a calc to hide the rows with negatives?
Sorry i cannot recreate your example, but i used one of my use cases.
just drag "name" to the filter pane and in the filter options go to conditions
there you need to apply the logic of Value > 0
This will make the rows disappear. Hope this helps

Editing labels of series in Google Spreadsheets

I have data listed in columns as below and by highlighting it all including the names and the units and then clicking Insert -> Diagram..., I can easily make the following graph:
The labels are correct LabelA, Labelb, and LabelC in this case.
But if the label names are not in the same column as the data, then I cannot make this graph. In the data structure below where names and data are in different columns, I again highlight all data cells as well as their units and names (by holding down the ctrl button and clicking all the cells with the cursor):
It is clear that the software does not know that it should assign the names as labels. Is there a method to make the graph show the correct labeling as in the first scenario but with the second scenario's data structure?
you could combine the data in another place with formula:
={{A1,C1,E1};{B4:B6,D4:D6,F4:F6}}
and then plot the diagram as usual.

Array logic with indexpathforselectedrow

So I’m attempting to grasp nested array logic using indexpathforselectedrow!
therefore, ill be using examples to explain my confusion.
my first thought: lets say I have
var colors: array = [“red”,”orange”,”yellow”]
in a table view.
If i got the indexpathforselectedrow of orange, what would that index value be? I assume that would be section = 0, row = 1, so [0][1]. would that be correct? or since this is a simple array, would the value just be one value? 1?
Secondly, if I have a more advanced array (please let me know if this array setup is correct)
var morecolor: [[“green”,”blue”,”teal”][“light green”, “dark green”]
[“light blue”, “dark blue”][“light teal”, “dark teal”]]
if I selected green (first array/ array 0) and wanted to segue to the light/dark green array, the second array (or first), how would i go about this?
An index path (NSIndexPath) consists of a section and a row. Both are integers, zero-based.
The first section in your table is section 0, the second is 1, etc. Same for rows.
You implement numberOfSections to tell how many sections you want, and numberOfRowsInSection to tell how many rows in each section (that method passes you the section number it needs the number of rows for).
Typically you have a model that represents the data to be displayed, and you index into that model in cellForRowAtIndexPath.
If you have a one-dimensional model, say a simple list of colors, you might have just one section, and as many rows as colors in your model. The color corresponding to any row would be something like:
model.colors[indexPath.row]
You can ignore section here because you know it's always zero (you only have 1 section).
If you have a two-dimensional model, say a set of themes each of which consists of several colors, you would have as many sections as themes, and rows as colors in each theme. The theme and color corresponding to any row would be something like:
model.theme[indexPath.section].colors[indexPath.row]
Many table view methods use index paths, so it's useful to know how they work.
T0 answer your first question, yes you're correct in saying that such a call would return an index path for item at section 0, row 0, but in actuality since it's an index path and not a regular integer representation the rows aren't represented as 1 2 3 4... etc but rather 0 64 128 etc... Thus, in order to get the row that was returned you can access it using indexPath.row which returns the int representation of the row selected.

Make operations between different numbers of all cells on tableview iOS

I HAVE THIS: A tableview with cells with a label were user gets a number. (From core data from a detail view).
WHAT I WANT: How to make an operation with all the cells with a number on a label on that cell.
Example, sum up all the cells label. label at cell 1, + label at cell 2, and so on.
MY PROBLEM: i can do it but with a lot of code, i have to make an operation for each cell user may create. (Maybe user creates 1 or 20 cells), and i think to make an operation with the index path and value for 20 cells its not necessary.
Im sure its another way but i don't know how.
Thanks from know to everybody.
So, you have a couple of options, this one is little code but isn't so efficient as the numbers start to add up:
NSArray *myNumbers = ...;
I'm assuming that this array exists and is being used to drive your table view. It contains the instances of your Numbers entity. Based on that, you can get the sum:
NSNumber *sum = [myNumbers valueForKeyPath:#"#sum.mynumber"];
The alternate route is to use NSExpression and NSFetchRequest to run the summing operation on the entities in the data store without actually reading everything into memory like the array does.
There is also a middle ground option where you could just run an NSFetchRequest to get only the mynumber values in dictionaries and then use valueForKeyPath:. The value of this option depends on how many attributes your Numbers entity has and what they contain.

Resources