回答編集履歴
1
修正
test
CHANGED
@@ -6,25 +6,27 @@
|
|
6
6
|
|
7
7
|
@labels = [*6.days.ago.to_date..Time.zone.today]
|
8
8
|
|
9
|
+
hash = (6.days.ago.to_date..Time.zone.today).to_h { |day| [day, 0] }
|
10
|
+
|
9
11
|
|
10
12
|
|
11
13
|
#カテゴリーの数だけ繰り返し実施
|
12
14
|
|
13
15
|
@r1, @r2, @r3, @r4, @r5, @r6 = (1..6).map do |i|
|
14
16
|
|
15
|
-
Record.reorder(nil).eager_load(bookshelf: :category)
|
17
|
+
datahash = Record.reorder(nil).eager_load(bookshelf: :category)
|
16
18
|
|
17
|
-
.where(yyyymmdd:(6.days.ago.to_date)..(Time.zone.today))
|
19
|
+
.where(yyyymmdd:(6.days.ago.to_date)..(Time.zone.today))
|
18
20
|
|
19
|
-
.where("categories.id=#{i}")
|
21
|
+
.where("categories.id=#{i}")
|
20
22
|
|
21
|
-
.group("records.yyyymmdd")
|
23
|
+
.group("records.yyyymmdd")
|
22
24
|
|
23
|
-
.order("categories.id")
|
25
|
+
.order("categories.id")
|
24
26
|
|
25
|
-
.sum(:summinutes)
|
27
|
+
.sum(:summinutes)
|
26
28
|
|
27
|
-
|
29
|
+
hash.merge(datahash).values
|
28
30
|
|
29
31
|
end
|
30
32
|
|