Grails each tag with iteration - grails

Hey. How can i have a variable in each tag to be an iterator (for example, first time run cycle takes value=1, second time value=2, and so on..

The status attribute is what you are looking for. See below:
<g:each collection=${books} var="abook" status="i">
${i}
</g:each>
if you call ${i} inside the each tag it will return the current iteration count.
Assuming the books collection contains 5 books, the output will be:
0
1
2
3
4

Related

How to use a Lambda function with Reduce to repeat row N numbre f time in google sheets

Hello I've tried using text manipulation to achieve the results, and while it works - I don't think it's an efficient way to do it and there is limitations with how many times it can be done.
I was trying to figure out how to get it done with reduce but it having hard time to figure it out.
This is the current table
Unique ID
Some other Info
How many times to repeat
123
Some Info
2
456
Some Info
3
The result would be
Unique ID
123
123
456
456
456
Thank you.
Here's one way to do this:
=ArrayFormula(REDUCE("Unique ID",SEQUENCE(COUNTA(A2:A)),LAMBDA(a,c,{a;IF(SEQUENCE(INDEX(C2:C,c)),INDEX(A2:A,c))})))
Explanation
The LAMBDA inside REDUCE works by taking 3 parameters: an accumulator (a), a current value (c) and the operation to perform using them.
The accumulator (a) is initialized to the first argument of REDUCE, which is "Unique ID" and every time the inner LAMBDA is executed, the accumulator updates with the result of that execution.
The current value (c) is a variable parameter and it takes on all the values provided in the second argument of REDUCE SEQUENCE(COUNTA(A2:A)) (1).
Let's assume (1) returns:
1
2
The main work happens here:
{a;IF(SEQUENCE(INDEX(C2:C,c)),INDEX(A2:A,c))} (2)
Before this piece of code is executed, a has a value of "Unique ID" and c has a value of 1.
When it executes for the first time, a and c are replaced with their initial value, so we get:
{"Unique ID";IF(SEQUENCE(INDEX(C2:C,1)),INDEX(A2:A,1))}
Now c becomes 2 and a becomes
{"Unique ID";IF(SEQUENCE(INDEX(C2:C,1)),INDEX(A2:A,1))}
So when (2) is executed for the second time, this is what we get:
{{"Unique ID";IF(SEQUENCE(INDEX(C2:C,1)),INDEX(A2:A,1))};
IF(SEQUENCE(INDEX(C2:C,2)),INDEX(A2:A,2))}
We have now gone through all the values of c so the formula stops executing and that's effectively what it returns.
The amount of iterations REDUCE does depends on the size of its second parameter.
Let's see another example. Assume (1) returns:
1
2
3
First time c=1, a="Unique ID":
{"Unique ID";IF(SEQUENCE(INDEX(C2:C,1)),INDEX(A2:A,1))}
Second time c=2, a=PREVIOUSLY_RETURNED_ARRAY:
{{"Unique ID";IF(SEQUENCE(INDEX(C2:C,1)),INDEX(A2:A,1))};
IF(SEQUENCE(INDEX(C2:C,2)),INDEX(A2:A,2))}
Third and last time c=3, a=PREVIOUSLY_RETURNED_ARRAY:
{{{"Unique ID";IF(SEQUENCE(INDEX(C2:C,1)),INDEX(A2:A,1))};
IF(SEQUENCE(INDEX(C2:C,2)),INDEX(A2:A,2))};
IF(SEQUENCE(INDEX(C2:C,3)),INDEX(A2:A,3))}
And that's the array REDUCE returns.
Do you see a pattern?
A different approach could be-
=QUERY(FLATTEN(INDEX(SPLIT(REPT(A2:A3&"|",C2:C3),"|"))),"where Col1 is not null")

Google Sheets VLOOKUP/IF

Plain english: Output 1 (yes) if the same ID# has more than one entry in the sheet within 5 minutes.
Example sheet, feel free to change anything: https://docs.google.com/spreadsheets/d/184jhnAmu63HSYl69prnAP7xo7j2PFvzjrWgDS4zj7dU
My thought is to get VLOOKUP to output something with an IF statement. But could also VLOOKUP in column E, IF calculation in column F?
VLOOKUP: input column D, output 1 in column e when input value is between 0 and 0.00347222221898846 (5 minutes reformatted). Output 0 if >0.00347222221898846.
Then I was trying to have an IF statement parse column A so that if the same value in A is present within the last 5 minutes. But I can't really figure out the IF statement.
Something like: time elapsed is less than 5 minutes (0.00347222221898846) AND that ID# was a previous entry (within the last 5 minutes). In some instances, another ID# will be the previous entry, but still within 5 minutes, so the IF can't just look up one row.
Well, I ended up just using IF/AND statements and a few extra calculation columns, see example sheet.
If anyone has any more efficient methods, let me know.

Loop through fields in rdlc report

I have an Rdlc report
In this report I have a field which takes its values by this expression
(Round(((First(Fields!Occurs.Value) / First(Fields!TotalDistance.Value))* 10000),2)
but in some cases (TotalDistance.Value) = 0 so the previous expression returns Infinity,
So I need to get the next record in case of that field equals 0 ,
If also next field equals 0 , I want to get the next one
I looked for way of getting next record but didn't find
I only found (First , Last) methods,
How can I do that ?
instead of using First or Last if you don't care which record as long as it isn't 0 then couldn't you use an aggregate function. ex:
(Round(((First(Fields!Occurs.Value) / MAX(Fields!TotalDistance.Value))* 10000),2)
you could use Max, Min or Avg to get a value. I am unaware of any way within the rdlc to loop through the records like you are asking.
Another completely different way could be to load the data into a datatable then add a column to contain the calculated value and use some code to calculate the values before being passed to the report.

Grouping and Filtering rows in reportviewer rdlc

I currently have a report viewer page - rdlc and displaying information from a dataset. My dataset returns information like:
Meeting - 3 hours 5 cases
Visit - 2 hours 2 cases
Organization - 5 hours
Prepare - 3 hours
I want to display in a table a totals row for all the activities that have 'case' and the second row will be the total for all activities WITHOUT 'cases.
Like so:
Totals with cases: 5 hours 7 cases
Totals without cases: 8 hours
Is there a way that i can display this information by entering a specific expression to filter based on the number of cases?
I tried this for an expression for the cell i want to show the number of hours that don't have a case but will always get the totals for both case and without case.
=IIf(Fields!Cases.Value is Nothing, Sum(Fields!Hours.Value), Nothing)
I figured out the work around. I created a table with a single row and for that row i entered the following expression for the GoupOn:
=IIf(Fields!Cases.Value is Nothing," " ,Fields!OfficeName.Value)
and in the first column i wrote an expression to see if it was case or non case based on the number of cases. The table when ran produced two rows one for case and the other for non-case with proper information in each.

Getting the current item number or index when using will_paginate in rails app

I have a rails app that stores movies watched, books read, etc. The index page for each type lists paged collections of all its items, using will_paginate to bring back 50 items per page. When I output the items I want to display a number to indicate what item in the total collection it is. The numbering should be reversed as the collection is displayed with most recent first. This might not relate to will_paginate but rather some other method of calculation.
I will be using the same ordering in multiple types so it will need to be reusable. As an example, say I have 51 movies. The first item of the first page should display:
Fight Club - Watched: 30th Dec 2010
Whilst the last item on the page should display:
The Matrix - Watched: 3rd Jan 2010
The paged collection is available as an instance variable e.g. #movies, and #movies.count will display the number of items in the paged collection. So if we're on page 1, movies.count == 50, whilst on page 2 #movies.count == 1. Using Movie.count would give 51.
If the page number and page size can be accessed the number could be calculated so how can they be returned? Though I'm hopeful there is something that already exists to handle this calculation!
It feels a bit hacky, but I've come up with a working solution. I create an instance variable in the view:
#count = #movies.total_entries - #movies.offset
Then when rendering each movie I output #count and decrement it.
As per my previous example with 51 items on two pages: total_entries == 51, and offset == 0 (page 1) or 50 (page 2).
Have a look at the built-in function:
<%= page_entries_info #posts %> #-> Displaying posts 6 - 10 of 26 in total

Resources