statosio 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.ipynb_checkpoints/[Ruby] statosio to svg-checkpoint.ipynb +1396 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +182 -0
- data/Rakefile +8 -0
- data/[Ruby] statosio to svg.ipynb +1459 -0
- data/assets/statosio.rb.png +0 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/jupyter/0-templates/d3.js +19542 -0
- data/jupyter/0-templates/dataset.json +3 -0
- data/jupyter/0-templates/html.txt +30 -0
- data/jupyter/0-templates/ruby.txt +140 -0
- data/jupyter/0-templates/statosio.js +854 -0
- data/jupyter/1-test/boilerplate-test.html +20547 -0
- data/jupyter/1-test/module-test-generate-svg.pdf +1179 -1
- data/jupyter/1-test/module-test-generate.pdf +1179 -1
- data/jupyter/1-test/module-test-html.html +20547 -0
- data/jupyter/2-examples/0-example1.svg +1 -0
- data/jupyter/2-examples/1-example2.pdf +1126 -0
- data/lib/boilerplate.rb +20563 -0
- data/lib/statosio.rb +206 -0
- data/lib/statosio/version.rb +5 -0
- data/statosio.gemspec +40 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 390a97c0b17ea4a5c9c5b1d107acd31d1ff22cd9eb3777f83648ee9f2d831cac
|
4
|
+
data.tar.gz: 24785f7fe490f6d270bea5c04084d6622aefb4fe20eccf0844b16a1cd1301bf5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f27cc45b1ffa13d97c69f8f8f3c543a4283a07d1b399954d0f91c8ed26c3a4a30d257fbaecea3b7f09186297463e1dc41edc4b36eb457b63c6f0d2e7bc562131
|
7
|
+
data.tar.gz: 794a84f6c33900b421f4e50df2f0560ab13a8ed8bf7722cc812a761b9188cbc630e8a0bbee9faec85bf32a00c903f99db1f3760acf8f4cacbe81543d5d8754ae
|
data/.gitignore
ADDED
@@ -0,0 +1,1396 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "markdown",
|
5
|
+
"id": "44709dec",
|
6
|
+
"metadata": {},
|
7
|
+
"source": [
|
8
|
+
"# Functions"
|
9
|
+
]
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"cell_type": "markdown",
|
13
|
+
"id": "60793629",
|
14
|
+
"metadata": {},
|
15
|
+
"source": [
|
16
|
+
"## obj_prepare_path"
|
17
|
+
]
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"cell_type": "code",
|
21
|
+
"execution_count": 57,
|
22
|
+
"id": "3bbf3ab7",
|
23
|
+
"metadata": {},
|
24
|
+
"outputs": [
|
25
|
+
{
|
26
|
+
"data": {
|
27
|
+
"text/plain": [
|
28
|
+
":obj_prepare_path"
|
29
|
+
]
|
30
|
+
},
|
31
|
+
"execution_count": 57,
|
32
|
+
"metadata": {},
|
33
|
+
"output_type": "execute_result"
|
34
|
+
}
|
35
|
+
],
|
36
|
+
"source": [
|
37
|
+
"def obj_prepare_path( obj, salt, status )\n",
|
38
|
+
" def helper_parse_path( str )\n",
|
39
|
+
" if str[ str.length - 1, 1 ] != '/'\n",
|
40
|
+
" str = str + '/'\n",
|
41
|
+
" end\n",
|
42
|
+
" return str\n",
|
43
|
+
" end\n",
|
44
|
+
"\n",
|
45
|
+
" def draw_obj_line_edge( l, offset )\n",
|
46
|
+
" str = ''\n",
|
47
|
+
" for i in 1..( ( l - 1 ) * offset )\n",
|
48
|
+
" str += ' '\n",
|
49
|
+
" end\n",
|
50
|
+
" if l > 1\n",
|
51
|
+
" str += \"┗\"\n",
|
52
|
+
" str += \"━\"\n",
|
53
|
+
" str += \" \"\n",
|
54
|
+
" else\n",
|
55
|
+
" str += ' '\n",
|
56
|
+
" end\n",
|
57
|
+
" return str\n",
|
58
|
+
" end\n",
|
59
|
+
" \n",
|
60
|
+
" def draw_obj_path_local( str, l, offset )\n",
|
61
|
+
" result = ''\n",
|
62
|
+
" for i in 0..( ( l - 1 ) * offset )\n",
|
63
|
+
" result += ' '\n",
|
64
|
+
" end\n",
|
65
|
+
" result += ''\n",
|
66
|
+
" result += str\n",
|
67
|
+
" return result\n",
|
68
|
+
" end\n",
|
69
|
+
"\n",
|
70
|
+
" def helper_obj_path( name, salt, k, f=nil )\n",
|
71
|
+
" str = ''\n",
|
72
|
+
" str += draw_obj_line_edge( name[ 1, name.length ].to_i, 4 )\n",
|
73
|
+
" str += 'hash[:path]'\n",
|
74
|
+
" if k.length == 0\n",
|
75
|
+
"\n",
|
76
|
+
" else\n",
|
77
|
+
" for i in 0..k.length-1\n",
|
78
|
+
" str += '[:children]'\n",
|
79
|
+
" str += '[:'\n",
|
80
|
+
" str += k[ i ].to_s\n",
|
81
|
+
" str += ']' \n",
|
82
|
+
" end\n",
|
83
|
+
" end\n",
|
84
|
+
"\n",
|
85
|
+
" if !f.nil?\n",
|
86
|
+
" str += '[:files][:'\n",
|
87
|
+
" str += f.to_s\n",
|
88
|
+
" str += '][:full]' \n",
|
89
|
+
" else\n",
|
90
|
+
" str += '[:full]'\n",
|
91
|
+
" end\n",
|
92
|
+
" return str\n",
|
93
|
+
" end\n",
|
94
|
+
" \n",
|
95
|
+
" def helper_insert_salt( salt, str )\n",
|
96
|
+
" if salt[ 0, 1 ] == ''\n",
|
97
|
+
" \n",
|
98
|
+
" else\n",
|
99
|
+
" if salt[ 0, 1 ] == '-'\n",
|
100
|
+
" else\n",
|
101
|
+
" salt = '-' + salt \n",
|
102
|
+
" end\n",
|
103
|
+
" end\n",
|
104
|
+
"\n",
|
105
|
+
" str = str.gsub( \"{{SALT}}\", salt )\n",
|
106
|
+
" return str\n",
|
107
|
+
" end\n",
|
108
|
+
"\n",
|
109
|
+
" def helper_parse_path( str )\n",
|
110
|
+
" if str[ str.length - 1, 1 ] != '/'\n",
|
111
|
+
" str = str + '/'\n",
|
112
|
+
" end\n",
|
113
|
+
" return str\n",
|
114
|
+
" end\n",
|
115
|
+
"\n",
|
116
|
+
" def draw_obj_line_edge( l, offset )\n",
|
117
|
+
" str = ''\n",
|
118
|
+
" for i in 1..( ( l - 1 ) * offset )\n",
|
119
|
+
" str += ' '\n",
|
120
|
+
" end\n",
|
121
|
+
" if l > 1\n",
|
122
|
+
" str += \"┗\"\n",
|
123
|
+
" str += \"━\"\n",
|
124
|
+
" str += \" \"\n",
|
125
|
+
" else\n",
|
126
|
+
" str += ' '\n",
|
127
|
+
" end\n",
|
128
|
+
" return str\n",
|
129
|
+
" end\n",
|
130
|
+
" \n",
|
131
|
+
" def draw_obj_path_local( str, l, offset )\n",
|
132
|
+
" result = ''\n",
|
133
|
+
" for i in 0..( ( l - 1 ) * offset )\n",
|
134
|
+
" result += ' '\n",
|
135
|
+
" end\n",
|
136
|
+
" result = result[ 1, result.length ]\n",
|
137
|
+
" \n",
|
138
|
+
" if str.index('.') != nil\n",
|
139
|
+
" result += 'File: '\n",
|
140
|
+
" else\n",
|
141
|
+
" result += 'Folder: '\n",
|
142
|
+
" end\n",
|
143
|
+
" result += str\n",
|
144
|
+
" return result\n",
|
145
|
+
" end\n",
|
146
|
+
"\n",
|
147
|
+
" def helper_obj_path( name, salt, k, f=nil )\n",
|
148
|
+
" str = ''\n",
|
149
|
+
" str += draw_obj_line_edge( name[ 1, name.length ].to_i, 4 )\n",
|
150
|
+
" str += ''\n",
|
151
|
+
" str += 'hash[:path]'\n",
|
152
|
+
" if k.length == 0\n",
|
153
|
+
"\n",
|
154
|
+
" else\n",
|
155
|
+
" for i in 0..k.length-1\n",
|
156
|
+
" str += '[:children]'\n",
|
157
|
+
" str += '[:'\n",
|
158
|
+
" str += k[ i ].to_s\n",
|
159
|
+
" str += ']' \n",
|
160
|
+
" end\n",
|
161
|
+
" end\n",
|
162
|
+
"\n",
|
163
|
+
" if !f.nil?\n",
|
164
|
+
" str += '[:files][:'\n",
|
165
|
+
" str += f.to_s\n",
|
166
|
+
" str += '][:full]' \n",
|
167
|
+
" else\n",
|
168
|
+
" str += '[:full]'\n",
|
169
|
+
" end\n",
|
170
|
+
" return str\n",
|
171
|
+
" end\n",
|
172
|
+
" \n",
|
173
|
+
" def helper_insert_salt( salt, str )\n",
|
174
|
+
" if salt[ 0, 1 ] == ''\n",
|
175
|
+
" \n",
|
176
|
+
" else\n",
|
177
|
+
" if salt[ 0, 1 ] == '-'\n",
|
178
|
+
" else\n",
|
179
|
+
" salt = '-' + salt \n",
|
180
|
+
" end\n",
|
181
|
+
" end\n",
|
182
|
+
"\n",
|
183
|
+
" str = str.gsub( \"{{SALT}}\", salt )\n",
|
184
|
+
" return str\n",
|
185
|
+
" end\n",
|
186
|
+
"\n",
|
187
|
+
" mode = {\n",
|
188
|
+
" :general => nil,\n",
|
189
|
+
" :hash => nil,\n",
|
190
|
+
" :path => nil\n",
|
191
|
+
" }\n",
|
192
|
+
" \n",
|
193
|
+
" case status\n",
|
194
|
+
" when 0\n",
|
195
|
+
" mode[:general] = false\n",
|
196
|
+
" mode[:hash] = false\n",
|
197
|
+
" mode[:path] = false\n",
|
198
|
+
" when 1\n",
|
199
|
+
" mode[:general] = true\n",
|
200
|
+
" mode[:hash] = true\n",
|
201
|
+
" mode[:path] = false\n",
|
202
|
+
" when 2\n",
|
203
|
+
" mode[:general] = true\n",
|
204
|
+
" mode[:hash] = false\n",
|
205
|
+
" mode[:path] = true\n",
|
206
|
+
" when 3\n",
|
207
|
+
" mode[:general] = true\n",
|
208
|
+
" mode[:hash] = true\n",
|
209
|
+
" mode[:path] = true\n",
|
210
|
+
" end\n",
|
211
|
+
" \n",
|
212
|
+
" \n",
|
213
|
+
" mode[:general] ? puts( 'TREE OVERVIEW' ) : ''\n",
|
214
|
+
" \n",
|
215
|
+
" obj[:full] = ''\n",
|
216
|
+
" obj[:full] += obj[:root]\n",
|
217
|
+
" obj[:full] += helper_parse_path( helper_insert_salt( salt, obj[:name] ) )\n",
|
218
|
+
" \n",
|
219
|
+
" mode[:hash] ? puts( helper_obj_path( 'l1', salt, [ ] ) ) : ''\n",
|
220
|
+
" mode[:path] ? puts( draw_obj_path_local( obj[:full], 2, 4 ) ) : ''\n",
|
221
|
+
"\n",
|
222
|
+
" obj[:children].keys.each { | l2 | \n",
|
223
|
+
" obj[:children][ l2 ][:full] = ''\n",
|
224
|
+
" obj[:children][ l2 ][:full] += obj[:full]\n",
|
225
|
+
" obj[:children][ l2 ][:full] += helper_parse_path( helper_insert_salt( salt, obj[:children][ l2 ][:name] ) )\n",
|
226
|
+
" mode[:hash] ? puts( helper_obj_path( 'l2', salt, [ l2 ] ) ) : ''\n",
|
227
|
+
" mode[:path] ? puts( draw_obj_path_local( obj[:children][ l2 ][:full], 3, 4 ) ) : ''\n",
|
228
|
+
" FileUtils.mkdir_p obj[:children][ l2 ][:full]\n",
|
229
|
+
"\n",
|
230
|
+
" if !obj[:children][ l2 ][:files].nil?\n",
|
231
|
+
" obj[:children][ l2 ][:files].keys.each { | f1 | \n",
|
232
|
+
" obj[:children][ l2 ][:files][ f1 ][:full] = '' \n",
|
233
|
+
" obj[:children][ l2 ][:files][ f1 ][:full] += obj[:children][ l2 ][:full] \n",
|
234
|
+
" obj[:children][ l2 ][:files][ f1 ][:full] += helper_insert_salt( salt, obj[:children][ l2 ][:files][ f1 ][:name] )\n",
|
235
|
+
" mode[:hash] ? puts( helper_obj_path( 'l2', salt, [ l2 ], f1 ) ) : ''\n",
|
236
|
+
" mode[:path] ? puts( draw_obj_path_local( obj[:children][ l2 ][:files][ f1 ][:full], 3, 4 ) ) : ''\n",
|
237
|
+
" }\n",
|
238
|
+
" end\n",
|
239
|
+
"\n",
|
240
|
+
" if !obj[:children][ l2 ][:children].nil?\n",
|
241
|
+
" obj[:children][ l2 ][:children].keys.each { | l3 | \n",
|
242
|
+
" obj[:children][ l2 ][:children][ l3 ][:full] = ''\n",
|
243
|
+
" obj[:children][ l2 ][:children][ l3 ][:full] += obj[:children][ l2 ][:full]\n",
|
244
|
+
" obj[:children][ l2 ][:children][ l3 ][:full] += helper_parse_path( helper_insert_salt( salt, obj[:children][ l2 ][:children][ l3 ][:name] ) )\n",
|
245
|
+
"\n",
|
246
|
+
" FileUtils.mkdir_p obj[:children][ l2 ][:children][ l3 ][:full]\n",
|
247
|
+
" mode[:hash] ? puts( helper_obj_path( 'l3', salt, [ l2, l3 ] ) ) : ''\n",
|
248
|
+
" mode[:path] ? puts( draw_obj_path_local( obj[:children][ l2 ][:children][ l3 ][:full], 4, 4 ) ) : ''\n",
|
249
|
+
"\n",
|
250
|
+
" if !obj[:children][ l2 ][:children][ l3 ][:files].nil?\n",
|
251
|
+
" obj[:children][ l2 ][:children][ l3 ][:files].keys.each { | f2 | \n",
|
252
|
+
" obj[:children][ l2 ][:children][ l3 ][:files][ f2 ][:full] = ''\n",
|
253
|
+
" obj[:children][ l2 ][:children][ l3 ][:files][ f2 ][:full] += obj[:children][ l2 ][:children][ l3 ][:full]\n",
|
254
|
+
" obj[:children][ l2 ][:children][ l3 ][:files][ f2 ][:full] += helper_insert_salt( salt, obj[:children][ l2 ][:children][ l3 ][:files][ f2 ][:name] )\n",
|
255
|
+
" mode[:hash] ? puts( helper_obj_path( 'l3', salt, [ l2, l3 ], f2 ) ) : ''\n",
|
256
|
+
" mode[:path] ? puts( draw_obj_path_local( obj[:children][ l2 ][:children][ l3 ][:files][ f2 ][:full], 4, 4 ) ) : ''\n",
|
257
|
+
" }\n",
|
258
|
+
" end\n",
|
259
|
+
" }\n",
|
260
|
+
" end\n",
|
261
|
+
" }\n",
|
262
|
+
" return obj\n",
|
263
|
+
"end"
|
264
|
+
]
|
265
|
+
},
|
266
|
+
{
|
267
|
+
"cell_type": "markdown",
|
268
|
+
"id": "cfe05ab8",
|
269
|
+
"metadata": {},
|
270
|
+
"source": [
|
271
|
+
"## boilerplate_create"
|
272
|
+
]
|
273
|
+
},
|
274
|
+
{
|
275
|
+
"cell_type": "code",
|
276
|
+
"execution_count": 58,
|
277
|
+
"id": "fc56b50e",
|
278
|
+
"metadata": {},
|
279
|
+
"outputs": [
|
280
|
+
{
|
281
|
+
"data": {
|
282
|
+
"text/plain": [
|
283
|
+
":boilerplate_create"
|
284
|
+
]
|
285
|
+
},
|
286
|
+
"execution_count": 58,
|
287
|
+
"metadata": {},
|
288
|
+
"output_type": "execute_result"
|
289
|
+
}
|
290
|
+
],
|
291
|
+
"source": [
|
292
|
+
"def boilerplate_create( obj )\n",
|
293
|
+
" files = {\n",
|
294
|
+
" d3: nil,\n",
|
295
|
+
" statosio: nil,\n",
|
296
|
+
" html: nil,\n",
|
297
|
+
" ruby: nil\n",
|
298
|
+
" }\n",
|
299
|
+
"\n",
|
300
|
+
" files\n",
|
301
|
+
" .keys.each do | key |\n",
|
302
|
+
" p = ''\n",
|
303
|
+
" p += obj[:path][:children][:jupyter][:children][:templates][:full]\n",
|
304
|
+
" p += key.to_s\n",
|
305
|
+
" \n",
|
306
|
+
" k = ''\n",
|
307
|
+
" if key == :html or key == :ruby\n",
|
308
|
+
" k = '.txt'\n",
|
309
|
+
" else\n",
|
310
|
+
" k = '.js'\n",
|
311
|
+
" end\n",
|
312
|
+
"\n",
|
313
|
+
" p += k\n",
|
314
|
+
" files[ key ] = File.read( p )\n",
|
315
|
+
" end\n",
|
316
|
+
" \n",
|
317
|
+
" \n",
|
318
|
+
" item = {}\n",
|
319
|
+
" keys = [ :d3, :statosio ]\n",
|
320
|
+
" keys.each { | key | item[ key ] = { sub: '<--' + key.to_s + '-->', value: nil } }\n",
|
321
|
+
" \n",
|
322
|
+
" values = [ :d3, :statosio ]\n",
|
323
|
+
" values.each { | key | item[ key ][:value] = files[ key ] }\n",
|
324
|
+
" \n",
|
325
|
+
" html = files[:html].clone\n",
|
326
|
+
" item.keys.each { | key | html.gsub!( item[ key ][:sub], item[ key ][:value] ) }\n",
|
327
|
+
" \n",
|
328
|
+
" ruby = File.read( obj[:path][:children][:jupyter][:children][:templates][:files][:ruby][:full] )\n",
|
329
|
+
" ruby.gsub!( \"<<--boilerplate-->>\", html )\n",
|
330
|
+
" \n",
|
331
|
+
" path = obj[:path][:children][:lib][:files][:boilerplate][:full]\n",
|
332
|
+
" File.open( path, \"w\" ) { | f | f.write( ruby ) }\n",
|
333
|
+
" \n",
|
334
|
+
" return true\n",
|
335
|
+
"end"
|
336
|
+
]
|
337
|
+
},
|
338
|
+
{
|
339
|
+
"cell_type": "markdown",
|
340
|
+
"id": "56944408",
|
341
|
+
"metadata": {},
|
342
|
+
"source": [
|
343
|
+
"## example_values"
|
344
|
+
]
|
345
|
+
},
|
346
|
+
{
|
347
|
+
"cell_type": "code",
|
348
|
+
"execution_count": 59,
|
349
|
+
"id": "c59f5550",
|
350
|
+
"metadata": {},
|
351
|
+
"outputs": [
|
352
|
+
{
|
353
|
+
"data": {
|
354
|
+
"text/plain": [
|
355
|
+
":example_values"
|
356
|
+
]
|
357
|
+
},
|
358
|
+
"execution_count": 59,
|
359
|
+
"metadata": {},
|
360
|
+
"output_type": "execute_result"
|
361
|
+
}
|
362
|
+
],
|
363
|
+
"source": [
|
364
|
+
"def example_values( obj )\n",
|
365
|
+
" path = obj[:path][:children][:jupyter][:children][:templates][:files][:dataset][:full]\n",
|
366
|
+
" values = { dataset: nil }\n",
|
367
|
+
"\n",
|
368
|
+
" tmp = JSON.parse( File.read( path ) ).with_indifferent_access\n",
|
369
|
+
" values[:dataset] = tmp[:data]\n",
|
370
|
+
" values[:x] = 'name'\n",
|
371
|
+
" values[:y] = 'mobile'\n",
|
372
|
+
" values[:options] = {}\n",
|
373
|
+
" return values\n",
|
374
|
+
"end"
|
375
|
+
]
|
376
|
+
},
|
377
|
+
{
|
378
|
+
"cell_type": "markdown",
|
379
|
+
"id": "bf68bdeb",
|
380
|
+
"metadata": {},
|
381
|
+
"source": [
|
382
|
+
"## boilerplate_test"
|
383
|
+
]
|
384
|
+
},
|
385
|
+
{
|
386
|
+
"cell_type": "code",
|
387
|
+
"execution_count": 73,
|
388
|
+
"id": "7b218452",
|
389
|
+
"metadata": {},
|
390
|
+
"outputs": [
|
391
|
+
{
|
392
|
+
"data": {
|
393
|
+
"text/plain": [
|
394
|
+
":boilerplate_test"
|
395
|
+
]
|
396
|
+
},
|
397
|
+
"execution_count": 73,
|
398
|
+
"metadata": {},
|
399
|
+
"output_type": "execute_result"
|
400
|
+
}
|
401
|
+
],
|
402
|
+
"source": [
|
403
|
+
"def boilerplate_test( obj, values )\n",
|
404
|
+
" module_path = obj[:path][:children][:lib][:files][:statosio][:full]\n",
|
405
|
+
" require module_path\n",
|
406
|
+
" a = Boilerplate.new\n",
|
407
|
+
" a.set_markers_value( values )\n",
|
408
|
+
" a.set_boilerplate\n",
|
409
|
+
" html = a.get_boilerplate\n",
|
410
|
+
" path = obj[:path][:children][:jupyter][:children][:test][:files][:test][:full]\n",
|
411
|
+
" File.open( path, \"w\" ) { | f | f.write( html ) } \n",
|
412
|
+
" return html\n",
|
413
|
+
"end"
|
414
|
+
]
|
415
|
+
},
|
416
|
+
{
|
417
|
+
"cell_type": "markdown",
|
418
|
+
"id": "18581fe7",
|
419
|
+
"metadata": {},
|
420
|
+
"source": [
|
421
|
+
"## module_test_svg"
|
422
|
+
]
|
423
|
+
},
|
424
|
+
{
|
425
|
+
"cell_type": "code",
|
426
|
+
"execution_count": 61,
|
427
|
+
"id": "721107c8",
|
428
|
+
"metadata": {},
|
429
|
+
"outputs": [
|
430
|
+
{
|
431
|
+
"data": {
|
432
|
+
"text/plain": [
|
433
|
+
":module_test_html"
|
434
|
+
]
|
435
|
+
},
|
436
|
+
"execution_count": 61,
|
437
|
+
"metadata": {},
|
438
|
+
"output_type": "execute_result"
|
439
|
+
}
|
440
|
+
],
|
441
|
+
"source": [
|
442
|
+
"def module_test_html( obj, values )\n",
|
443
|
+
" module_path = obj[:path][:children][:lib][:files][:statosio][:full]\n",
|
444
|
+
" require module_path\n",
|
445
|
+
" a = Statosio::Generate.new\n",
|
446
|
+
" html = a.render_prepare( values )\n",
|
447
|
+
" path = obj[:path][:children][:jupyter][:children][:test][:files][:gem][:full]\n",
|
448
|
+
" File.open( path, \"w\" ) { | f | f.write( html ) } \n",
|
449
|
+
" return true\n",
|
450
|
+
"end"
|
451
|
+
]
|
452
|
+
},
|
453
|
+
{
|
454
|
+
"cell_type": "markdown",
|
455
|
+
"id": "0fdc9aa4",
|
456
|
+
"metadata": {},
|
457
|
+
"source": [
|
458
|
+
"## module_test_svg"
|
459
|
+
]
|
460
|
+
},
|
461
|
+
{
|
462
|
+
"cell_type": "code",
|
463
|
+
"execution_count": 62,
|
464
|
+
"id": "733cbfb3",
|
465
|
+
"metadata": {},
|
466
|
+
"outputs": [
|
467
|
+
{
|
468
|
+
"data": {
|
469
|
+
"text/plain": [
|
470
|
+
":module_test_svg"
|
471
|
+
]
|
472
|
+
},
|
473
|
+
"execution_count": 62,
|
474
|
+
"metadata": {},
|
475
|
+
"output_type": "execute_result"
|
476
|
+
}
|
477
|
+
],
|
478
|
+
"source": [
|
479
|
+
"def module_test_svg( obj, values )\n",
|
480
|
+
" module_path = obj[:path][:children][:lib][:files][:statosio][:full]\n",
|
481
|
+
" require module_path\n",
|
482
|
+
" a = Statosio::Generate.new\n",
|
483
|
+
" svg = a.render_svg( values )\n",
|
484
|
+
" return svg\n",
|
485
|
+
"end"
|
486
|
+
]
|
487
|
+
},
|
488
|
+
{
|
489
|
+
"cell_type": "markdown",
|
490
|
+
"id": "7a7a3b4a",
|
491
|
+
"metadata": {},
|
492
|
+
"source": [
|
493
|
+
"## module_test_generate"
|
494
|
+
]
|
495
|
+
},
|
496
|
+
{
|
497
|
+
"cell_type": "code",
|
498
|
+
"execution_count": 63,
|
499
|
+
"id": "caa69d91",
|
500
|
+
"metadata": {},
|
501
|
+
"outputs": [
|
502
|
+
{
|
503
|
+
"data": {
|
504
|
+
"text/plain": [
|
505
|
+
":module_test_generate"
|
506
|
+
]
|
507
|
+
},
|
508
|
+
"execution_count": 63,
|
509
|
+
"metadata": {},
|
510
|
+
"output_type": "execute_result"
|
511
|
+
}
|
512
|
+
],
|
513
|
+
"source": [
|
514
|
+
"def module_test_generate( obj )\n",
|
515
|
+
" path = obj[:path][:children][:jupyter][:children][:templates][:files][:dataset][:full]\n",
|
516
|
+
" data = JSON.parse( File.read( path ) ).with_indifferent_access\n",
|
517
|
+
" \n",
|
518
|
+
" module_path = obj[:path][:children][:lib][:files][:statosio][:full]\n",
|
519
|
+
" require module_path\n",
|
520
|
+
" a = Statosio::Generate.new\n",
|
521
|
+
" svg = a.svg( dataset: data[:data], x: 'name', y: 'mobile', options: {}, silent: false)\n",
|
522
|
+
" return svg\n",
|
523
|
+
"end"
|
524
|
+
]
|
525
|
+
},
|
526
|
+
{
|
527
|
+
"cell_type": "markdown",
|
528
|
+
"id": "3cb56f16",
|
529
|
+
"metadata": {},
|
530
|
+
"source": [
|
531
|
+
"## module_test_svg_w_prawn"
|
532
|
+
]
|
533
|
+
},
|
534
|
+
{
|
535
|
+
"cell_type": "code",
|
536
|
+
"execution_count": 64,
|
537
|
+
"id": "30d068e3",
|
538
|
+
"metadata": {},
|
539
|
+
"outputs": [
|
540
|
+
{
|
541
|
+
"data": {
|
542
|
+
"text/plain": [
|
543
|
+
":module_test_svg_w_prawn"
|
544
|
+
]
|
545
|
+
},
|
546
|
+
"execution_count": 64,
|
547
|
+
"metadata": {},
|
548
|
+
"output_type": "execute_result"
|
549
|
+
}
|
550
|
+
],
|
551
|
+
"source": [
|
552
|
+
"def module_test_svg_w_prawn( obj, values )\n",
|
553
|
+
" require 'prawn'\n",
|
554
|
+
" require 'prawn-svg'\n",
|
555
|
+
" \n",
|
556
|
+
" module_path = obj[:path][:children][:lib][:files][:statosio][:full]\n",
|
557
|
+
" require module_path\n",
|
558
|
+
" \n",
|
559
|
+
" path = obj[:path][:children][:jupyter][:children][:test][:files][:svg][:full]\n",
|
560
|
+
" Prawn::Document.generate( path ) do | doc |\n",
|
561
|
+
" svg_path = module_test_svg( obj, values )\n",
|
562
|
+
" doc.svg svg_path\n",
|
563
|
+
" end\n",
|
564
|
+
"end"
|
565
|
+
]
|
566
|
+
},
|
567
|
+
{
|
568
|
+
"cell_type": "markdown",
|
569
|
+
"id": "504de5c4",
|
570
|
+
"metadata": {},
|
571
|
+
"source": [
|
572
|
+
"## module_test_generate_w_prawn"
|
573
|
+
]
|
574
|
+
},
|
575
|
+
{
|
576
|
+
"cell_type": "code",
|
577
|
+
"execution_count": 65,
|
578
|
+
"id": "e7922063",
|
579
|
+
"metadata": {},
|
580
|
+
"outputs": [
|
581
|
+
{
|
582
|
+
"data": {
|
583
|
+
"text/plain": [
|
584
|
+
":module_test_generate_w_prawn"
|
585
|
+
]
|
586
|
+
},
|
587
|
+
"execution_count": 65,
|
588
|
+
"metadata": {},
|
589
|
+
"output_type": "execute_result"
|
590
|
+
}
|
591
|
+
],
|
592
|
+
"source": [
|
593
|
+
"def module_test_generate_w_prawn( obj )\n",
|
594
|
+
" require 'prawn'\n",
|
595
|
+
" require 'prawn-svg'\n",
|
596
|
+
" \n",
|
597
|
+
" module_path = obj[:path][:children][:lib][:files][:statosio][:full]\n",
|
598
|
+
" require module_path\n",
|
599
|
+
" \n",
|
600
|
+
" path = obj[:path][:children][:jupyter][:children][:test][:files][:generate][:full]\n",
|
601
|
+
" Prawn::Document.generate( path ) do | doc |\n",
|
602
|
+
" svg_path = module_test_generate( obj )\n",
|
603
|
+
" doc.svg svg_path\n",
|
604
|
+
" end\n",
|
605
|
+
"end"
|
606
|
+
]
|
607
|
+
},
|
608
|
+
{
|
609
|
+
"cell_type": "markdown",
|
610
|
+
"id": "d0829ef3",
|
611
|
+
"metadata": {},
|
612
|
+
"source": [
|
613
|
+
"## values_validation"
|
614
|
+
]
|
615
|
+
},
|
616
|
+
{
|
617
|
+
"cell_type": "code",
|
618
|
+
"execution_count": 66,
|
619
|
+
"id": "1b616b98",
|
620
|
+
"metadata": {},
|
621
|
+
"outputs": [
|
622
|
+
{
|
623
|
+
"data": {
|
624
|
+
"text/plain": [
|
625
|
+
":values_validation"
|
626
|
+
]
|
627
|
+
},
|
628
|
+
"execution_count": 66,
|
629
|
+
"metadata": {},
|
630
|
+
"output_type": "execute_result"
|
631
|
+
}
|
632
|
+
],
|
633
|
+
"source": [
|
634
|
+
"def values_validation( dataset: nil, x: nil, y: nil, options: nil, allow_list: nil, silent: false ) \n",
|
635
|
+
" def check_dataset( dataset, messages, errors )\n",
|
636
|
+
" if !dataset.nil?\n",
|
637
|
+
" if dataset.class.to_s == 'Array'\n",
|
638
|
+
" if dataset[ 0 ].class.to_s == 'Hash' or dataset[ 0 ].class.to_s == 'ActiveSupport::HashWithIndifferentAccess'\n",
|
639
|
+
" if dataset[ 0 ].keys.length > 1\n",
|
640
|
+
" search = dataset[ 0 ].keys\n",
|
641
|
+
" keys = dataset\n",
|
642
|
+
" .map { | a | a.keys }\n",
|
643
|
+
" .flatten\n",
|
644
|
+
" .to_set\n",
|
645
|
+
" .to_a\n",
|
646
|
+
" if keys.eql? search\n",
|
647
|
+
" else\n",
|
648
|
+
" errors.push( messages[:dataset][ 4 ])\n",
|
649
|
+
" end\n",
|
650
|
+
" else\n",
|
651
|
+
" errors.push( messages[:dataset][ 3 ])\n",
|
652
|
+
" end\n",
|
653
|
+
" else\n",
|
654
|
+
" errors.push( messages[:dataset][ 2 ] )\n",
|
655
|
+
" end\n",
|
656
|
+
" else\n",
|
657
|
+
" errors.push( messages[:dataset][ 1 ] )\n",
|
658
|
+
" end\n",
|
659
|
+
" else\n",
|
660
|
+
" errors.push( messages[:dataset][ 0 ] )\n",
|
661
|
+
" end\n",
|
662
|
+
" return errors\n",
|
663
|
+
" end\n",
|
664
|
+
"\n",
|
665
|
+
"\n",
|
666
|
+
" def check_x( x, messages, errors )\n",
|
667
|
+
" if !x.nil?\n",
|
668
|
+
" if x.class.to_s == \"String\"\n",
|
669
|
+
" else\n",
|
670
|
+
" errors.push( messages[:x][ 1 ] )\n",
|
671
|
+
" end\n",
|
672
|
+
" else\n",
|
673
|
+
" errors.push( messages[:x][ 0 ] )\n",
|
674
|
+
" end\n",
|
675
|
+
" return errors\n",
|
676
|
+
" end\n",
|
677
|
+
"\n",
|
678
|
+
"\n",
|
679
|
+
" def check_y( y, messages, errors )\n",
|
680
|
+
" if !y.nil?\n",
|
681
|
+
" if y.class.to_s == 'String' or y.class.to_s == 'Array'\n",
|
682
|
+
" else\n",
|
683
|
+
" errors.push( messages[:y][ 1 ] )\n",
|
684
|
+
" end\n",
|
685
|
+
" else\n",
|
686
|
+
" errors.push( messages[:y][ 0 ] )\n",
|
687
|
+
" end\n",
|
688
|
+
" return errors\n",
|
689
|
+
" end \n",
|
690
|
+
"\n",
|
691
|
+
"\n",
|
692
|
+
" def check_options( options, messages, allow_list, errors )\n",
|
693
|
+
" def str_difference( a, b )\n",
|
694
|
+
" a = a.to_s.downcase.split( '_' ).join( '' )\n",
|
695
|
+
" b = b.to_s.downcase.split( '_' ).join( '' )\n",
|
696
|
+
" longer = [ a.size, b.size ].max\n",
|
697
|
+
" same = a\n",
|
698
|
+
" .each_char\n",
|
699
|
+
" .zip( b.each_char )\n",
|
700
|
+
" .select { | a, b | a == b }\n",
|
701
|
+
" .size\n",
|
702
|
+
" ( longer - same ) / a.size.to_f\n",
|
703
|
+
" end\n",
|
704
|
+
"\n",
|
705
|
+
"\n",
|
706
|
+
" if !options.nil?\n",
|
707
|
+
" if options.class.to_s == 'Hash'\n",
|
708
|
+
" options.keys.each do | key |\n",
|
709
|
+
" if allow_list.include?( key.to_s )\n",
|
710
|
+
" else\n",
|
711
|
+
" tmp = messages[:options][ 2 ][ 0 ]\n",
|
712
|
+
" tmp = tmp.gsub( '<--key-->', key.to_s)\n",
|
713
|
+
"\n",
|
714
|
+
" nearest = allow_list\n",
|
715
|
+
" .map { | word | { score: str_difference( key, word ), word: word } }\n",
|
716
|
+
" .min_by { | item | item[:score] }\n",
|
717
|
+
" tmp = tmp.gsub( '<--similar-->', nearest[:word] )\n",
|
718
|
+
" errors.push( [ tmp, messages[:options][ 2 ][ 1 ] ] )\n",
|
719
|
+
" end\n",
|
720
|
+
" end\n",
|
721
|
+
" else\n",
|
722
|
+
" errors.push( messages[:options][ 1 ] )\n",
|
723
|
+
" end\n",
|
724
|
+
" else\n",
|
725
|
+
" errors.push( messages[:options][ 0 ] )\n",
|
726
|
+
" end\n",
|
727
|
+
"\n",
|
728
|
+
" return errors\n",
|
729
|
+
" end\n",
|
730
|
+
"\n",
|
731
|
+
"\n",
|
732
|
+
" def check_silent( silent, messages, errors )\n",
|
733
|
+
" value = silent.class.to_s\n",
|
734
|
+
" if value == 'FalseClass' or value == 'TrueClass'\n",
|
735
|
+
" else\n",
|
736
|
+
" errors.push( messages[:silent][ 0 ] )\n",
|
737
|
+
" end\n",
|
738
|
+
" return errors\n",
|
739
|
+
" end\n",
|
740
|
+
"\n",
|
741
|
+
"\n",
|
742
|
+
" messages = {\n",
|
743
|
+
" dataset: [\n",
|
744
|
+
" [ \"dataset:\\t is empty. Expect: \\\"Array\\\" [{},{}]\", :d0 ],\n",
|
745
|
+
" [ \"dataset:\\t is not class \\\"Array\\\"\", :d1 ],\n",
|
746
|
+
" [ \"dataset:\\t is not class \\\"Hash\\\"\", :d2 ],\n",
|
747
|
+
" [ \"dataset:\\t \\\"Hash\\\" has less then 2 keys\", :d3 ],\n",
|
748
|
+
" [ \"dataset:\\t have diffrent keys\", :d4 ]\n",
|
749
|
+
" ],\n",
|
750
|
+
" x: [\n",
|
751
|
+
" [ \"x:\\t\\t is empty. Expect: \\\"String\\\"\", :x0 ],\n",
|
752
|
+
" [ \"x:\\t\\t is not Class \\\"String\\\"\", :x1 ]\n",
|
753
|
+
" ],\n",
|
754
|
+
" y: [\n",
|
755
|
+
" [ \"y:\\t\\t is empty. Expect: \\\"String\\\"\", :y0 ],\n",
|
756
|
+
" [ \"y:\\t\\t is not Class \\\"String\\\"\", :y1 ]\n",
|
757
|
+
" ],\n",
|
758
|
+
" options: [\n",
|
759
|
+
" [ \"options:\\t is empty. Expect: \\\"Hash\\\"\", :o0 ],\n",
|
760
|
+
" [ \"options:\\t is not Class \\\"Hash\\\"\", :o1 ],\n",
|
761
|
+
" [ \"options:\\t key: \\\"<--key-->\\\" is not a valid parameter, did you mean: \\\"<--similar-->\\\"? For more Information visit: https://docs.statosio.com/options/<--similar-->\", :o2 ]\n",
|
762
|
+
" ],\n",
|
763
|
+
" silent: [\n",
|
764
|
+
" [ \"silent:\\t is not Class \\\"Hash\\\"\", :s0 ]\n",
|
765
|
+
" ]\n",
|
766
|
+
" }\n",
|
767
|
+
"\n",
|
768
|
+
" errors = []\n",
|
769
|
+
" errors = check_dataset( dataset, messages, errors )\n",
|
770
|
+
" errors = check_y( y, messages, errors )\n",
|
771
|
+
" errors = check_x( x, messages, errors )\n",
|
772
|
+
" errors = check_options( options, messages, allow_list, errors )\n",
|
773
|
+
" errors = check_silent( silent, messages, errors )\n",
|
774
|
+
"\n",
|
775
|
+
" if silent == false\n",
|
776
|
+
" if errors.length != 0\n",
|
777
|
+
" puts errors.length.to_s + ' Errors found: '\n",
|
778
|
+
" errors.each { | error | puts( ' - ' + error[ 0 ] ) }\n",
|
779
|
+
" end\n",
|
780
|
+
" end\n",
|
781
|
+
"\n",
|
782
|
+
" return errors\n",
|
783
|
+
"end"
|
784
|
+
]
|
785
|
+
},
|
786
|
+
{
|
787
|
+
"cell_type": "markdown",
|
788
|
+
"id": "0e06be6e",
|
789
|
+
"metadata": {},
|
790
|
+
"source": [
|
791
|
+
"## values_validation_test"
|
792
|
+
]
|
793
|
+
},
|
794
|
+
{
|
795
|
+
"cell_type": "code",
|
796
|
+
"execution_count": 74,
|
797
|
+
"id": "31131f9c",
|
798
|
+
"metadata": {},
|
799
|
+
"outputs": [
|
800
|
+
{
|
801
|
+
"data": {
|
802
|
+
"text/plain": [
|
803
|
+
":values_validation_test"
|
804
|
+
]
|
805
|
+
},
|
806
|
+
"execution_count": 74,
|
807
|
+
"metadata": {},
|
808
|
+
"output_type": "execute_result"
|
809
|
+
}
|
810
|
+
],
|
811
|
+
"source": [
|
812
|
+
"def values_validation_test( obj, mode, debug )\n",
|
813
|
+
" module_path = obj[:path][:children][:lib][:files][:statosio][:full]\n",
|
814
|
+
" require module_path\n",
|
815
|
+
" a = Statosio::Generate.new\n",
|
816
|
+
" options_allow_list = a.get_options_allow_list\n",
|
817
|
+
" \n",
|
818
|
+
" validations = {\n",
|
819
|
+
" dataset: [\n",
|
820
|
+
" [ nil, :d0 ],\n",
|
821
|
+
" [ '', :d1 ],\n",
|
822
|
+
" [ 23, :d1 ],\n",
|
823
|
+
" [ {}, :d1 ],\n",
|
824
|
+
" [ [], :d2 ],\n",
|
825
|
+
" [ [ {} ], :d3 ],\n",
|
826
|
+
" [ [ { a: '23' } ], :d3 ],\n",
|
827
|
+
" [ [ { a: '23', b: '23' } ], :ok ],\n",
|
828
|
+
" [ [ { a: 23, b: 23 }, { a: 23, b: 23, c: 232 } ], :d4 ],\n",
|
829
|
+
" [ [ { a: 23, b: 23, c: 2323 }, { a: 23, b: 23, c: 232 } ], :ok ]\n",
|
830
|
+
" ],\n",
|
831
|
+
" x: [\n",
|
832
|
+
" [ nil, :x0 ],\n",
|
833
|
+
" [ '', :ok ],\n",
|
834
|
+
" [ 1, :x1 ],\n",
|
835
|
+
" [ [], :x1 ],\n",
|
836
|
+
" [ {}, :x1 ],\n",
|
837
|
+
" ],\n",
|
838
|
+
" y: [\n",
|
839
|
+
" [ nil, :y0 ],\n",
|
840
|
+
" [ 2, :y1 ],\n",
|
841
|
+
" [ '', :ok ],\n",
|
842
|
+
" [ [], :ok ],\n",
|
843
|
+
" [ {}, :y1 ]\n",
|
844
|
+
" ],\n",
|
845
|
+
" options: [\n",
|
846
|
+
" [ nil, :o0 ],\n",
|
847
|
+
" [ '', :o1 ],\n",
|
848
|
+
" [ 2, :o1 ],\n",
|
849
|
+
" [ [], :o1 ],\n",
|
850
|
+
" [ {}, :ok ],\n",
|
851
|
+
" [ { 'showLegend': 'dede' }, :ok ],\n",
|
852
|
+
" [ { show_legend: 'dede' }, :o2 ],\n",
|
853
|
+
" [ { show__legend: 'dede', 'showTitle': false, 'show__Title': false }, :o2 ],\n",
|
854
|
+
" ],\n",
|
855
|
+
" silent: [\n",
|
856
|
+
" [ nil, :s0 ],\n",
|
857
|
+
" [ '', :s0 ],\n",
|
858
|
+
" [ 2, :s0 ],\n",
|
859
|
+
" [ {}, :s0 ],\n",
|
860
|
+
" [ [], :s0 ],\n",
|
861
|
+
" [ true, :ok ]\n",
|
862
|
+
" ]\n",
|
863
|
+
" }\n",
|
864
|
+
"\n",
|
865
|
+
" results = []\n",
|
866
|
+
"\n",
|
867
|
+
" index = 0\n",
|
868
|
+
" validations.keys.each do | type |\n",
|
869
|
+
" if mode == 'detail' or mode == 'user'\n",
|
870
|
+
" puts type.to_s + ':'\n",
|
871
|
+
" end\n",
|
872
|
+
" validations[ type ].each do | test |\n",
|
873
|
+
" case type\n",
|
874
|
+
" when :dataset\n",
|
875
|
+
" codes = values_validation( dataset: test[ 0 ], x: nil, y: nil, options: nil, allow_list: options_allow_list, silent: debug )\n",
|
876
|
+
" when :x\n",
|
877
|
+
" codes = values_validation( dataset: nil, x: test[ 0 ], y: '', options: nil, allow_list: options_allow_list, silent: debug )\n",
|
878
|
+
" when :y\n",
|
879
|
+
" codes = values_validation( dataset: nil, x: nil, y: test[ 0 ], options: nil, allow_list: options_allow_list, silent: debug )\n",
|
880
|
+
" when :options\n",
|
881
|
+
" codes = values_validation( dataset: [ { a: 1, b: 2 } ], x: '', y: [ '' ], options: test[ 0 ], allow_list: options_allow_list, silent: debug )\n",
|
882
|
+
" when :silent\n",
|
883
|
+
" codes = values_validation( dataset: nil, x: nil, y: nil, options: nil, allow_list: options_allow_list, silent: test[ 0 ] )\n",
|
884
|
+
" end\n",
|
885
|
+
"\n",
|
886
|
+
" short = type.to_s[ 0, 1 ]\n",
|
887
|
+
" find = codes.select do | a | \n",
|
888
|
+
" a[ 1 ].to_s[ 0, 1 ] == short ? true : false \n",
|
889
|
+
" end\n",
|
890
|
+
"\n",
|
891
|
+
" if find.length == 0 and test[ 1 ] == :ok\n",
|
892
|
+
" result = true\n",
|
893
|
+
" else\n",
|
894
|
+
" result = find[0].include?( test[ 1 ] )\n",
|
895
|
+
" end\n",
|
896
|
+
" results.push( result )\n",
|
897
|
+
" case mode\n",
|
898
|
+
" when 'detail'\n",
|
899
|
+
" index.to_s.length == 1 ? m = ' ' : m = ''\n",
|
900
|
+
" print ' [' + index.to_s + '] ' + m\n",
|
901
|
+
" if find.length == 0 \n",
|
902
|
+
" print \"Code: \" + find.to_s + \"\\t\"\n",
|
903
|
+
" else\n",
|
904
|
+
" print \"Code: \" + find[ 0 ][ 1 ].to_s + \"\\t\"\n",
|
905
|
+
" end\n",
|
906
|
+
" \n",
|
907
|
+
" print \"Expect: \" + test[ 1 ].to_s + \"\\t\"\n",
|
908
|
+
" print \"Result: \" + result.to_s\n",
|
909
|
+
" puts\n",
|
910
|
+
" index = index + 1\n",
|
911
|
+
" when 'user'\n",
|
912
|
+
" index.to_s.length == 1 ? m = ' ' : m = ''\n",
|
913
|
+
" print ' [' + index.to_s + '] ' + m\n",
|
914
|
+
" # print codes[ 0 ]\n",
|
915
|
+
" puts\n",
|
916
|
+
" index = index + 1\n",
|
917
|
+
" when 'result'\n",
|
918
|
+
" end\n",
|
919
|
+
" end\n",
|
920
|
+
" if mode == 'detail' or mode == 'user'\n",
|
921
|
+
" puts\n",
|
922
|
+
" end\n",
|
923
|
+
" end\n",
|
924
|
+
" \n",
|
925
|
+
" if mode == 'result'\n",
|
926
|
+
" all = results.to_set.to_a == [true]\n",
|
927
|
+
" print 'All tests were passed successfully: '\n",
|
928
|
+
" print all.to_s\n",
|
929
|
+
" end\n",
|
930
|
+
" \n",
|
931
|
+
" return true\n",
|
932
|
+
"end"
|
933
|
+
]
|
934
|
+
},
|
935
|
+
{
|
936
|
+
"cell_type": "markdown",
|
937
|
+
"id": "89066688",
|
938
|
+
"metadata": {},
|
939
|
+
"source": [
|
940
|
+
"# Execute"
|
941
|
+
]
|
942
|
+
},
|
943
|
+
{
|
944
|
+
"cell_type": "code",
|
945
|
+
"execution_count": 75,
|
946
|
+
"id": "7c36bb85",
|
947
|
+
"metadata": {},
|
948
|
+
"outputs": [
|
949
|
+
{
|
950
|
+
"data": {
|
951
|
+
"text/plain": [
|
952
|
+
"false"
|
953
|
+
]
|
954
|
+
},
|
955
|
+
"execution_count": 75,
|
956
|
+
"metadata": {},
|
957
|
+
"output_type": "execute_result"
|
958
|
+
}
|
959
|
+
],
|
960
|
+
"source": [
|
961
|
+
"require 'json'\n",
|
962
|
+
"require 'active_support/core_ext/hash'\n",
|
963
|
+
"require 'puppeteer'\n",
|
964
|
+
"require 'prawn'\n",
|
965
|
+
"require 'prawn-svg'"
|
966
|
+
]
|
967
|
+
},
|
968
|
+
{
|
969
|
+
"cell_type": "code",
|
970
|
+
"execution_count": 76,
|
971
|
+
"id": "9012064d",
|
972
|
+
"metadata": {
|
973
|
+
"scrolled": true
|
974
|
+
},
|
975
|
+
"outputs": [
|
976
|
+
{
|
977
|
+
"name": "stdout",
|
978
|
+
"output_type": "stream",
|
979
|
+
"text": [
|
980
|
+
"TREE OVERVIEW\n",
|
981
|
+
" hash[:path][:full]\n",
|
982
|
+
" ┗━ hash[:path][:children][:jupyter][:full]\n",
|
983
|
+
" ┗━ hash[:path][:children][:jupyter][:children][:templates][:full]\n",
|
984
|
+
" ┗━ hash[:path][:children][:jupyter][:children][:templates][:files][:dataset][:full]\n",
|
985
|
+
" ┗━ hash[:path][:children][:jupyter][:children][:templates][:files][:html][:full]\n",
|
986
|
+
" ┗━ hash[:path][:children][:jupyter][:children][:templates][:files][:ruby][:full]\n",
|
987
|
+
" ┗━ hash[:path][:children][:jupyter][:children][:test][:full]\n",
|
988
|
+
" ┗━ hash[:path][:children][:jupyter][:children][:test][:files][:test][:full]\n",
|
989
|
+
" ┗━ hash[:path][:children][:jupyter][:children][:test][:files][:gem][:full]\n",
|
990
|
+
" ┗━ hash[:path][:children][:jupyter][:children][:test][:files][:svg][:full]\n",
|
991
|
+
" ┗━ hash[:path][:children][:jupyter][:children][:test][:files][:generate][:full]\n",
|
992
|
+
" ┗━ hash[:path][:children][:jupyter][:children][:gem][:full]\n",
|
993
|
+
" ┗━ hash[:path][:children][:jupyter][:children][:gem][:files][:boilerplate][:full]\n",
|
994
|
+
" ┗━ hash[:path][:children][:lib][:full]\n",
|
995
|
+
" ┗━ hash[:path][:children][:lib][:files][:statosio][:full]\n",
|
996
|
+
" ┗━ hash[:path][:children][:lib][:files][:boilerplate][:full]\n",
|
997
|
+
"\n"
|
998
|
+
]
|
999
|
+
}
|
1000
|
+
],
|
1001
|
+
"source": [
|
1002
|
+
"hash = {\n",
|
1003
|
+
" path: {\n",
|
1004
|
+
" root: '.',\n",
|
1005
|
+
" name: '/',\n",
|
1006
|
+
" children: {\n",
|
1007
|
+
" jupyter: {\n",
|
1008
|
+
" name: 'jupyter',\n",
|
1009
|
+
" children: {\n",
|
1010
|
+
" templates: {\n",
|
1011
|
+
" name: '0-templates',\n",
|
1012
|
+
" files: {\n",
|
1013
|
+
" dataset: {\n",
|
1014
|
+
" name: 'dataset.json',\n",
|
1015
|
+
" },\n",
|
1016
|
+
" html: {\n",
|
1017
|
+
" name: 'test.html',\n",
|
1018
|
+
" },\n",
|
1019
|
+
" ruby: {\n",
|
1020
|
+
" name: 'ruby.txt',\n",
|
1021
|
+
" }\n",
|
1022
|
+
" }\n",
|
1023
|
+
" },\n",
|
1024
|
+
" test: {\n",
|
1025
|
+
" name: '1-test',\n",
|
1026
|
+
" files: {\n",
|
1027
|
+
" test: {\n",
|
1028
|
+
" name: 'boilerplate-test.html',\n",
|
1029
|
+
" },\n",
|
1030
|
+
" gem: {\n",
|
1031
|
+
" name: 'module-test-html.html',\n",
|
1032
|
+
" },\n",
|
1033
|
+
" svg: {\n",
|
1034
|
+
" name: 'module-test-generate-svg.pdf',\n",
|
1035
|
+
" },\n",
|
1036
|
+
" generate: {\n",
|
1037
|
+
" name: 'module-test-generate.pdf'\n",
|
1038
|
+
" }\n",
|
1039
|
+
" }\n",
|
1040
|
+
" },\n",
|
1041
|
+
" gem: {\n",
|
1042
|
+
" name: '2-gem',\n",
|
1043
|
+
" files: {\n",
|
1044
|
+
" boilerplate: {\n",
|
1045
|
+
" name: 'boilerplate.rb',\n",
|
1046
|
+
" }\n",
|
1047
|
+
" }\n",
|
1048
|
+
" }\n",
|
1049
|
+
" }\n",
|
1050
|
+
" },\n",
|
1051
|
+
" lib: {\n",
|
1052
|
+
" name: 'lib',\n",
|
1053
|
+
" files: {\n",
|
1054
|
+
" statosio: {\n",
|
1055
|
+
" name: 'statosio.rb'\n",
|
1056
|
+
" },\n",
|
1057
|
+
" boilerplate: {\n",
|
1058
|
+
" name: 'boilerplate.rb'\n",
|
1059
|
+
" }\n",
|
1060
|
+
" }\n",
|
1061
|
+
" }\n",
|
1062
|
+
" }\n",
|
1063
|
+
" }\n",
|
1064
|
+
"}\n",
|
1065
|
+
"\n",
|
1066
|
+
"\n",
|
1067
|
+
"hash[:path] = obj_prepare_path( hash[:path], '', 1 )\n",
|
1068
|
+
"puts"
|
1069
|
+
]
|
1070
|
+
},
|
1071
|
+
{
|
1072
|
+
"cell_type": "markdown",
|
1073
|
+
"id": "55fc8828",
|
1074
|
+
"metadata": {},
|
1075
|
+
"source": [
|
1076
|
+
"## Boilerplate Create"
|
1077
|
+
]
|
1078
|
+
},
|
1079
|
+
{
|
1080
|
+
"cell_type": "code",
|
1081
|
+
"execution_count": 77,
|
1082
|
+
"id": "929e1383",
|
1083
|
+
"metadata": {},
|
1084
|
+
"outputs": [
|
1085
|
+
{
|
1086
|
+
"data": {
|
1087
|
+
"text/plain": [
|
1088
|
+
"true"
|
1089
|
+
]
|
1090
|
+
},
|
1091
|
+
"execution_count": 77,
|
1092
|
+
"metadata": {},
|
1093
|
+
"output_type": "execute_result"
|
1094
|
+
}
|
1095
|
+
],
|
1096
|
+
"source": [
|
1097
|
+
"boilerplate_create( hash )"
|
1098
|
+
]
|
1099
|
+
},
|
1100
|
+
{
|
1101
|
+
"cell_type": "markdown",
|
1102
|
+
"id": "b48e85b7",
|
1103
|
+
"metadata": {},
|
1104
|
+
"source": [
|
1105
|
+
"## Boilerplate Test"
|
1106
|
+
]
|
1107
|
+
},
|
1108
|
+
{
|
1109
|
+
"cell_type": "code",
|
1110
|
+
"execution_count": 78,
|
1111
|
+
"id": "48f709e6",
|
1112
|
+
"metadata": {},
|
1113
|
+
"outputs": [
|
1114
|
+
{
|
1115
|
+
"name": "stdout",
|
1116
|
+
"output_type": "stream",
|
1117
|
+
"text": [
|
1118
|
+
"\n"
|
1119
|
+
]
|
1120
|
+
}
|
1121
|
+
],
|
1122
|
+
"source": [
|
1123
|
+
"values = example_values( hash )\n",
|
1124
|
+
"html = boilerplate_test( hash, values )\n",
|
1125
|
+
"puts"
|
1126
|
+
]
|
1127
|
+
},
|
1128
|
+
{
|
1129
|
+
"cell_type": "markdown",
|
1130
|
+
"id": "bd468eef",
|
1131
|
+
"metadata": {},
|
1132
|
+
"source": [
|
1133
|
+
"## Module Test generate_html"
|
1134
|
+
]
|
1135
|
+
},
|
1136
|
+
{
|
1137
|
+
"cell_type": "code",
|
1138
|
+
"execution_count": 79,
|
1139
|
+
"id": "0b0f1c19",
|
1140
|
+
"metadata": {},
|
1141
|
+
"outputs": [
|
1142
|
+
{
|
1143
|
+
"data": {
|
1144
|
+
"text/plain": [
|
1145
|
+
"true"
|
1146
|
+
]
|
1147
|
+
},
|
1148
|
+
"execution_count": 79,
|
1149
|
+
"metadata": {},
|
1150
|
+
"output_type": "execute_result"
|
1151
|
+
}
|
1152
|
+
],
|
1153
|
+
"source": [
|
1154
|
+
"values = example_values( hash )\n",
|
1155
|
+
"html_path = module_test_html( hash, values )"
|
1156
|
+
]
|
1157
|
+
},
|
1158
|
+
{
|
1159
|
+
"cell_type": "markdown",
|
1160
|
+
"id": "d5fcc8a2",
|
1161
|
+
"metadata": {},
|
1162
|
+
"source": [
|
1163
|
+
"## Module Test generate_svg"
|
1164
|
+
]
|
1165
|
+
},
|
1166
|
+
{
|
1167
|
+
"cell_type": "code",
|
1168
|
+
"execution_count": 80,
|
1169
|
+
"id": "e45bc5e3",
|
1170
|
+
"metadata": {},
|
1171
|
+
"outputs": [
|
1172
|
+
{
|
1173
|
+
"name": "stdout",
|
1174
|
+
"output_type": "stream",
|
1175
|
+
"text": [
|
1176
|
+
"\n"
|
1177
|
+
]
|
1178
|
+
}
|
1179
|
+
],
|
1180
|
+
"source": [
|
1181
|
+
"values = example_values( hash )\n",
|
1182
|
+
"svg_path = module_test_svg( hash, values )\n",
|
1183
|
+
"puts"
|
1184
|
+
]
|
1185
|
+
},
|
1186
|
+
{
|
1187
|
+
"cell_type": "markdown",
|
1188
|
+
"id": "e115e0e5",
|
1189
|
+
"metadata": {},
|
1190
|
+
"source": [
|
1191
|
+
"## Module Test generate_svg w/ prawn"
|
1192
|
+
]
|
1193
|
+
},
|
1194
|
+
{
|
1195
|
+
"cell_type": "code",
|
1196
|
+
"execution_count": 99,
|
1197
|
+
"id": "721a3394",
|
1198
|
+
"metadata": {},
|
1199
|
+
"outputs": [],
|
1200
|
+
"source": [
|
1201
|
+
"values = example_values( hash )\n",
|
1202
|
+
"module_test_svg_w_prawn( hash, values )"
|
1203
|
+
]
|
1204
|
+
},
|
1205
|
+
{
|
1206
|
+
"cell_type": "markdown",
|
1207
|
+
"id": "e987f1a6",
|
1208
|
+
"metadata": {},
|
1209
|
+
"source": [
|
1210
|
+
"## Module Test Validation"
|
1211
|
+
]
|
1212
|
+
},
|
1213
|
+
{
|
1214
|
+
"cell_type": "code",
|
1215
|
+
"execution_count": 100,
|
1216
|
+
"id": "cc8084cf",
|
1217
|
+
"metadata": {},
|
1218
|
+
"outputs": [
|
1219
|
+
{
|
1220
|
+
"name": "stdout",
|
1221
|
+
"output_type": "stream",
|
1222
|
+
"text": [
|
1223
|
+
"All tests were passed successfully: true"
|
1224
|
+
]
|
1225
|
+
},
|
1226
|
+
{
|
1227
|
+
"data": {
|
1228
|
+
"text/plain": [
|
1229
|
+
"true"
|
1230
|
+
]
|
1231
|
+
},
|
1232
|
+
"execution_count": 100,
|
1233
|
+
"metadata": {},
|
1234
|
+
"output_type": "execute_result"
|
1235
|
+
}
|
1236
|
+
],
|
1237
|
+
"source": [
|
1238
|
+
"index = 1\n",
|
1239
|
+
"modes = [ 'detail', 'result' ]\n",
|
1240
|
+
"values_validation_test( hash, modes[ index ], true )"
|
1241
|
+
]
|
1242
|
+
},
|
1243
|
+
{
|
1244
|
+
"cell_type": "markdown",
|
1245
|
+
"id": "313464d3",
|
1246
|
+
"metadata": {},
|
1247
|
+
"source": [
|
1248
|
+
"## Module Test generate w/ prawn"
|
1249
|
+
]
|
1250
|
+
},
|
1251
|
+
{
|
1252
|
+
"cell_type": "code",
|
1253
|
+
"execution_count": 101,
|
1254
|
+
"id": "11158e15",
|
1255
|
+
"metadata": {},
|
1256
|
+
"outputs": [],
|
1257
|
+
"source": [
|
1258
|
+
"module_test_generate_w_prawn( hash )"
|
1259
|
+
]
|
1260
|
+
},
|
1261
|
+
{
|
1262
|
+
"cell_type": "markdown",
|
1263
|
+
"id": "6c4353c9",
|
1264
|
+
"metadata": {},
|
1265
|
+
"source": [
|
1266
|
+
"## Example SVG"
|
1267
|
+
]
|
1268
|
+
},
|
1269
|
+
{
|
1270
|
+
"cell_type": "code",
|
1271
|
+
"execution_count": 109,
|
1272
|
+
"id": "496488dc",
|
1273
|
+
"metadata": {},
|
1274
|
+
"outputs": [
|
1275
|
+
{
|
1276
|
+
"name": "stdout",
|
1277
|
+
"output_type": "stream",
|
1278
|
+
"text": [
|
1279
|
+
"<svg width=\"600\" hei ... \n"
|
1280
|
+
]
|
1281
|
+
}
|
1282
|
+
],
|
1283
|
+
"source": [
|
1284
|
+
"require 'open-uri'\n",
|
1285
|
+
"require 'statosio'\n",
|
1286
|
+
"\n",
|
1287
|
+
"url = 'https://d3.statosio.com/data/performance.json'\n",
|
1288
|
+
"content = URI.open( url ).read\n",
|
1289
|
+
"dataset = JSON.parse( content )\n",
|
1290
|
+
"\n",
|
1291
|
+
"statosio = Statosio::Generate.new\n",
|
1292
|
+
"svg = statosio.svg(\n",
|
1293
|
+
" dataset: dataset,\n",
|
1294
|
+
" x: 'name',\n",
|
1295
|
+
" y: 'mobile',\n",
|
1296
|
+
" options: {}\n",
|
1297
|
+
")\n",
|
1298
|
+
"\n",
|
1299
|
+
"puts svg[0, 20] + ' ... '"
|
1300
|
+
]
|
1301
|
+
},
|
1302
|
+
{
|
1303
|
+
"cell_type": "markdown",
|
1304
|
+
"id": "c87f914b",
|
1305
|
+
"metadata": {},
|
1306
|
+
"source": [
|
1307
|
+
"## Example Prawn"
|
1308
|
+
]
|
1309
|
+
},
|
1310
|
+
{
|
1311
|
+
"cell_type": "code",
|
1312
|
+
"execution_count": null,
|
1313
|
+
"id": "53107b56",
|
1314
|
+
"metadata": {},
|
1315
|
+
"outputs": [
|
1316
|
+
{
|
1317
|
+
"ename": "NoMethodError",
|
1318
|
+
"evalue": "undefined method `+' for nil:NilClass",
|
1319
|
+
"output_type": "error",
|
1320
|
+
"traceback": [
|
1321
|
+
"\u001b[31mNoMethodError\u001b[0m: undefined method `+' for nil:NilClass",
|
1322
|
+
"/Users/andreasbanholzer/PROJEKTE/2021-06-01--statosio-v3/1/statosio/lib/statosio.rb:47:in `block in render_svg'",
|
1323
|
+
"/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/puppeteer-ruby-0.32.3/lib/puppeteer/puppeteer.rb:76:in `launch'",
|
1324
|
+
"/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/puppeteer-ruby-0.32.3/lib/puppeteer.rb:77:in `public_send'",
|
1325
|
+
"/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/puppeteer-ruby-0.32.3/lib/puppeteer.rb:77:in `method_missing'",
|
1326
|
+
"/Users/andreasbanholzer/PROJEKTE/2021-06-01--statosio-v3/1/statosio/lib/statosio.rb:43:in `render_svg'",
|
1327
|
+
"/Users/andreasbanholzer/PROJEKTE/2021-06-01--statosio-v3/1/statosio/lib/statosio.rb:19:in `svg'",
|
1328
|
+
"(eval):16:in `<main>'",
|
1329
|
+
"/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/lib/iruby/backend.rb:44:in `eval'",
|
1330
|
+
"/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/lib/iruby/backend.rb:44:in `eval'",
|
1331
|
+
"/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/lib/iruby/backend.rb:12:in `eval'",
|
1332
|
+
"/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/lib/iruby/kernel.rb:90:in `execute_request'",
|
1333
|
+
"/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/lib/iruby/kernel.rb:49:in `dispatch'",
|
1334
|
+
"/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/lib/iruby/kernel.rb:38:in `run'",
|
1335
|
+
"/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/lib/iruby/command.rb:110:in `run_kernel'",
|
1336
|
+
"/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/lib/iruby/command.rb:40:in `run'",
|
1337
|
+
"/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/bin/iruby:5:in `<top (required)>'",
|
1338
|
+
"/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/bin/iruby:23:in `load'",
|
1339
|
+
"/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/bin/iruby:23:in `<main>'"
|
1340
|
+
]
|
1341
|
+
}
|
1342
|
+
],
|
1343
|
+
"source": [
|
1344
|
+
"require 'open-uri'\n",
|
1345
|
+
"require 'statosio'\n",
|
1346
|
+
"\n",
|
1347
|
+
"require 'prawn'\n",
|
1348
|
+
"require 'prawn-svg'\n",
|
1349
|
+
"\n",
|
1350
|
+
"# Initialize Statosio\n",
|
1351
|
+
"statosio = Statosio::Generate.new\n",
|
1352
|
+
"\n",
|
1353
|
+
"# Load Sample Dataset\n",
|
1354
|
+
"url = 'https://d3.statosio.com/data/performance.json'\n",
|
1355
|
+
"content = URI.open( url ).read\n",
|
1356
|
+
"dataset = JSON.parse( content )\n",
|
1357
|
+
"\n",
|
1358
|
+
"# Generate Statosio\n",
|
1359
|
+
"chart = statosio.svg(\n",
|
1360
|
+
" dataset: dataset,\n",
|
1361
|
+
" x: 'name',\n",
|
1362
|
+
" y: ['mobile'],\n",
|
1363
|
+
" options: {}\n",
|
1364
|
+
")\n",
|
1365
|
+
"\n",
|
1366
|
+
"# Generate .pdf\n",
|
1367
|
+
"Prawn::Document.generate( \"statosio.pdf\" ) do | pdf |\n",
|
1368
|
+
" pdf.svg( chart, width: 500, )\n",
|
1369
|
+
"end"
|
1370
|
+
]
|
1371
|
+
},
|
1372
|
+
{
|
1373
|
+
"cell_type": "code",
|
1374
|
+
"execution_count": null,
|
1375
|
+
"id": "b19e18f6",
|
1376
|
+
"metadata": {},
|
1377
|
+
"outputs": [],
|
1378
|
+
"source": []
|
1379
|
+
}
|
1380
|
+
],
|
1381
|
+
"metadata": {
|
1382
|
+
"kernelspec": {
|
1383
|
+
"display_name": "Ruby 3.0.0",
|
1384
|
+
"language": "ruby",
|
1385
|
+
"name": "ruby"
|
1386
|
+
},
|
1387
|
+
"language_info": {
|
1388
|
+
"file_extension": ".rb",
|
1389
|
+
"mimetype": "application/x-ruby",
|
1390
|
+
"name": "ruby",
|
1391
|
+
"version": "3.0.0"
|
1392
|
+
}
|
1393
|
+
},
|
1394
|
+
"nbformat": 4,
|
1395
|
+
"nbformat_minor": 5
|
1396
|
+
}
|