Skip to content

Commit

Permalink
Merge pull request #16 from dsten/split-stuff
Browse files Browse the repository at this point in the history
Restructure package, datascience.py -> table.py, and stub map widget
  • Loading branch information
papajohn committed Jul 21, 2015
2 parents 30e8c93 + 63c75a4 commit 0a95626
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 6 deletions.
2 changes: 2 additions & 0 deletions datascience/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .table import *
from .maps import *
4 changes: 4 additions & 0 deletions datascience/maps/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .loader import *
from .maps import *

init_js()
13 changes: 13 additions & 0 deletions datascience/maps/js/maps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Registers the Backbone view for the Polymap widget, although for now this is
// a dummy view until we can get everything hooked up properly.
// TODO(sam): Make this actually do things.

require(["widgets/js/widget", "widgets/js/manager"], function(widget, manager) {
var TestWidgetView = widget.DOMWidgetView.extend({
render: function() {
this.$el.text("Hello world!");
}
});

manager.WidgetManager.register_widget_view('TestWidgetView', TestWidgetView);
});
13 changes: 13 additions & 0 deletions datascience/maps/loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from IPython.display import display_javascript

__maps_js_has_initialized__ = False

# Uses a hack to load the Javascript needed to render the map. Becaose of this,
# calls to draw_map cannot be in the same cell as the import statement.
#
# Maybe it's a good idea to put this login in a line magic?
def init_js():
global __maps_js_has_initialized__
if not __maps_js_has_initialized__:
# Keep in sync with the the data_files variable in setup.py
display_javascript("IPython.load_extensions('datascience_js/maps')")
34 changes: 34 additions & 0 deletions datascience/maps/maps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from IPython.html import widgets # Widget definitions
from IPython.utils.traitlets import Unicode

"""
This file contains the Python backend to draw maps with overlaid polygons.
TODO(sam): Actually make this draw maps
"""

class TestWidget(widgets.DOMWidget):
_view_name = Unicode('TestWidgetView', sync=True)
_view_module = Unicode('maps', sync=True)


def draw_map(center, zoom, points=[], regions=[]):
"""Draw a map with center & zoom containing all points and
regions that displays points as circles and regions as polygons.
center -- lat-long pair at the center of the map
zoom -- zoom level
points -- a sequence of MapPoints
regions -- a sequence of MapRegions
"""
# Some magic to get javascript to display the map

class MapPoint:
"""A circle https://developers.google.com/maps/documentation/javascript/shapes#circles"""
def __init__(self, center, radius, strokeColor, strokeOpacity, strokeWeight, fillColor, fillOpacity):
pass

class MapRegion:
"""A polygon https://developers.google.com/maps/documentation/javascript/shapes#polygons"""
def __init__(self, paths, strokeColor, strokeOpacity, strokeWeight, fillColor, fillOpacity):
"""paths -- a list of lat-long pairs or a list of list of lat-long pairs"""
pass
1 change: 0 additions & 1 deletion datascience.py → datascience/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,6 @@ def __len__(self):
def __repr__(self):
return '{0}({1})'.format(type(self).__name__, repr(self._table))


def _zero_on_type_error(column_fn):
"""Wrap a function on an np.ndarray to return 0 on a type error."""
@functools.wraps(column_fn)
Expand Down
20 changes: 15 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import sys
from distutils.core import setup
import os
import IPython
from setuptools import setup
from setuptools.command.test import test as TestCommand

install_requires = [
Expand Down Expand Up @@ -31,15 +33,23 @@ def run_tests(self):
sys.exit(errno)


# Installs GMaps Javascript in the nbextensions folder for loading.
# We load this file using IPython.load_extensions('datascience_js/maps') in
# Javascript. Keep in sync with the path in maps/leader.py
ipython_dir = IPython.utils.path.get_ipython_dir()
data_files = [(os.path.join(ipython_dir, "nbextensions/datascience_js"),
["datascience/maps/js/maps.js"] )]

setup(
name = 'datascience',
py_modules = ['datascience'],
version = '0.2.1',
packages = ['datascience'],
version = '0.2.2',
install_requires = install_requires,
tests_require = test_requires,
data_files = data_files,
cmdclass = {'test': PyTest},
description = 'A Python library for introductory data science',
author = 'John DeNero, David Culler, Alvin Wan',
description = 'A Jupyter notebook Python library for introductory data science',
author = 'John DeNero, David Culler, Alvin Wan, Sam Lau',
author_email = 'ds-instr@berkeley.edu',
url = 'https://github.com/dsten/datascience',
download_url = 'https://github.com/dsten/datascience/archive/0.2.0.zip',
Expand Down

0 comments on commit 0a95626

Please sign in to comment.