I have an excel sheet / Yaml file containing few records.
I was wondering if rails provide a way to achieve pagination while reading data from yaml document or excel sheet.
Try Kaminari gem.
You can paginate through any kind of Array-ish object using Kaminari::PaginatableArray
> p Kaminari::PaginatableArray.new([*1..100]).page(3).per(20)
[41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]
Another good pagination gem is will_paginate
It works really well with active record relations, and will also paginate arrays as long as you require the right file first. See https://stackoverflow.com/a/8407304/441979
Related
Hey I have an issue with trying to do a reverse order lookup or a bottom up vlookup
My formula is
=ARRAYFORMULA(IFERROR(VLOOKUP(A3:A,{'movement co'!C:R;bfitt!C:R;gladstone!C:R;parkhurst!C:R;mayfield!C:R;alexandria!C:R;'crows nest'!C:R;newtown!C:R;'gregory hills'!C:R;annandale!C:R;graceville!C:R;'south penrith'!C:R;'north melbourne'!C:R;'back on track'!C:R;'elsternwick'!C:R;'brighton'!C:R},{16,2,3,4,15,10,5},0)))
This looks over multiple tabs/sheets to gather the data which works fine, but I need it to look at the last added row which I can't seem to make work with a sort function.
Any ideas?
try:
=ARRAYFORMULA(IFERROR(VLOOKUP(A3:A, SORT(
{'movement co'!C:R, ROW('movement co'!C:R);
bfitt!C:R, ROW(bfitt!C:R);
gladstone!C:R, ROW(gladstone!C:R);
parkhurst!C:R, ROW(parkhurst!C:R);
mayfield!C:R, ROW(mayfield!C:R);
alexandria!C:R, ROW(alexandria!C:R);
'crows nest'!C:R, ROW('crows nest'!C:R);
newtown!C:R, ROW(newtown!C:R);
'gregory hills'!C:R, ROW('gregory hills'!C:R);
annandale!C:R, ROW(annandale!C:R);
graceville!C:R, ROW(graceville!C:R);
'south penrith'!C:R, ROW('south penrith'!C:R);
'north melbourne'!C:R, ROW('north melbourne'!C:R);
'back on track'!C:R, ROW('back on track'!C:R);
'elsternwick'!C:R, ROW('elsternwick'!C:R);
'brighton'!C:R, ROW('brighton'!C:R)}, 17, 0),
{16, 2, 3, 4, 15, 10, 5}, 0)))
I am pulling some tickets from Jira to a sheet and then perform some calculations on each of the rows.
Separately, I am pulling any new tickets on another tab to see if any new tickets need calculation. So my current setup looks like this:
Tab1 "Calc" sheet
Issue 113, Description, Priority, Score
Issue 112, Description, Priority, Score
In the same sheet I have a separate tab to pull any new tickets from Jira
Tab2 "Pull" sheet
Issue 115, Description, Priority
Issue 114, Description, Priority
Issue 113, Description, Priority
Issue 112, Description, Priority
Now because I have two new tickets 114 & 115, I need to copy these rows over into Tab1, without overriding the existing data.
How can I do this?
I have a query that results in an ActiveRecord::Relation:
> query.class
=> ActiveRecord::Relation
Usually these two expressions yield the same results, but I have a problem where they yield different results:
query.pluck(:id).uniq.sort
query.map(&:id).uniq.sort
For example:
[14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 321, 322, 323, 324, 325]
vs
[310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325]
The query in question is a paging query. I have 116 sample users and the query is:
"SELECT users.* FROM users WHERE users.company_id = 2 LIMIT 25 OFFSET 100"
It's not clear to me why that should ever be the case, or what I should be looking for. Any suggestions as to why they might be different?
The documentation suggests they should be equivalent.
Your query:
SELECT users.* FROM users WHERE users.company_id = 2 LIMIT 25 OFFSET 100
doesn't have an ORDER BY clause so you have no reason to expect any particular 25 rows to come back. Keep in mind that the rows in a table have no natural order so you always need to explicitly specify an order if you need a specific order.
Add an ORDER BY and you should get the same results from both the pluck and map approaches.
I need to create subscale scores for 4 subscales of the REI: REI_Appear; REI_Hlth; REI_Mood; REI_Enjoy. The items comprising each subscale are as follows:
Appearance (9 items): 1, 5, 9, 13, 16, 17, 19, 21, 24
Health (8 items): 3, 6, 8, 15, 18, 20, 22, 23
Mood (4 items): 2, 7, 12, 14
Enjoyment (3 items): 4, 10, 25
For example, I have placed REI_Appear in the target variable but then im unsure of what to place in the numeric expression section for it to work?
There are several important issues.
Do you want means or sums or some other composite?
Do any items need reversing?
How do you want to handle missing data?
Assuming you want means, there are no items needing reversing, and you want a participant to have at least 3 items to get a score, then you could use:
compute REI_appear = mean.3(item1, item5, ..., item24).
EXECUTE.
where you replace item1 etc. with the relevant variable names.
I have an existing post dedicated to the topic of computing scale scores for psychological tests which discusses some of these issues further.
it's a noob question so hope somebody can help on this
I want to transform the resultset from the query which has a multiple lines for one user to a single row of data for one activity
i get this data
userid, date, activity_id, parameter_id, parameter_value
545, 2011/9/11, 1, 4, 20
545, 2011/9/11, 1, 5, 10,
545, 2011/9/11, 1, 6, 30,
i want it to convert to
userid, date, activity_id, parameter_4_id_value, parameter_5_id_value, parameter_6_id_value
545, 2011/9/11, 1, 20,10,30
any example will be really helpful. Thank you
If you are talking about pulling data from MySQL you can use GROUP_CONCAT to do something like this. See this other answer for an example https://stackoverflow.com/a/276949/511203