Combine multiple Tabs with common tables in Google Sheets - join

Good day! I'm quite new with sheets so I hope that am asking the right question. Please see the link for the sample file below:
https://docs.google.com/spreadsheets/d/1eDBqzwsyakyP3RGWAdNKs76Ia7JOGFwjIl_czREU0s0/edit?usp=sharing
What I'm trying to do is that I'd like to combine 4 tabs of schedule into 1, with the first column being combined in the process (note that "NAME") column may have additional entries on week 2 and so on. Once I have that info in the "Combined" Tab, I will then combine it with 12 similar worksheets. I hope that I can get this one done first, I just learned about the importrange function, Hope you can also give me some tips on how to make it faster if I get to that second step in creating my consolidated file. Thanks in advance and more power to the people of Stackoverflow!

use:
=ARRAYFORMULA(IFNA({UNIQUE(QUERY({'Week 1'!A:A; 'Week 2'!A:A; 'Week 3'!A:A; 'Week 4'!A:A},
"where Col1 is not null", 1)),
VLOOKUP(UNIQUE(QUERY({'Week 1'!A:A; 'Week 2'!A:A; 'Week 3'!A:A; 'Week 4'!A:A},
"where Col1 is not null", 1)), 'Week 1'!A:H, COLUMN(B:G), 0),
VLOOKUP(UNIQUE(QUERY({'Week 1'!A:A; 'Week 2'!A:A; 'Week 3'!A:A; 'Week 4'!A:A},
"where Col1 is not null", 1)), 'Week 2'!A:H, COLUMN(B:G), 0),
VLOOKUP(UNIQUE(QUERY({'Week 1'!A:A; 'Week 2'!A:A; 'Week 3'!A:A; 'Week 4'!A:A},
"where Col1 is not null", 1)), 'Week 3'!A:H, COLUMN(B:G), 0),
VLOOKUP(UNIQUE(QUERY({'Week 1'!A:A; 'Week 2'!A:A; 'Week 3'!A:A; 'Week 4'!A:A},
"where Col1 is not null", 1)), 'Week 4'!A:H, COLUMN(B:G), 0)}))
then use:
=IMPORTRANGE("1eDBqzwsyakyP3RGWAdNKs76Ia7JOGFwjIl_czREU0s0", "Combined!A1:100")

Related

option_groups_from_collection_for_select using three tables in rails 4

Generally we show option_groups_from_collection_for_select to group data using two tables such as cities as per provinces. That's pretty simple and I have done it.
Here I have a to show locations(from Locations table) grouped into cities(from City table) and cities grouped into Provinces(from provinces table). I am not able to figure out whether its even possible or not.
Just refer to select_tag document here
We can create a select tag like this example
= select_tag '', options_for_select([ ["Option 1", 1], ["Option 2", 2] ])
For simply, your work is just how to create this array from the query
[ ["Option 1", 1], ["Option 2", 2] ]

Chartkick/Google charts only using first colour in array on bar graph

I'm using chartkick in rails to produce graphs like this:
<% #graphs.each_with_index do |g, i| %>
<%= column_chart g, discrete: true, min: 0.0, max: 1.1, colors: ["pink", "blue", "red"],
library: {hAxis: {textStyle: {fontSize: 10}}} %>
<% end %>
Where g is some data like:
[['test1', 0.1],['test2',0.4],['test3',07]]
My problem is that instead of the first three columns being pink, blue, and red, they're all pink!
Does anyone know how to make the bars different colours?
Edit:
Toy example:
<%= column_chart [['test1', 20], ['test2', 30],['test3', 30]], colors: ["pink", "red", "blue"] %>
As seen here https://github.com/ankane/chartkick/issues/77 it's not possible unless you use two series. I would recomend using the Google Charts directly it might solve your problem.

Rails 12 hour AM/PM range for a day

This is a really simple question, and it's probably been asked and answered before, but I haven't been able to find anything.
Anyway, I need a range/array for 12 hour time, so like 12AM - 11AM, 12PM - 11PM. You probably get the gist of it. Right now I'm trying to do an absurdly complicated method involving mapping AM onto one array, PM onto another one, and then joining the two arrays together. There has to be an easier way to do this.
I know about Rails time_select, but I need a different format than what it provides. Any suggestions?
Clarification: So what I'm looking for is the 12-hour clock, with AM and PM. If I wanted a 24-hour clock, I could just do (0..24), and be done. But the 12-hour clock goes from 12-11 AM, and then goes from 12-11 PM. I'm pretty sure someone has done this before.
I agree with #MrYoshi's comment, the easiest way of formatting a date is .strftime(),
see RubyDoc for all possible options
Example:
Time.now.strftime("%I:%M %p")
output: HH:MM AM
Or what you literally asked for:
Time.now.strftime("%I:00")
output: HH:00
As you mentioned time_select I assume you want to offer time as a user selectable range, so try these options for time_select(more options):
time_select 'game', 'game_time', {:minute_step => 60, :ampm => true}
also this previous question: Time select form helper with 12 hour format for Rails 3?
Rails does this built in
<%= f.time_select :start, {ampm: true} %>
http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-time_select
I know this has already been answered awhile ago with the built in. But I needed a custom function to get these values and wrote this:
times = {"12 AM" => 0}.merge!(1.upto(11).collect { |n| {"#{n} AM" => n} }.reduce(Hash.new, :merge)).merge!({"12 PM" => 12}).merge!(1.upto(11).collect { |n| {"#{n} PM" => n + 12} }.reduce(Hash.new, :merge))
This yields:
{"12 AM"=>0, "1 AM"=>1, "2 AM"=>2, "3 AM"=>3, "4 AM"=>4, "5 AM"=>5, "6 AM"=>6, "7 AM"=>7, "8 AM"=>8, "9 AM"=>9, "10 AM"=>10, "11 AM"=>11, "12 PM"=>12, "1 PM"=>13, "2 PM"=>14, "3 PM"=>15, "4 PM"=>16, "5 PM"=>17, "6 PM"=>18, "7 PM"=>19, "8 PM"=>20, "9 PM"=>21, "10 PM"=>22, "11 PM"=>23}

group by in active records

I have one instance variable with two records.
id item_with_detail_id quantity
100 205 3
101 205 5
Now, i want the result as follows using Active record group_by .
100 205 8
i tried with
#bill_details=#bill_details.group_by{|bd| bd.item_with_detail_id}.values.map(&:first)
but its not working. Please help me to achieve the result.
#bill
select("id, item_with_detail_id,SUM(quantity)").group("item_with_group_id")
Finally i solved this problem. As follows
In the controller =>
#bill_details = #bill_details.group_by{|bd| bd.item_with_detail_id}.values
it will give the following result
#[[#<BillDetail id: 100, item_with_detail_id: 205, quantity: 3, #<BillDetail id:101, item_with_detail_id: 205, quantity: 5]]
And in the view page:
<% for bd in #bill_details%>
<%quantity=0%>
<%for bill_detail in bd%>
<%quantity+=bill_detail.quantity%>
<%end%>
<%bd=bd.first%>
<%end%>

How to print out a random number between a range? [duplicate]

This question already has answers here:
How to get a random number in Ruby
(18 answers)
Closed 5 years ago.
I've the following but it doesn't work:
<%= (5..30).sample %>
Give this a shot.
<%= [*5..30].sample %>
...or...
<%= rand(5..30) %>
This would generate a random number in that range:
5 + rand(25)
Simply add the min to the rand(max-min).
Range has no #sample method. Use the one from Array instead.
<%= (5..30).to_a.sample %>
for 1 random number:
a = (5...30).sort_by{rand}[1]
# => 7
It seems more verbose than what others have suggested, but from here, it's easy to pick three random unique numbers from the same range:
a = (5...30).sort_by{rand}[1..3]
# => [19, 22, 28]
Or 20:
a = (5...30).sort_by{rand}[1..20]
# => [7, 12, 16, 14, 13, 15, 22, 17, 24, 19, 20, 10, 21, 26, 29, 9, 23, 27, 8, 18]
Might come in useful for someone who needs to display 5 random foos in their sidebar
EDIT:
Thanks to Marc-Andre Lafortune, I discovered that the following is much better:
a=[*5..30].sample(3)

Resources