lkmltools.grapher package

Submodules

lkmltools.grapher.graph_animator module

class lkmltools.grapher.graph_animator.GraphAnimator(config)

Bases: object

create_gif(path_to_repo, branch, directory, gif_filename)

create an animated GIF given path to a repo

Parameters
  • path_to_repo (str) – path to the git repo

  • branch (str) – the brnch name, e.g. ‘master’

  • directory (str) – directory to save the image files to

  • gif_filename (str) – filepath of final GIF file

Returns

nothing. Side effect is to save a GIF file at gif_filename

generate_gif(filenames, gif_filename)

create an animated GIF given a list of images

Parameters
  • filenames (list) – list of image filenames, ordered in required sequence

  • gif_filename (str) – filepath of final GIF file

Returns

nothing. Side effect is to save a GIF file at gif_filename

generate_images(repo, commits, directory)

given a set of commits, run the LookML grapher to produce one image per commit

Parameters
  • commits (list) – list of commits in going forward in time (oldest -> newest)

  • directory (str) – directory to save the image files to

Returns

nothing. Side effect is to create a set of images in a directory

get_commits(path_to_repo, branch='master')

get the list of commits from a repo

Parameters
  • path_to_repo (str) – path to the git repo

  • branch (str) – the brnch name, e.g. ‘master’

Returns

git Repo commits (list): list of commits in going forward in time (oldest -> newest)

Return type

repo (Repo)

lkmltools.grapher.lookml_grapher module

grapher: creates an image showing the relationship among the models, explores and views

Authors:

Carl Anderson (carl.anderson@weightwatchers.com)

class lkmltools.grapher.lookml_grapher.LookMlGrapher(config)

Bases: object

A LookML Grapher that parses a set of LookML files specified in some config and creates an image showing the relationship among the models, explores and views

create_graph()

add nodes and edges to a graph

Returns

instance of networkx graph

extract_graph_info(globstrings)

given a list of fileglobs, process them to extract list of nodes and edges, and orphaned views

Parameters

globstrings (list) – list of globstrings

Returns

nothing but side effect is that nodes are strored in self.node_map and self.models_to_explores and self.explores_to_views are completed

orphans()

retrieve the set or orphaned views (if any) from the set of files

Prerequisites:

tag_orphans() has been called

Returns

set of view names (if any)

plot_graph(g, filename, title, node_size=500, label_font_size=12, text_angle=0, image_width=16, image_height=12)

plot the graph and write to file

Parameters
  • g (networkx) – networkx graph object

  • filename (str) – path to write image to

  • title (str) – title to add to chart

  • node_size (int) – node size

  • label_font_size (int) – font size

  • text_angle (int) – angle to rotate. This is angle in degrees counter clockwise from east

  • image_width (int) – width of image in inches

  • image_height (int) – heightof image in inches

Returns

nothing but does write image to file

process_explores(m, e)

extract the views referenced by these explores and add them to node map and add explore–>view or model–>explores

Parameters
  • m (str) – model

  • e (str) – explore

Returns

nothing. Side effect is to add to maps

process_lookml(lookml)

given a filepath to a LookML file, extract the views, models, explores as the nodes as well as any model–>explore and explore–>view edges

Parameters
  • filepath (str) – path to LookML file

  • json_data (JSON) – chunk of JSONified LookML code

Returns

nothing but stores node names and their types as well as edges

run()

process the set of files and create an image of the graph

Returns

nothing. Saves an image file, specified in the config

tag_orphans()

find any orphaned views and tag them as orphan node type

Returns

nothing but side effect is that any orphans are tagged in the node map

class lkmltools.grapher.lookml_grapher.NodeType

Bases: enum.Enum

types of node

EXPLORE = 'explore'
MODEL = 'model'
ORPHAN = 'orphan'
VIEW = 'view'

Module contents