How to do a "compact push" - angular-gridster2

e.g. in this demo https://tiberiuzuld.github.io/angular-gridster2/push
When I move item 2 to the top, 1 and 3 are moved down and an empty row (4) is added:
I could not find a way to get rid of this empty row: i.e. I'd like to get this result after moving 1 to the top:
Is there a setting or other way to get this behaviour?

Related

How to copy cells to new location while removing blanks?

I am looking for a formula that reads one row of 5 cells, and fills the new row with the contents of the original row, but with the non-numeric cells removed and the rest shifted to the left:
Original
*P* *Q* *R* *S* *T*
*23* 8 3 2
(Note: The "blank" cells aren't actually blank, the only way I can get them to read correctly in a formula is if I reference them as "". I am guessing this is because P23:T23 are also references to other cells, instead of direct numbers.)
Result
*B* *C* *D* *E* *F*
*3* 8 3 2
I am looking for the formula to be executed in cell B3. I thought this would work:
=FILTER(P23:T23,NOT(ISBLANK(P23:T23)))
but, it didn't get rid of the blank cells, probably because Google Sheets doesn't think P23 & S23 are blank. Any ideas?
Edit: Here's a link to the sheet: https://docs.google.com/spreadsheets/d/14M6XggpIUXNdZ5ihQ7ipim44wsn4u-ywMZCG4kYMlQY/edit?usp=sharing
try:
=INDEX(SPLIT(JOIN(",", IF(ISNUMBER(P23:T23*1), P23:T23, )), ","))
or:
=FILTER(P23:T23, ISNUMBER(P23:T23))

Increment 2 different Ids based on selected option

I'm trying to update a working solution of incrementing one ID based on several conditions, so I was using the ROW() function without any issue. But now I'm trying to increment 2 different IDs based on selected option as shown in the screenshot below, where I've started the following so far:
=ARRAYFORMULA(IF(LEN(A2:A),COUNTIFS(A2:A, A2:A, ROW(A2:A), "<="&ROW(A2:A),A2:A,"Option 2"),))
Can anyone bring some light on this scenario: thanks
Link of spreadsheet illustrating my situation: here
You have to first check if the value is Option 1/Option 2 or not. A way to do this without using OR (which can't be iterated over an array) is this:
IF(A2:A="Option 1",0,1)*IF(A2:A="Option 2",0,1)
Next, you can wrap this into another IF so that the returned value depends on whether the previous condition is true. So, if option is not 1 nor 2, the corresponding value should result from the count of all the previous values which are not 1 or 2. So the COUNTIFS should check if the option is not 1 nor 2. Something like this:
29999 + COUNTIFS(A2:A,"<>Option 1",A2:A,"<>Option 2",ROW(A2:A), "<="&ROW(A2:A))
Finally, if the option is 1 or 2, the returned value should result from hte count of all previous 1 and 2 values. Since that's an OR condition, you have to sum two different COUNTIFS, one for option 1 and one for 2. Could be like this:
9999 + COUNTIFS(A2:A,"=Option 1",ROW(A2:A), "<="&ROW(A2:A)) + COUNTIFS(A2:A,"=Option 2",ROW(A2:A), "<="&ROW(A2:A))
Putting it all together, it could be like this:
=ARRAYFORMULA(IF(LEN(A2:A),IF(IF(A2:A="Option 1",0,1)*IF(A2:A="Option 2",0,1),
29999 + COUNTIFS(A2:A,"<>Option 1",A2:A,"<>Option 2",ROW(A2:A), "<="&ROW(A2:A)),
9999 + COUNTIFS(A2:A,"=Option 1",ROW(A2:A), "<="&ROW(A2:A)) + COUNTIFS(A2:A,"=Option 2",ROW(A2:A), "<="&ROW(A2:A))),""))
slight alternative:
=ARRAYFORMULA(IF(A2:A="",,IF(REGEXMATCH(A2:A, H2&"$|"&H3&"$"),
9999+COUNTIFS(REGEXMATCH(A2:A, H2&"$|"&H3&"$"),
REGEXMATCH(A2:A, H2&"$|"&H3&"$"), ROW(A2:A), "<="&ROW(A2:A)),
29999+COUNTIFS(A2:A, "<>"&H2, A2:A, "<>"&H3, ROW(A2:A), "<="&ROW(A2:A)))))

orgmode, referring to an item in a numbered list

I need to refer to the number of an item in a numbered list. For example:
1. Something
2. See item (1)
3. Something else
Orgmode lets me create hyperlinks, but these are useless in a printed document, so I need to refer to the actual number of the item. I'm not picky about how it's presented (1), <1>, 1., etc. are all fine for my needs.
There is an example in the OrgMode manual using internal links.
The following document:
1. <<first>>Something
2. See item [[first]]
3. Something else
Will export as:
1. Something
2. See item 1
3. Something else

is vector < list <marker> > the right way to approach this?

I'm trying to solve a problem for work and am a novice programmer. I have three files, both tab delimited.
File1 has two fields: *Marker_id* & position and this file is sorted by position (0-26) and then Marker_id is in an order that is a consequence of another application but is not alphabetical.The order of Marker_id is important because the goal of my program is to find a starting Marker_id and count the number of Markers between that and an ending Marker. This file contains nearly 2,500,000 entries.
File2 has one field *Marker_id* This is the same Marker_id that is used in File1, but this file contains only around 2,200,000 entries. This file is a list of "active" markers or markers that should be counted by my program.
File3 has fields position *starting_marker* ending marker *number_markers* and other fields. I need to basically update the number_markers field by counting the number of markers between start and end.
I already have code that reads file1 into
vector< list<marker> >;
where marker is a struct:
struct MARKER{
string snp_id;
bool included;
MARKER(string temp_id) : snp_id(temp_id), included(false) { }
};
And the position (0-26) from file one specifies what index in the vector to store the markers. I also successfully update the count in file3 with the number of markers between start and stop.
However, I'm having trouble implementing a function to trim my list to only "active markers." I was going to simply do MARKER.included(true); for entries in file2 until I realized file2 does not contain position and therfore, I'd have to search every list at each vector index. This is possible, I just feel like it would be incredibly slow with so many entries.
I'm trying to think of alternatives such as storing file1 in a map where the key is Marker_id, but needing to keep Marker_id's in original order for counting is hanging me up.
Does anyone have any advice? Thanks.
UPDATE (example files):
***File1***
Marker_id position
test_marker_1 1
test_marker_2 1
test_marker_3 1
test_marker_4 1
test_marker_5 1
test_marker_6 1
test_marker_7 1
test_marker_8 1
test_marker_9 1
.
***File2***
Marker_id C20020.Log R Ratio C20020.B Allele Freq
test_marker_1 0.0180 0.0010
test_marker_3 -0.0340 0.5000
test_marker_4 0.0500 0.0700
test_marker_5 0.0500 0.0700
test_marker_6 0.0500 0.0700
test_marker_7 0.0500 0.0700
test_marker_9 0.0500 0.0700
Note: test_marker_2 and test_marker_8 are omitted from file 2 and therefore, will not be included in counts.
***File3***
position copy_num sampleID startMarker endMarker conf num_Markers
1 4 C20020 test_marker_1 test_marker_3 1774.967 0
1 3 C20020 test_marker_3 test_marker_5 17.967 0
1 0 C20020 test_marker_7 test_marker_9 107.967 0
.
***My desired output***
position copy_num sampleID startMarker endMarker conf num_Markers
1 4 C20020 test_marker_1 test_marker_3 1774.967 2
1 3 C20020 test_marker_3 test_marker_5 17.967 3
1 0 C20020 test_marker_7 test_marker_9 107.967 2
As it stands now, I have everything functioning except my counts would be 3 for all three examples since I do not exclude those Markers not found in file2.
A couple of approaches come to mind.
You could sort files 1 and 2 by marker id (temporary copies, of course), then could easily determine the markers that are in file 1 but not in file 2 in a single pass. You could then use this "exclusion list" to determine markers to ignore in the other part of the algorithm. Per your numbers, this would be ~300,000 items, which could be inserted into a hash map for quick lookups.
Of course, if you have oodles of memory, you could always just put all of file 2 into a hash map, and use it in the same way.
If memory is a real issue, but the marker values are such that they define a complete space (e.g. numbers 1 to 10 million, or whatever), where markers can be mapped to offsets, then you could create a bit map of the entire space, with 1's only for markers that are active. Again, using this bitmap to exclude those markers that are to be ignored.
Basically, as long as you can get a constant-time check for the include/exclude test, you're laughing.

Filtering on the count with the Django ORM

I have a query that's basically "count all the items of type X, and return the items that exist more than once, along with their counts". Right now I have this:
Item.objects.annotate(type_count=models.Count("type")).filter(type_count__gt=1).order_by("-type_count")
but it returns nothing (the count is 1 for all items). What am I doing wrong?
Ideally, it should get the following:
Type
----
1
1
2
3
3
3
and return:
Type, Count
-----------
1 2
3 3
In order to count the number of occurrences of each type, you have to group by the type field. In Django this is done by using values to get just that field. So, this should work:
Item.objects.values('group').annotate(
type_count=models.Count("type")
).filter(type_count__gt=1).order_by("-type_count")
It's logical error ;)
type_count__gt=1 means type_count > 1 so if the count == 1 it won't be displayed :)
use type_count__gte=1 instead - it means type_count >= 1 :)