DEV Community

Cover image for ArcadeDB, Ruby && Jupyter
Hartmut B.
Hartmut B.

Posted on

ArcadeDB, Ruby && Jupyter

Jupyter Notebooks are widely used in data science, scientific computing, and machine learning due to their interactive nature and ability to present code, results, and explanations in a clear and organized manner. The IRuby Project introduces a modern ruby kernel to jupyter and opens the environment for ruby projects.

The ArcadeDB Ruby Interface naively supports iruby jupyter notebooks.

To activate include both gems in the Gemfile

## Gemfile
gem 'arcadedb'
gem 'iruby'
Enter fullscreen mode Exit fullscreen mode

Jupyter-output is realized through IRuby.display, IRuby.html and IRuby.table-commands in the to_html-method of the class to be supported. ArcadeDB-database objects inherit this to_html-implementation

def to_html  # iruby
  the_rid = "[#{rid}] : {#{self.in.count}->}{->#{self.out.count }}"
  IRuby.display IRuby.html "<b>#{self.class}</b>#{the_rid} < #{html_attributes.map{|_,v|  v }.join(', ')} >"
end
Enter fullscreen mode Exit fullscreen mode

which leads to the following output

  • Member.find name: ‘Gross’
    Member[#49:43] : {0->}{->0} < Frau, Maria, Gross, Lüneburg, Hauptstr. 12a >

Customization

The default output is defined by

def html_attributes  # Standard
  invariant_attributes
end
Enter fullscreen mode Exit fullscreen mode

It includes all properties except created_at and modified_at. Customization is straightforward:

def html_attributes  # model/arcade/member.rb
 {     Sex: :sex,
   Vorname: :surname,
      Name: :name,
       Ort: :town,
    Straße: :street } 
end
Enter fullscreen mode Exit fullscreen mode

This affects the output of tables, too.
Member.where returns an array and triggers the expected jupyter-output:

  • Member.where name: ‘Gross’


    Sex Vorname Name Ort Straße
    Frau Maria Gross Lüneburg Hauptstr. 12a

Advanced Visualization && Calculations

The ecosystem of applications supporting jupyter notebooks is slowly growing. Visualizations of any kind are realized with the excellent vega gem. Jupyter notebooks are supported.

ArcadeDB database contents are easily exported to polars dataframes.

A typical workflow would be to use

  • arcadedb to store and easily retrieve the data,
  • export them to polars dataframes, perform extensive calculations and use
  • vega for visualization.

The ruby script runs in a python environment, uses a java-based database for storage, a rust-powered Dataframe-Engine for calculations and a javascript library to present the results.


To experiment with this environment in jupyter, the Github respiratory from the Ruby Adventures with ArcadeDB Series contains an iruby directory.
Clone it, install Jupyter and ìruby, go to theiruby-directory and enterjuypter notebook` to start Jupyter in the standard browser. Enjoy!

Top comments (0)