Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View schaunwheeler's full-sized avatar

Schaun Wheeler schaunwheeler

View GitHub Profile
@schaunwheeler
schaunwheeler / ds_prod_portability2.py
Created March 6, 2019 21:11
Data science productionization: portability - example 2
STOPCHARS = ['a', 'b', 'c', 'd']
def normalize_word(word, stops=None):
word = word.strip().lower()
if stops:
word = ''.join([char for char in word if char not in stops])
return word
@schaunwheeler
schaunwheeler / ds_prod_portability1.py
Created March 6, 2019 21:08
Data science productionization: portability - example 1
stopchars = ['a', 'b', 'c', 'd']
word = 'abracadabra'
word = word.strip().lower()
word = ''.join([char for char in word if char not in stops])
word
"""
Code described in Medium post https://medium.com/@schaun.wheeler/codify-your-workflow-377f5f8bf4c3
Copyright (c) 2018 Valassis Digital under the terms of the BSD 3-Clause license.
"""
def add_source(self, data, label, column_name=None, **kwargs):
# process data into x and y coordinates
if type(data) == DataFrame:
"""
Code described in Medium post https://medium.com/@schaun.wheeler/codify-your-workflow-377f5f8bf4c3
Copyright (c) 2018 Valassis Digital under the terms of the BSD 3-Clause license.
"""
def add_layer(self, source_label, bokeh_model, tooltips=None, **kwargs):
if self.plot is None:
raise AssertionError('self.plot is null; call `self.prepare_plot`.')
"""
Code described in Medium post https://medium.com/@schaun.wheeler/codify-your-workflow-377f5f8bf4c3
Copyright (c) 2018 Valassis Digital under the terms of the BSD 3-Clause license.
"""
def prepare_plot(self, plot_width=700, plot_height=None, zoom=None, map_type='hybrid', **kwargs):
zoom_level, lat_center, lng_center, auto_plot_height = self._estimate_zoom_level(plot_width)
if plot_height is None:
plot_height = auto_plot_height
@schaunwheeler
schaunwheeler / geoPlotter.py
Last active May 8, 2018 17:13
Example of workflow automation using Bokeh. Copyright (c) 2018 Valassis Digital under the terms of the BSD 3-Clause license.
"""
Code described in Medium post https://medium.com/@schaun.wheeler/codify-your-workflow-377f5f8bf4c3
Copyright (c) 2018 Valassis Digital under the terms of the BSD 3-Clause license.
"""
from math import sin, pi, log, floor
from shapely.wkt import loads, dumps
from shapely.geometry import Polygon, Point, MultiPolygon, LineString, MultiLineString, MultiPoint, GeometryCollection
from bokeh.io import output_notebook, show, output_file, reset_output, save
DROP FUNCTION IF EXISTS pivotcode(varchar, varchar, varchar, varchar, varchar, varchar);
create or replace function pivotcode (tablename varchar, resultname varchar, rowc varchar, colc varchar, cellc varchar, celldatatype varchar)
returns VOID language plpgsql as $$
declare
dynsql1 varchar;
dynsql2 varchar;
columnlist varchar;
begin
-- 1. retrieve list of column names.
dynsql1 = 'select string_agg(distinct ''"''||'||colc||'||''" '||celldatatype||''','','' order by ''"''||'||colc||'||''" '||celldatatype||''') from '||tablename||';';
from pandas import DataFrame
from bokeh.models.axes import CategoricalAxis
from bokeh.models import Plot, ColumnDataSource
from bokeh.models.ranges import FactorRange, Range1d
from bokeh.models.glyphs import Circle
from bokeh.models.widgets.markups import PreText
from bokeh.layouts import Column
from bokeh.models.widgets.inputs import Select
from bokeh.plotting import curdoc
from bokeh.models.callbacks import CustomJS
@schaunwheeler
schaunwheeler / bokeh_resize_test.py
Created September 21, 2016 18:59
Reproduces problem with adjusting plot size
from pandas import DataFrame
from bokeh.models.axes import CategoricalAxis
from bokeh.models import Plot, ColumnDataSource
from bokeh.models.ranges import FactorRange
from bokeh.models.glyphs import Circle
from bokeh.models.widgets.markups import PreText
from bokeh.layouts import Column
from bokeh.models.widgets.inputs import Select
from bokeh.plotting import curdoc
@schaunwheeler
schaunwheeler / app_reload.py
Created April 28, 2015 18:53
Trying to figure out why app reloads
from bokeh.properties import Instance, Bool, String
from bokeh.models.widgets.buttons import Button, Toggle
from bokeh.models.widgets.markups import Paragraph
from bokeh.models.widgets.layouts import VBox, HBox, VBoxForm
from bokeh.models.widgets.inputs import Select
from bokeh.server.app import bokeh_app
from bokeh.server.utils.plugins import object_page
from bokeh.plotting import curdoc