Skip to content

Commit

Permalink
Dynamic time granularity on any datetime column
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Mar 16, 2016
1 parent 2aa0e0d commit 27fb810
Show file tree
Hide file tree
Showing 24 changed files with 346 additions and 296 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.pyc
babel
.DS_Store
.coverage
_build
Expand Down
3 changes: 0 additions & 3 deletions babel/babel.cfg

This file was deleted.

1 change: 0 additions & 1 deletion babel/messages.pot

This file was deleted.

2 changes: 1 addition & 1 deletion panoramix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ def index(self):
sm = appbuilder.sm

get_session = appbuilder.get_session
from panoramix import config, views
from panoramix import config, views # noqa
4 changes: 3 additions & 1 deletion panoramix/assets/javascripts/featured.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
var $ = window.$ = require('jquery');
var jQuery = window.jQuery = $;
var px = require('./modules/panoramix.js');

require('bootstrap');
require('datatables');
require('../node_modules/datatables-bootstrap3-plugin/media/css/datatables-bootstrap3.css');
require('bootstrap');

$(document).ready(function () {
$('#dataset-table').DataTable({
Expand All @@ -13,5 +14,6 @@ $(document).ready(function () {
]
});
$('#dataset-table_info').remove();
//$('input[type=search]').addClass('form-control'); # TODO get search box to look nice
$('#dataset-table').show();
});
5 changes: 4 additions & 1 deletion panoramix/bin/panoramix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ from subprocess import Popen
from flask.ext.script import Manager
from panoramix import app
from flask.ext.migrate import MigrateCommand
import panoramix
from panoramix import db
from panoramix import data, utils

Expand Down Expand Up @@ -49,7 +50,7 @@ def runserver(debug, port, timeout, workers):
@manager.command
def init():
"""Inits the Panoramix application"""
utils.init()
utils.init(panoramix)

@manager.option(
'-s', '--sample', action='store_true',
Expand All @@ -58,6 +59,8 @@ def load_examples(sample):
"""Loads a set of Slices and Dashboards and a supporting dataset """
print("Loading examples into {}".format(db))

data.load_css_templates()

print("Loading [World Bank's Health Nutrition and Population Stats]")
data.load_world_bank_health_n_pop()

Expand Down
6 changes: 3 additions & 3 deletions panoramix/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# ---------------------------------------------------------

# Your App secret key
SECRET_KEY = '\2\1thisismyscretkey\1\2\e\y\y\h'
SECRET_KEY = '\2\1thisismyscretkey\1\2\e\y\y\h' # noqa

# The SQLAlchemy connection string.
SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/panoramix.db'
Expand All @@ -48,7 +48,7 @@
APP_NAME = "Panoramix"

# Uncomment to setup Setup an App icon
APP_ICON = "/static/img/chaudron_white.png"
# APP_ICON = "/static/img/something.png"

# Druid query timezone
# tz.tzutc() : Using utc timezone
Expand Down Expand Up @@ -113,6 +113,6 @@
# IMG_SIZE = (300, 200, True)

try:
from panoramix_config import *
from panoramix_config import * # noqa
except Exception:
pass
64 changes: 35 additions & 29 deletions panoramix/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,33 +274,14 @@ def load_world_bank_health_n_pop():
dash = Dash(
dashboard_title=dash_name,
position_json=json.dumps(l, indent=4),
slug="world_health",
)
for s in slices:
dash.slices.append(s)
db.session.commit()


def load_birth_names():
session = db.session
with gzip.open(os.path.join(DATA_FOLDER, 'birth_names.json.gz')) as f:
pdf = pd.read_json(f)
pdf.ds = pd.to_datetime(pdf.ds, unit='ms')
pdf.to_sql(
'birth_names',
db.engine,
if_exists='replace',
chunksize=500,
dtype={
'ds': DateTime,
'gender': String(16),
'state': String(10),
'name': String(255),
},
index=False)
l = []
print("Done loading table!")
print("-" * 80)

def load_css_templates():
print('Creating default CSS templates')
CSS = models.CssTemplate

Expand Down Expand Up @@ -400,6 +381,27 @@ def load_birth_names():
db.session.merge(obj)
db.session.commit()


def load_birth_names():
with gzip.open(os.path.join(DATA_FOLDER, 'birth_names.json.gz')) as f:
pdf = pd.read_json(f)
pdf.ds = pd.to_datetime(pdf.ds, unit='ms')
pdf.to_sql(
'birth_names',
db.engine,
if_exists='replace',
chunksize=500,
dtype={
'ds': DateTime,
'gender': String(16),
'state': String(10),
'name': String(255),
},
index=False)
l = []
print("Done loading table!")
print("-" * 80)

print("Creating table reference")
obj = db.session.query(TBL).filter_by(table_name='birth_names').first()
if not obj:
Expand Down Expand Up @@ -500,12 +502,15 @@ def load_birth_names():
defaults,
viz_type="markup", markup_type="html",
code="""\
<div style="text-align:center">
<h1>Birth Names Dashboard</h1>
<p>The source dataset came from <a href="https://github.com/hadley/babynames">[here]</a></p>
<img src="http://monblog.system-linux.net/image/tux/baby-tux_overlord59-tux.png">
</div>
"""
<div style="text-align:center">
<h1>Birth Names Dashboard</h1>
<p>
The source dataset came from
<a href="https://github.com/hadley/babynames">[here]</a>
</p>
<img src="http://monblog.system-linux.net/image/tux/baby-tux_overlord59-tux.png">
</div>
"""
)),
Slice(
slice_name="Name Cloud",
Expand All @@ -531,7 +536,7 @@ def load_birth_names():
merge_slice(slc)

print("Creating a dashboard")
dash = session.query(Dash).filter_by(dashboard_title="Births").first()
dash = db.session.query(Dash).filter_by(dashboard_title="Births").first()

if dash:
db.session.delete(dash)
Expand Down Expand Up @@ -608,7 +613,8 @@ def load_birth_names():
dash = Dash(
dashboard_title="Births",
position_json=json.dumps(l, indent=4),
slug="births",
)
for s in slices:
dash.slices.append(s)
session.commit()
db.session.commit()
4 changes: 4 additions & 0 deletions panoramix/data/countries.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
This module contains data related to countries and is used for geo mapping
"""

countries = [
{
"name": "Angola",
Expand Down
Loading

0 comments on commit 27fb810

Please sign in to comment.