All Projects → bergant → Datamodelr

bergant / Datamodelr

Licence: other
Data model diagrams in R

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to Datamodelr

Technicalnote
Repository to store what we have studied. 📖 We want everyone to get a job through TechnicalNote.
Stars: ✭ 206 (-16.94%)
Mutual labels:  data-structures
Program Blog
Practice, thinking and reading
Stars: ✭ 228 (-8.06%)
Mutual labels:  data-structures
Ctci 6th Edition Cn
《Cracking the Coding Interview, 6th Edition》CtCI中文翻译
Stars: ✭ 237 (-4.44%)
Mutual labels:  data-structures
Problem Solving Training
Problem solving training for computer science students.
Stars: ✭ 210 (-15.32%)
Mutual labels:  data-structures
Codejam
Set of handy reusable .NET components that can simplify your daily work and save your time when you copy and paste your favorite helper methods and classes from one project to another
Stars: ✭ 217 (-12.5%)
Mutual labels:  data-structures
Collectable
High-performance immutable data structures for modern JavaScript and TypeScript applications. Functional interfaces, deep/composite operations API, mixed mutability API, TypeScript definitions, ES2015 module exports.
Stars: ✭ 233 (-6.05%)
Mutual labels:  data-structures
Leetcodesolutions
Theoretical solutions for LeetCode problems.
Stars: ✭ 205 (-17.34%)
Mutual labels:  data-structures
Jctools
jctools.github.io/jctools
Stars: ✭ 2,833 (+1042.34%)
Mutual labels:  data-structures
C Algorithms
A library of common data structures and algorithms written in C.
Stars: ✭ 2,654 (+970.16%)
Mutual labels:  data-structures
Staticvec
Implements a fixed-capacity stack-allocated Vec alternative backed by an array, using const generics.
Stars: ✭ 236 (-4.84%)
Mutual labels:  data-structures
Competitive Programming
My competitive programming guide,reading materials, link to system and design interview preparation and my own coding solutions from Codechef, Leetcode,Geeks for Geeks, HackerRank , spoj, codesignal, codebyte, codeblocks and other online judges
Stars: ✭ 206 (-16.94%)
Mutual labels:  data-structures
Static Frame
Immutable and grow-only Pandas-like DataFrames with a more explicit and consistent interface.
Stars: ✭ 217 (-12.5%)
Mutual labels:  data-structures
Libdict
C library of key-value data structures.
Stars: ✭ 234 (-5.65%)
Mutual labels:  data-structures
C Sharp
All algorithms implemented in C#.
Stars: ✭ 3,310 (+1234.68%)
Mutual labels:  data-structures
Rethink C
A reuseable codebase for C Programming Language.
Stars: ✭ 241 (-2.82%)
Mutual labels:  data-structures
Cs50
🎓 Harvard CS50x — 2018 solutions 👨‍🏫
Stars: ✭ 206 (-16.94%)
Mutual labels:  data-structures
Deepgraph
Analyze Data with Pandas-based Networks. Documentation:
Stars: ✭ 232 (-6.45%)
Mutual labels:  data-structures
Rust Algorithms
Common data structures and algorithms in Rust
Stars: ✭ 2,918 (+1076.61%)
Mutual labels:  data-structures
Argo
使用go语言实现数据结构与算法,涵盖字符串、数组、链表、队列、栈、树、图等数据结构。在实现算法的基础上,进行go语言实战。此外也包含经典算法在go实战项目中的应用,以及开源项目算法方面源码分析。
Stars: ✭ 243 (-2.02%)
Mutual labels:  data-structures
Computer Science In Javascript
Computer science reimplemented in JavaScript
Stars: ✭ 2,590 (+944.35%)
Mutual labels:  data-structures

This project is no longer actively maintained. Please take a look at dm package.

datamodelr

Define and display data model diagrams:

Use shiny to implement interactive model definition and rendering.

Installation

devtools::install_github("bergant/datamodelr")

Usage

Model Definition in YAML

Define a data model in YAML:

# data model segments

- segment: &md Master data
- segment: &tran Transactions

# Tables and columns

- table: Person
  segment: *md
  columns:
    Person ID: {key: yes}
    Name:
    E-mail:
    Street:
    Street number:
    City:
    ZIP:

- table: Order
  segment: *tran
  columns:
    Order ID: {key: yes}
    Customer: {ref: Person}
    Sales person: {ref: Person}
    Order date:
    Requested ship date:
    Status:

- table: Order Line
  segment: *tran
  columns:
    Order ID: {key: yes, ref: Order}
    Line number: {key: yes}
    Order item: {ref: Item}
    Quantity:
    Price:

- table: Item
  segment: *md
  display: accent1
  columns:
    Item ID: {key: yes}
    Item Name:
    Description:
    Category:
    Size:
    Color:

Create a data model object with dm_read_yaml:

library(datamodelr)
file_path <- system.file("samples/example.yml", package = "datamodelr")
dm <- dm_read_yaml(file_path)

Create a graph object to plot the model:

graph <- dm_create_graph(dm, rankdir = "BT")
dm_render_graph(graph)

Model Diagram of Interconnected Data Frames

Attach flights database (nycflights13 package) and create a data model from data frames:

library("nycflights13")
dm_f <- dm_from_data_frames(flights, airlines, weather, airports, planes)

Create plot:

graph <- dm_create_graph(dm_f, rankdir = "BT", col_attr = c("column", "type"))
dm_render_graph(graph)

Add references and primary keys:

dm_f <- dm_add_references(
  dm_f,
  
  flights$carrier == airlines$carrier,
  flights$origin == airports$faa,
  flights$dest == airports$faa,
  flights$tailnum == planes$tailnum,
  weather$origin == airports$faa
)
graph <- dm_create_graph(dm_f, rankdir = "BT", col_attr = c("column", "type"))
dm_render_graph(graph)

Reverse-engineer SQL Server Database

This example uses Northwind sample database and RODBC package as an interface to SQL Server.

library(RODBC)
con <- odbcConnect(dsn = "NW")
sQuery <- dm_re_query("sqlserver")
dm_northwind <- sqlQuery(con, sQuery, stringsAsFactors = FALSE, errors=TRUE)
odbcClose(con)

# convert to a data model
dm_northwind <- as.data_model(dm_northwind)

Plot the result:

graph <- dm_create_graph(dm_northwind, rankdir = "BT")
dm_render_graph(graph)

Reverse-engineer PostgreSQL Database

This example uses DVD Rental sample database and RPostgreSQL package as an interface to PostgreSQL database.

library(RPostgreSQL)
#> Loading required package: DBI
con <- dbConnect(dbDriver("PostgreSQL"), dbname="dvdrental", user ="postgres")
sQuery <- dm_re_query("postgres")
dm_dvdrental <- dbGetQuery(con, sQuery) 
dbDisconnect(con)
#> [1] TRUE

dm_dvdrental <- as.data_model(dm_dvdrental)

Show model:

graph <- dm_create_graph(dm_dvdrental, rankdir = "RL")
dm_render_graph(graph)

Focused Data Model Diagram

To focus in on a few tables from your model use focus attribute in dm_create_graph function:

focus <- list(tables = c(
    "customer",
    "payment", 
    "rental",
    "inventory",
    "film"
))
    
graph <- dm_create_graph( dm_dvdrental, rankdir = "RL", focus = focus)
dm_render_graph(graph)

Hide columns

To emphasize table relations and hide the "non-key"" columns use view_type = "keys_only":

graph <- dm_create_graph(dm_dvdrental, view_type = "keys_only", rankdir = "RL")
dm_render_graph(graph)

Diagram Segments

Arrange tables in clusters with dm_set_segment function:

table_segments <- list(
  Transactions = c("rental", "inventory", "payment"),
  Party = c("customer", "staff", "address", "city", "country", "store"),
  Film = c("film", "film_actor", "actor", "language", "film_category", "category") )

dm_dvdrental_seg <- dm_set_segment(dm_dvdrental, table_segments)

Render diagram with segments:

graph <- dm_create_graph(dm_dvdrental_seg, rankdir = "RL", view_type = "keys_only")
dm_render_graph(graph)

Graph Direction

Use rankdir to change the direction of graph:

graph <- dm_create_graph(dm_dvdrental_seg, rankdir = "BT", view_type = "keys_only")
dm_render_graph(graph)

Colors

To emphasise tables with colors use dm_set_display function:

display <- list(
  accent1 = c("rental", "payment"),
  accent2 = c("customer"),
  accent3 = c("staff", "store"),
  accent4 = c("film", "actor") )

dm_dvdrental_col <- dm_set_display(dm_dvdrental_seg, display)
graph <- dm_create_graph(dm_dvdrental_col, rankdir = "BT", view_type = "keys_only")
dm_render_graph(graph)

Default color scheme includes:

Custom Colors

Add your colors with dm_add_colors function:

my_colors <-
  dm_color_scheme(
    purple = dm_palette(
      line_color = "#8064A2",
      header_bgcolor = "#B1A0C7",
      header_font = "#FFFFFF",
      bgcolor = "#E4DFEC"
    ),
    red = dm_palette(
      line_color = "#C0504D",
      header_bgcolor = "#DA9694",
      header_font = "#FFFFFF",
      bgcolor = "#F2DCDB"
    )
)

dm_add_colors(my_colors)

dm <- dm_set_display(dm, display = list(
  red = c("Order", "Order Line"),
  purple = "Item"
))

graph <- dm_create_graph(dm, rankdir = "RL")
dm_render_graph(graph)

Graphviz Attributes

To change general graph, node or edge graphviz attributes use graph_attrs, edge_attrs and node_attrs arguments when creating graph. This example changes graph background, arrow style (edge attribute) and font (node attribute):

graph <- dm_create_graph( 
  dm, 
  graph_attrs = "rankdir = RL, bgcolor = '#F4F0EF' ", 
  edge_attrs = "dir = both, arrowtail = crow, arrowhead = odiamond",
  node_attrs = "fontname = 'Arial'")
                          
dm_render_graph(graph)

Additional Column Attributes

To include additional column attributes set col_attr when creating graph:

focus <- list(tables = c(
    "customer",
    "rental",
    "inventory",
    "film"
))
    
graph <- dm_create_graph( dm_dvdrental, rankdir = "RL", focus = focus,
                          col_attr = c("column", "type"))
dm_render_graph(graph)

Shiny Application

Try datamodelr Shiny application:

shiny::runApp(system.file("shiny", package = "datamodelr"))

Utilised Packages

datamodelr depends on:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].