jupyter_on_rails 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jupyter_on_rails/daru/active_record_ext.rb +27 -2
- data/lib/jupyter_on_rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db480dd0b66703b18e2b2b381a2b7e8503dbbb7ad9a0d0602689059dc4b965b1
|
4
|
+
data.tar.gz: 0b7dfd212a1d16ba74d816a20e3273e73ec54838d8359501efad1755118e51c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3378f5acca6859363fe341814b483f0a8e70c0c8577497aec33330a8866ea733e87c04947a16110706bf4a207105ff846a328147b7f149f98f22d5ca226cb525
|
7
|
+
data.tar.gz: 5ecb5de5b600ba2d83cf045770c9ab0c1cd9d23181f15b57942bc0f23d7a566463c469926bdabf336cd2b76b91fb81227b0a44887aedf36f661f558faae676a1
|
@@ -5,8 +5,33 @@ module JupyterOnRails
|
|
5
5
|
module ActiveRecordExt
|
6
6
|
extend ::ActiveSupport::Concern
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
class_methods do
|
9
|
+
def to_df
|
10
|
+
relation = all
|
11
|
+
loaded_associations =
|
12
|
+
%i[includes_values preload_values eager_load_values]
|
13
|
+
.map(&relation.method(:send)).reduce(&:|)
|
14
|
+
|
15
|
+
datas = relation.flat_map do |record|
|
16
|
+
ret = [record.attributes.symbolize_keys]
|
17
|
+
loaded_associations.each do |assoc|
|
18
|
+
ret = ret.flat_map do |attrs|
|
19
|
+
assocs = record.send(assoc)
|
20
|
+
next [attrs] unless assocs.present?
|
21
|
+
|
22
|
+
assocs.map(&:attributes).map do |assoc_attrs|
|
23
|
+
new_attrs = assoc_attrs.transform_keys do |key|
|
24
|
+
"#{assoc}.#{key}".to_sym
|
25
|
+
end
|
26
|
+
attrs.merge(new_attrs)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
ret
|
31
|
+
end
|
32
|
+
|
33
|
+
::Daru::DataFrame.new(datas)
|
34
|
+
end
|
10
35
|
end
|
11
36
|
end
|
12
37
|
end
|