{ "cells": [ { "cell_type": "markdown", "id": "44709dec", "metadata": {}, "source": [ "# Functions" ] }, { "cell_type": "markdown", "id": "60793629", "metadata": {}, "source": [ "## obj_prepare_path" ] }, { "cell_type": "code", "execution_count": 57, "id": "3bbf3ab7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ ":obj_prepare_path" ] }, "execution_count": 57, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def obj_prepare_path( obj, salt, status )\n", " def helper_parse_path( str )\n", " if str[ str.length - 1, 1 ] != '/'\n", " str = str + '/'\n", " end\n", " return str\n", " end\n", "\n", " def draw_obj_line_edge( l, offset )\n", " str = ''\n", " for i in 1..( ( l - 1 ) * offset )\n", " str += ' '\n", " end\n", " if l > 1\n", " str += \"┗\"\n", " str += \"━\"\n", " str += \" \"\n", " else\n", " str += ' '\n", " end\n", " return str\n", " end\n", " \n", " def draw_obj_path_local( str, l, offset )\n", " result = ''\n", " for i in 0..( ( l - 1 ) * offset )\n", " result += ' '\n", " end\n", " result += ''\n", " result += str\n", " return result\n", " end\n", "\n", " def helper_obj_path( name, salt, k, f=nil )\n", " str = ''\n", " str += draw_obj_line_edge( name[ 1, name.length ].to_i, 4 )\n", " str += 'hash[:path]'\n", " if k.length == 0\n", "\n", " else\n", " for i in 0..k.length-1\n", " str += '[:children]'\n", " str += '[:'\n", " str += k[ i ].to_s\n", " str += ']' \n", " end\n", " end\n", "\n", " if !f.nil?\n", " str += '[:files][:'\n", " str += f.to_s\n", " str += '][:full]' \n", " else\n", " str += '[:full]'\n", " end\n", " return str\n", " end\n", " \n", " def helper_insert_salt( salt, str )\n", " if salt[ 0, 1 ] == ''\n", " \n", " else\n", " if salt[ 0, 1 ] == '-'\n", " else\n", " salt = '-' + salt \n", " end\n", " end\n", "\n", " str = str.gsub( \"{{SALT}}\", salt )\n", " return str\n", " end\n", "\n", " def helper_parse_path( str )\n", " if str[ str.length - 1, 1 ] != '/'\n", " str = str + '/'\n", " end\n", " return str\n", " end\n", "\n", " def draw_obj_line_edge( l, offset )\n", " str = ''\n", " for i in 1..( ( l - 1 ) * offset )\n", " str += ' '\n", " end\n", " if l > 1\n", " str += \"┗\"\n", " str += \"━\"\n", " str += \" \"\n", " else\n", " str += ' '\n", " end\n", " return str\n", " end\n", " \n", " def draw_obj_path_local( str, l, offset )\n", " result = ''\n", " for i in 0..( ( l - 1 ) * offset )\n", " result += ' '\n", " end\n", " result = result[ 1, result.length ]\n", " \n", " if str.index('.') != nil\n", " result += 'File: '\n", " else\n", " result += 'Folder: '\n", " end\n", " result += str\n", " return result\n", " end\n", "\n", " def helper_obj_path( name, salt, k, f=nil )\n", " str = ''\n", " str += draw_obj_line_edge( name[ 1, name.length ].to_i, 4 )\n", " str += ''\n", " str += 'hash[:path]'\n", " if k.length == 0\n", "\n", " else\n", " for i in 0..k.length-1\n", " str += '[:children]'\n", " str += '[:'\n", " str += k[ i ].to_s\n", " str += ']' \n", " end\n", " end\n", "\n", " if !f.nil?\n", " str += '[:files][:'\n", " str += f.to_s\n", " str += '][:full]' \n", " else\n", " str += '[:full]'\n", " end\n", " return str\n", " end\n", " \n", " def helper_insert_salt( salt, str )\n", " if salt[ 0, 1 ] == ''\n", " \n", " else\n", " if salt[ 0, 1 ] == '-'\n", " else\n", " salt = '-' + salt \n", " end\n", " end\n", "\n", " str = str.gsub( \"{{SALT}}\", salt )\n", " return str\n", " end\n", "\n", " mode = {\n", " :general => nil,\n", " :hash => nil,\n", " :path => nil\n", " }\n", " \n", " case status\n", " when 0\n", " mode[:general] = false\n", " mode[:hash] = false\n", " mode[:path] = false\n", " when 1\n", " mode[:general] = true\n", " mode[:hash] = true\n", " mode[:path] = false\n", " when 2\n", " mode[:general] = true\n", " mode[:hash] = false\n", " mode[:path] = true\n", " when 3\n", " mode[:general] = true\n", " mode[:hash] = true\n", " mode[:path] = true\n", " end\n", " \n", " \n", " mode[:general] ? puts( 'TREE OVERVIEW' ) : ''\n", " \n", " obj[:full] = ''\n", " obj[:full] += obj[:root]\n", " obj[:full] += helper_parse_path( helper_insert_salt( salt, obj[:name] ) )\n", " \n", " mode[:hash] ? puts( helper_obj_path( 'l1', salt, [ ] ) ) : ''\n", " mode[:path] ? puts( draw_obj_path_local( obj[:full], 2, 4 ) ) : ''\n", "\n", " obj[:children].keys.each { | l2 | \n", " obj[:children][ l2 ][:full] = ''\n", " obj[:children][ l2 ][:full] += obj[:full]\n", " obj[:children][ l2 ][:full] += helper_parse_path( helper_insert_salt( salt, obj[:children][ l2 ][:name] ) )\n", " mode[:hash] ? puts( helper_obj_path( 'l2', salt, [ l2 ] ) ) : ''\n", " mode[:path] ? puts( draw_obj_path_local( obj[:children][ l2 ][:full], 3, 4 ) ) : ''\n", " FileUtils.mkdir_p obj[:children][ l2 ][:full]\n", "\n", " if !obj[:children][ l2 ][:files].nil?\n", " obj[:children][ l2 ][:files].keys.each { | f1 | \n", " obj[:children][ l2 ][:files][ f1 ][:full] = '' \n", " obj[:children][ l2 ][:files][ f1 ][:full] += obj[:children][ l2 ][:full] \n", " obj[:children][ l2 ][:files][ f1 ][:full] += helper_insert_salt( salt, obj[:children][ l2 ][:files][ f1 ][:name] )\n", " mode[:hash] ? puts( helper_obj_path( 'l2', salt, [ l2 ], f1 ) ) : ''\n", " mode[:path] ? puts( draw_obj_path_local( obj[:children][ l2 ][:files][ f1 ][:full], 3, 4 ) ) : ''\n", " }\n", " end\n", "\n", " if !obj[:children][ l2 ][:children].nil?\n", " obj[:children][ l2 ][:children].keys.each { | l3 | \n", " obj[:children][ l2 ][:children][ l3 ][:full] = ''\n", " obj[:children][ l2 ][:children][ l3 ][:full] += obj[:children][ l2 ][:full]\n", " obj[:children][ l2 ][:children][ l3 ][:full] += helper_parse_path( helper_insert_salt( salt, obj[:children][ l2 ][:children][ l3 ][:name] ) )\n", "\n", " FileUtils.mkdir_p obj[:children][ l2 ][:children][ l3 ][:full]\n", " mode[:hash] ? puts( helper_obj_path( 'l3', salt, [ l2, l3 ] ) ) : ''\n", " mode[:path] ? puts( draw_obj_path_local( obj[:children][ l2 ][:children][ l3 ][:full], 4, 4 ) ) : ''\n", "\n", " if !obj[:children][ l2 ][:children][ l3 ][:files].nil?\n", " obj[:children][ l2 ][:children][ l3 ][:files].keys.each { | f2 | \n", " obj[:children][ l2 ][:children][ l3 ][:files][ f2 ][:full] = ''\n", " obj[:children][ l2 ][:children][ l3 ][:files][ f2 ][:full] += obj[:children][ l2 ][:children][ l3 ][:full]\n", " obj[:children][ l2 ][:children][ l3 ][:files][ f2 ][:full] += helper_insert_salt( salt, obj[:children][ l2 ][:children][ l3 ][:files][ f2 ][:name] )\n", " mode[:hash] ? puts( helper_obj_path( 'l3', salt, [ l2, l3 ], f2 ) ) : ''\n", " mode[:path] ? puts( draw_obj_path_local( obj[:children][ l2 ][:children][ l3 ][:files][ f2 ][:full], 4, 4 ) ) : ''\n", " }\n", " end\n", " }\n", " end\n", " }\n", " return obj\n", "end" ] }, { "cell_type": "markdown", "id": "cfe05ab8", "metadata": {}, "source": [ "## boilerplate_create" ] }, { "cell_type": "code", "execution_count": 58, "id": "fc56b50e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ ":boilerplate_create" ] }, "execution_count": 58, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def boilerplate_create( obj )\n", " files = {\n", " d3: nil,\n", " statosio: nil,\n", " html: nil,\n", " ruby: nil\n", " }\n", "\n", " files\n", " .keys.each do | key |\n", " p = ''\n", " p += obj[:path][:children][:jupyter][:children][:templates][:full]\n", " p += key.to_s\n", " \n", " k = ''\n", " if key == :html or key == :ruby\n", " k = '.txt'\n", " else\n", " k = '.js'\n", " end\n", "\n", " p += k\n", " files[ key ] = File.read( p )\n", " end\n", " \n", " \n", " item = {}\n", " keys = [ :d3, :statosio ]\n", " keys.each { | key | item[ key ] = { sub: '<--' + key.to_s + '-->', value: nil } }\n", " \n", " values = [ :d3, :statosio ]\n", " values.each { | key | item[ key ][:value] = files[ key ] }\n", " \n", " html = files[:html].clone\n", " item.keys.each { | key | html.gsub!( item[ key ][:sub], item[ key ][:value] ) }\n", " \n", " ruby = File.read( obj[:path][:children][:jupyter][:children][:templates][:files][:ruby][:full] )\n", " ruby.gsub!( \"<<--boilerplate-->>\", html )\n", " \n", " path = obj[:path][:children][:lib][:files][:boilerplate][:full]\n", " File.open( path, \"w\" ) { | f | f.write( ruby ) }\n", " \n", " return true\n", "end" ] }, { "cell_type": "markdown", "id": "56944408", "metadata": {}, "source": [ "## example_values" ] }, { "cell_type": "code", "execution_count": 59, "id": "c59f5550", "metadata": {}, "outputs": [ { "data": { "text/plain": [ ":example_values" ] }, "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def example_values( obj )\n", " path = obj[:path][:children][:jupyter][:children][:templates][:files][:dataset][:full]\n", " values = { dataset: nil }\n", "\n", " tmp = JSON.parse( File.read( path ) ).with_indifferent_access\n", " values[:dataset] = tmp[:data]\n", " values[:x] = 'name'\n", " values[:y] = 'mobile'\n", " values[:options] = {}\n", " return values\n", "end" ] }, { "cell_type": "markdown", "id": "bf68bdeb", "metadata": {}, "source": [ "## boilerplate_test" ] }, { "cell_type": "code", "execution_count": 73, "id": "7b218452", "metadata": {}, "outputs": [ { "data": { "text/plain": [ ":boilerplate_test" ] }, "execution_count": 73, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def boilerplate_test( obj, values )\n", " module_path = obj[:path][:children][:lib][:files][:statosio][:full]\n", " require module_path\n", " a = Boilerplate.new\n", " a.set_markers_value( values )\n", " a.set_boilerplate\n", " html = a.get_boilerplate\n", " path = obj[:path][:children][:jupyter][:children][:test][:files][:test][:full]\n", " File.open( path, \"w\" ) { | f | f.write( html ) } \n", " return html\n", "end" ] }, { "cell_type": "markdown", "id": "18581fe7", "metadata": {}, "source": [ "## module_test_svg" ] }, { "cell_type": "code", "execution_count": 61, "id": "721107c8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ ":module_test_html" ] }, "execution_count": 61, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def module_test_html( obj, values )\n", " module_path = obj[:path][:children][:lib][:files][:statosio][:full]\n", " require module_path\n", " a = Statosio::Generate.new\n", " html = a.render_prepare( values )\n", " path = obj[:path][:children][:jupyter][:children][:test][:files][:gem][:full]\n", " File.open( path, \"w\" ) { | f | f.write( html ) } \n", " return true\n", "end" ] }, { "cell_type": "markdown", "id": "0fdc9aa4", "metadata": {}, "source": [ "## module_test_svg" ] }, { "cell_type": "code", "execution_count": 62, "id": "733cbfb3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ ":module_test_svg" ] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def module_test_svg( obj, values )\n", " module_path = obj[:path][:children][:lib][:files][:statosio][:full]\n", " require module_path\n", " a = Statosio::Generate.new\n", " svg = a.render_svg( values )\n", " return svg\n", "end" ] }, { "cell_type": "markdown", "id": "7a7a3b4a", "metadata": {}, "source": [ "## module_test_generate" ] }, { "cell_type": "code", "execution_count": 63, "id": "caa69d91", "metadata": {}, "outputs": [ { "data": { "text/plain": [ ":module_test_generate" ] }, "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def module_test_generate( obj )\n", " path = obj[:path][:children][:jupyter][:children][:templates][:files][:dataset][:full]\n", " data = JSON.parse( File.read( path ) ).with_indifferent_access\n", " \n", " module_path = obj[:path][:children][:lib][:files][:statosio][:full]\n", " require module_path\n", " a = Statosio::Generate.new\n", " svg = a.svg( dataset: data[:data], x: 'name', y: 'mobile', options: {}, silent: false)\n", " return svg\n", "end" ] }, { "cell_type": "markdown", "id": "3cb56f16", "metadata": {}, "source": [ "## module_test_svg_w_prawn" ] }, { "cell_type": "code", "execution_count": 64, "id": "30d068e3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ ":module_test_svg_w_prawn" ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def module_test_svg_w_prawn( obj, values )\n", " require 'prawn'\n", " require 'prawn-svg'\n", " \n", " module_path = obj[:path][:children][:lib][:files][:statosio][:full]\n", " require module_path\n", " \n", " path = obj[:path][:children][:jupyter][:children][:test][:files][:svg][:full]\n", " Prawn::Document.generate( path ) do | doc |\n", " svg_path = module_test_svg( obj, values )\n", " doc.svg svg_path\n", " end\n", "end" ] }, { "cell_type": "markdown", "id": "504de5c4", "metadata": {}, "source": [ "## module_test_generate_w_prawn" ] }, { "cell_type": "code", "execution_count": 65, "id": "e7922063", "metadata": {}, "outputs": [ { "data": { "text/plain": [ ":module_test_generate_w_prawn" ] }, "execution_count": 65, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def module_test_generate_w_prawn( obj )\n", " require 'prawn'\n", " require 'prawn-svg'\n", " \n", " module_path = obj[:path][:children][:lib][:files][:statosio][:full]\n", " require module_path\n", " \n", " path = obj[:path][:children][:jupyter][:children][:test][:files][:generate][:full]\n", " Prawn::Document.generate( path ) do | doc |\n", " svg_path = module_test_generate( obj )\n", " doc.svg svg_path\n", " end\n", "end" ] }, { "cell_type": "markdown", "id": "d0829ef3", "metadata": {}, "source": [ "## values_validation" ] }, { "cell_type": "code", "execution_count": 66, "id": "1b616b98", "metadata": {}, "outputs": [ { "data": { "text/plain": [ ":values_validation" ] }, "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def values_validation( dataset: nil, x: nil, y: nil, options: nil, allow_list: nil, silent: false ) \n", " def check_dataset( dataset, messages, errors )\n", " if !dataset.nil?\n", " if dataset.class.to_s == 'Array'\n", " if dataset[ 0 ].class.to_s == 'Hash' or dataset[ 0 ].class.to_s == 'ActiveSupport::HashWithIndifferentAccess'\n", " if dataset[ 0 ].keys.length > 1\n", " search = dataset[ 0 ].keys\n", " keys = dataset\n", " .map { | a | a.keys }\n", " .flatten\n", " .to_set\n", " .to_a\n", " if keys.eql? search\n", " else\n", " errors.push( messages[:dataset][ 4 ])\n", " end\n", " else\n", " errors.push( messages[:dataset][ 3 ])\n", " end\n", " else\n", " errors.push( messages[:dataset][ 2 ] )\n", " end\n", " else\n", " errors.push( messages[:dataset][ 1 ] )\n", " end\n", " else\n", " errors.push( messages[:dataset][ 0 ] )\n", " end\n", " return errors\n", " end\n", "\n", "\n", " def check_x( x, messages, errors )\n", " if !x.nil?\n", " if x.class.to_s == \"String\"\n", " else\n", " errors.push( messages[:x][ 1 ] )\n", " end\n", " else\n", " errors.push( messages[:x][ 0 ] )\n", " end\n", " return errors\n", " end\n", "\n", "\n", " def check_y( y, messages, errors )\n", " if !y.nil?\n", " if y.class.to_s == 'String' or y.class.to_s == 'Array'\n", " else\n", " errors.push( messages[:y][ 1 ] )\n", " end\n", " else\n", " errors.push( messages[:y][ 0 ] )\n", " end\n", " return errors\n", " end \n", "\n", "\n", " def check_options( options, messages, allow_list, errors )\n", " def str_difference( a, b )\n", " a = a.to_s.downcase.split( '_' ).join( '' )\n", " b = b.to_s.downcase.split( '_' ).join( '' )\n", " longer = [ a.size, b.size ].max\n", " same = a\n", " .each_char\n", " .zip( b.each_char )\n", " .select { | a, b | a == b }\n", " .size\n", " ( longer - same ) / a.size.to_f\n", " end\n", "\n", "\n", " if !options.nil?\n", " if options.class.to_s == 'Hash'\n", " options.keys.each do | key |\n", " if allow_list.include?( key.to_s )\n", " else\n", " tmp = messages[:options][ 2 ][ 0 ]\n", " tmp = tmp.gsub( '<--key-->', key.to_s)\n", "\n", " nearest = allow_list\n", " .map { | word | { score: str_difference( key, word ), word: word } }\n", " .min_by { | item | item[:score] }\n", " tmp = tmp.gsub( '<--similar-->', nearest[:word] )\n", " errors.push( [ tmp, messages[:options][ 2 ][ 1 ] ] )\n", " end\n", " end\n", " else\n", " errors.push( messages[:options][ 1 ] )\n", " end\n", " else\n", " errors.push( messages[:options][ 0 ] )\n", " end\n", "\n", " return errors\n", " end\n", "\n", "\n", " def check_silent( silent, messages, errors )\n", " value = silent.class.to_s\n", " if value == 'FalseClass' or value == 'TrueClass'\n", " else\n", " errors.push( messages[:silent][ 0 ] )\n", " end\n", " return errors\n", " end\n", "\n", "\n", " messages = {\n", " dataset: [\n", " [ \"dataset:\\t is empty. Expect: \\\"Array\\\" [{},{}]\", :d0 ],\n", " [ \"dataset:\\t is not class \\\"Array\\\"\", :d1 ],\n", " [ \"dataset:\\t is not class \\\"Hash\\\"\", :d2 ],\n", " [ \"dataset:\\t \\\"Hash\\\" has less then 2 keys\", :d3 ],\n", " [ \"dataset:\\t have diffrent keys\", :d4 ]\n", " ],\n", " x: [\n", " [ \"x:\\t\\t is empty. Expect: \\\"String\\\"\", :x0 ],\n", " [ \"x:\\t\\t is not Class \\\"String\\\"\", :x1 ]\n", " ],\n", " y: [\n", " [ \"y:\\t\\t is empty. Expect: \\\"String\\\"\", :y0 ],\n", " [ \"y:\\t\\t is not Class \\\"String\\\"\", :y1 ]\n", " ],\n", " options: [\n", " [ \"options:\\t is empty. Expect: \\\"Hash\\\"\", :o0 ],\n", " [ \"options:\\t is not Class \\\"Hash\\\"\", :o1 ],\n", " [ \"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", " ],\n", " silent: [\n", " [ \"silent:\\t is not Class \\\"Hash\\\"\", :s0 ]\n", " ]\n", " }\n", "\n", " errors = []\n", " errors = check_dataset( dataset, messages, errors )\n", " errors = check_y( y, messages, errors )\n", " errors = check_x( x, messages, errors )\n", " errors = check_options( options, messages, allow_list, errors )\n", " errors = check_silent( silent, messages, errors )\n", "\n", " if silent == false\n", " if errors.length != 0\n", " puts errors.length.to_s + ' Errors found: '\n", " errors.each { | error | puts( ' - ' + error[ 0 ] ) }\n", " end\n", " end\n", "\n", " return errors\n", "end" ] }, { "cell_type": "markdown", "id": "0e06be6e", "metadata": {}, "source": [ "## values_validation_test" ] }, { "cell_type": "code", "execution_count": 74, "id": "31131f9c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ ":values_validation_test" ] }, "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def values_validation_test( obj, mode, debug )\n", " module_path = obj[:path][:children][:lib][:files][:statosio][:full]\n", " require module_path\n", " a = Statosio::Generate.new\n", " options_allow_list = a.get_options_allow_list\n", " \n", " validations = {\n", " dataset: [\n", " [ nil, :d0 ],\n", " [ '', :d1 ],\n", " [ 23, :d1 ],\n", " [ {}, :d1 ],\n", " [ [], :d2 ],\n", " [ [ {} ], :d3 ],\n", " [ [ { a: '23' } ], :d3 ],\n", " [ [ { a: '23', b: '23' } ], :ok ],\n", " [ [ { a: 23, b: 23 }, { a: 23, b: 23, c: 232 } ], :d4 ],\n", " [ [ { a: 23, b: 23, c: 2323 }, { a: 23, b: 23, c: 232 } ], :ok ]\n", " ],\n", " x: [\n", " [ nil, :x0 ],\n", " [ '', :ok ],\n", " [ 1, :x1 ],\n", " [ [], :x1 ],\n", " [ {}, :x1 ],\n", " ],\n", " y: [\n", " [ nil, :y0 ],\n", " [ 2, :y1 ],\n", " [ '', :ok ],\n", " [ [], :ok ],\n", " [ {}, :y1 ]\n", " ],\n", " options: [\n", " [ nil, :o0 ],\n", " [ '', :o1 ],\n", " [ 2, :o1 ],\n", " [ [], :o1 ],\n", " [ {}, :ok ],\n", " [ { 'showLegend': 'dede' }, :ok ],\n", " [ { show_legend: 'dede' }, :o2 ],\n", " [ { show__legend: 'dede', 'showTitle': false, 'show__Title': false }, :o2 ],\n", " ],\n", " silent: [\n", " [ nil, :s0 ],\n", " [ '', :s0 ],\n", " [ 2, :s0 ],\n", " [ {}, :s0 ],\n", " [ [], :s0 ],\n", " [ true, :ok ]\n", " ]\n", " }\n", "\n", " results = []\n", "\n", " index = 0\n", " validations.keys.each do | type |\n", " if mode == 'detail' or mode == 'user'\n", " puts type.to_s + ':'\n", " end\n", " validations[ type ].each do | test |\n", " case type\n", " when :dataset\n", " codes = values_validation( dataset: test[ 0 ], x: nil, y: nil, options: nil, allow_list: options_allow_list, silent: debug )\n", " when :x\n", " codes = values_validation( dataset: nil, x: test[ 0 ], y: '', options: nil, allow_list: options_allow_list, silent: debug )\n", " when :y\n", " codes = values_validation( dataset: nil, x: nil, y: test[ 0 ], options: nil, allow_list: options_allow_list, silent: debug )\n", " when :options\n", " codes = values_validation( dataset: [ { a: 1, b: 2 } ], x: '', y: [ '' ], options: test[ 0 ], allow_list: options_allow_list, silent: debug )\n", " when :silent\n", " codes = values_validation( dataset: nil, x: nil, y: nil, options: nil, allow_list: options_allow_list, silent: test[ 0 ] )\n", " end\n", "\n", " short = type.to_s[ 0, 1 ]\n", " find = codes.select do | a | \n", " a[ 1 ].to_s[ 0, 1 ] == short ? true : false \n", " end\n", "\n", " if find.length == 0 and test[ 1 ] == :ok\n", " result = true\n", " else\n", " result = find[0].include?( test[ 1 ] )\n", " end\n", " results.push( result )\n", " case mode\n", " when 'detail'\n", " index.to_s.length == 1 ? m = ' ' : m = ''\n", " print ' [' + index.to_s + '] ' + m\n", " if find.length == 0 \n", " print \"Code: \" + find.to_s + \"\\t\"\n", " else\n", " print \"Code: \" + find[ 0 ][ 1 ].to_s + \"\\t\"\n", " end\n", " \n", " print \"Expect: \" + test[ 1 ].to_s + \"\\t\"\n", " print \"Result: \" + result.to_s\n", " puts\n", " index = index + 1\n", " when 'user'\n", " index.to_s.length == 1 ? m = ' ' : m = ''\n", " print ' [' + index.to_s + '] ' + m\n", " # print codes[ 0 ]\n", " puts\n", " index = index + 1\n", " when 'result'\n", " end\n", " end\n", " if mode == 'detail' or mode == 'user'\n", " puts\n", " end\n", " end\n", " \n", " if mode == 'result'\n", " all = results.to_set.to_a == [true]\n", " print 'All tests were passed successfully: '\n", " print all.to_s\n", " end\n", " \n", " return true\n", "end" ] }, { "cell_type": "markdown", "id": "89066688", "metadata": {}, "source": [ "# Execute" ] }, { "cell_type": "code", "execution_count": 75, "id": "7c36bb85", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "false" ] }, "execution_count": 75, "metadata": {}, "output_type": "execute_result" } ], "source": [ "require 'json'\n", "require 'active_support/core_ext/hash'\n", "require 'puppeteer'\n", "require 'prawn'\n", "require 'prawn-svg'" ] }, { "cell_type": "code", "execution_count": 76, "id": "9012064d", "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "TREE OVERVIEW\n", " hash[:path][:full]\n", " ┗━ hash[:path][:children][:jupyter][:full]\n", " ┗━ hash[:path][:children][:jupyter][:children][:templates][:full]\n", " ┗━ hash[:path][:children][:jupyter][:children][:templates][:files][:dataset][:full]\n", " ┗━ hash[:path][:children][:jupyter][:children][:templates][:files][:html][:full]\n", " ┗━ hash[:path][:children][:jupyter][:children][:templates][:files][:ruby][:full]\n", " ┗━ hash[:path][:children][:jupyter][:children][:test][:full]\n", " ┗━ hash[:path][:children][:jupyter][:children][:test][:files][:test][:full]\n", " ┗━ hash[:path][:children][:jupyter][:children][:test][:files][:gem][:full]\n", " ┗━ hash[:path][:children][:jupyter][:children][:test][:files][:svg][:full]\n", " ┗━ hash[:path][:children][:jupyter][:children][:test][:files][:generate][:full]\n", " ┗━ hash[:path][:children][:jupyter][:children][:gem][:full]\n", " ┗━ hash[:path][:children][:jupyter][:children][:gem][:files][:boilerplate][:full]\n", " ┗━ hash[:path][:children][:lib][:full]\n", " ┗━ hash[:path][:children][:lib][:files][:statosio][:full]\n", " ┗━ hash[:path][:children][:lib][:files][:boilerplate][:full]\n", "\n" ] } ], "source": [ "hash = {\n", " path: {\n", " root: '.',\n", " name: '/',\n", " children: {\n", " jupyter: {\n", " name: 'jupyter',\n", " children: {\n", " templates: {\n", " name: '0-templates',\n", " files: {\n", " dataset: {\n", " name: 'dataset.json',\n", " },\n", " html: {\n", " name: 'test.html',\n", " },\n", " ruby: {\n", " name: 'ruby.txt',\n", " }\n", " }\n", " },\n", " test: {\n", " name: '1-test',\n", " files: {\n", " test: {\n", " name: 'boilerplate-test.html',\n", " },\n", " gem: {\n", " name: 'module-test-html.html',\n", " },\n", " svg: {\n", " name: 'module-test-generate-svg.pdf',\n", " },\n", " generate: {\n", " name: 'module-test-generate.pdf'\n", " }\n", " }\n", " },\n", " gem: {\n", " name: '2-gem',\n", " files: {\n", " boilerplate: {\n", " name: 'boilerplate.rb',\n", " }\n", " }\n", " }\n", " }\n", " },\n", " lib: {\n", " name: 'lib',\n", " files: {\n", " statosio: {\n", " name: 'statosio.rb'\n", " },\n", " boilerplate: {\n", " name: 'boilerplate.rb'\n", " }\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\n", "\n", "hash[:path] = obj_prepare_path( hash[:path], '', 1 )\n", "puts" ] }, { "cell_type": "markdown", "id": "55fc8828", "metadata": {}, "source": [ "## Boilerplate Create" ] }, { "cell_type": "code", "execution_count": 77, "id": "929e1383", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "true" ] }, "execution_count": 77, "metadata": {}, "output_type": "execute_result" } ], "source": [ "boilerplate_create( hash )" ] }, { "cell_type": "markdown", "id": "b48e85b7", "metadata": {}, "source": [ "## Boilerplate Test" ] }, { "cell_type": "code", "execution_count": 78, "id": "48f709e6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "values = example_values( hash )\n", "html = boilerplate_test( hash, values )\n", "puts" ] }, { "cell_type": "markdown", "id": "bd468eef", "metadata": {}, "source": [ "## Module Test generate_html" ] }, { "cell_type": "code", "execution_count": 79, "id": "0b0f1c19", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "true" ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ "values = example_values( hash )\n", "html_path = module_test_html( hash, values )" ] }, { "cell_type": "markdown", "id": "d5fcc8a2", "metadata": {}, "source": [ "## Module Test generate_svg" ] }, { "cell_type": "code", "execution_count": 80, "id": "e45bc5e3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "values = example_values( hash )\n", "svg_path = module_test_svg( hash, values )\n", "puts" ] }, { "cell_type": "markdown", "id": "e115e0e5", "metadata": {}, "source": [ "## Module Test generate_svg w/ prawn" ] }, { "cell_type": "code", "execution_count": 99, "id": "721a3394", "metadata": {}, "outputs": [], "source": [ "values = example_values( hash )\n", "module_test_svg_w_prawn( hash, values )" ] }, { "cell_type": "markdown", "id": "e987f1a6", "metadata": {}, "source": [ "## Module Test Validation" ] }, { "cell_type": "code", "execution_count": 100, "id": "cc8084cf", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "All tests were passed successfully: true" ] }, { "data": { "text/plain": [ "true" ] }, "execution_count": 100, "metadata": {}, "output_type": "execute_result" } ], "source": [ "index = 1\n", "modes = [ 'detail', 'result' ]\n", "values_validation_test( hash, modes[ index ], true )" ] }, { "cell_type": "markdown", "id": "313464d3", "metadata": {}, "source": [ "## Module Test generate w/ prawn" ] }, { "cell_type": "code", "execution_count": 101, "id": "11158e15", "metadata": {}, "outputs": [], "source": [ "module_test_generate_w_prawn( hash )" ] }, { "cell_type": "markdown", "id": "6c4353c9", "metadata": {}, "source": [ "## Example SVG" ] }, { "cell_type": "code", "execution_count": 109, "id": "496488dc", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "'", "/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/lib/iruby/backend.rb:44:in `eval'", "/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/lib/iruby/backend.rb:44:in `eval'", "/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/lib/iruby/backend.rb:12:in `eval'", "/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/lib/iruby/kernel.rb:90:in `execute_request'", "/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/lib/iruby/kernel.rb:49:in `dispatch'", "/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/lib/iruby/kernel.rb:38:in `run'", "/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/lib/iruby/command.rb:110:in `run_kernel'", "/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/lib/iruby/command.rb:40:in `run'", "/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/gems/iruby-0.4.0/bin/iruby:5:in `'", "/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/bin/iruby:23:in `load'", "/Users/andreasbanholzer/.rvm/gems/ruby-3.0.0-latest/bin/iruby:23:in `
'" ] } ], "source": [ "require 'open-uri'\n", "require 'statosio'\n", "\n", "require 'prawn'\n", "require 'prawn-svg'\n", "\n", "# Initialize Statosio\n", "statosio = Statosio::Generate.new\n", "\n", "# Load Sample Dataset\n", "url = 'https://d3.statosio.com/data/performance.json'\n", "content = URI.open( url ).read\n", "dataset = JSON.parse( content )\n", "\n", "# Generate Statosio\n", "chart = statosio.svg(\n", " dataset: dataset,\n", " x: 'name',\n", " y: ['mobile'],\n", " options: {}\n", ")\n", "\n", "# Generate .pdf\n", "Prawn::Document.generate( \"statosio.pdf\" ) do | pdf |\n", " pdf.svg( chart, width: 500, )\n", "end" ] }, { "cell_type": "code", "execution_count": null, "id": "b19e18f6", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Ruby 3.0.0", "language": "ruby", "name": "ruby" }, "language_info": { "file_extension": ".rb", "mimetype": "application/x-ruby", "name": "ruby", "version": "3.0.0" } }, "nbformat": 4, "nbformat_minor": 5 }