Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic time granularity on any datetime column #181

Merged
merged 2 commits into from Mar 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
*.pyc
babel
.DS_Store
.coverage
_build
Expand Down
22 changes: 22 additions & 0 deletions .landscape.yml
@@ -0,0 +1,22 @@
doc-warnings: yes
test-warnings: no
strictness: medium
max-line-length: 90
uses:
- flask
autodetect: yes
pylint:
disable:
- cyclic-import
options:
docstring-min-length: 10
ignore-paths:
- docs
- panoramix/migrations/env.py
- panoramix/ascii_art.py
ignore-patterns:
- ^example/doc_.*\.py$
- (^|/)docs(/|$)
python-targets:
- 2
- 3
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
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
@@ -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
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
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
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()
42 changes: 23 additions & 19 deletions panoramix/data/countries.py
@@ -1,3 +1,7 @@
"""
This module contains data related to countries and is used for geo mapping
"""

countries = [
{
"name": "Angola",
Expand Down Expand Up @@ -490,11 +494,11 @@
"cca3": "THA"
},
{
"name": "S\u00e3o Tom\u00e9 and Pr\u00edncipe",
"name": "Sao Tome and Principe",
"area": 964,
"cioc": "STP",
"cca2": "ST",
"capital": "S\u00e3o Tom\u00e9",
"capital": "Sao Tome",
"lat": 1,
"lng": 7,
"cca3": "STP"
Expand Down Expand Up @@ -684,7 +688,7 @@
"area": 4167,
"cioc": "",
"cca2": "PF",
"capital": u"Papeet\u0113",
"capital": "Papeete",
"lat": -15,
"lng": -140,
"cca3": "PYF"
Expand Down Expand Up @@ -754,7 +758,7 @@
"area": 56785,
"cioc": "TOG",
"cca2": "TG",
"capital": u"Lom\u00e9",
"capital": "Lome",
"lat": 8,
"lng": 1.16666666,
"cca3": "TGO"
Expand All @@ -774,7 +778,7 @@
"area": 549,
"cioc": "GUM",
"cca2": "GU",
"capital": u"Hag\u00e5t\u00f1a",
"capital": "Hagatna",
"lat": 13.46666666,
"lng": 144.78333333,
"cca3": "GUM"
Expand Down Expand Up @@ -834,7 +838,7 @@
"area": 51100,
"cioc": "CRC",
"cca2": "CR",
"capital": u"San Jos\u00e9",
"capital": "San Jose",
"lat": 10,
"lng": -84,
"cca3": "CRI"
Expand All @@ -844,7 +848,7 @@
"area": 475442,
"cioc": "CMR",
"cca2": "CM",
"capital": u"Yaound\u00e9",
"capital": "Yaounde",
"lat": 6,
"lng": 12,
"cca3": "CMR"
Expand Down Expand Up @@ -1070,7 +1074,7 @@
"cca3": "BLR"
},
{
"name": u"Saint Barth\u00e9lemy",
"name": "Saint Barthelemy",
"area": 21,
"cioc": "",
"cca2": "BL",
Expand Down Expand Up @@ -1274,7 +1278,7 @@
"area": 7747,
"cioc": "",
"cca2": "TF",
"capital": u"Port-aux-Fran\u00e7ais",
"capital": "Port-aux-Francais",
"lat": -49.25,
"lng": 69.167,
"cca3": "ATF"
Expand Down Expand Up @@ -1380,7 +1384,7 @@
"cca3": "PER"
},
{
"name": u"R\u00e9union",
"name": "Reunion",
"area": 2511,
"cioc": "",
"cca2": "RE",
Expand Down Expand Up @@ -1484,7 +1488,7 @@
"area": 1141748,
"cioc": "COL",
"cca2": "CO",
"capital": u"Bogot\u00e1",
"capital": "Bogota",
"lat": 4,
"lng": -72,
"cca3": "COL"
Expand Down Expand Up @@ -1534,7 +1538,7 @@
"area": 33846,
"cioc": "MDA",
"cca2": "MD",
"capital": u"Chi\u0219in\u0103u",
"capital": "Chisinau",
"lat": 47,
"lng": 29,
"cca3": "MDA"
Expand Down Expand Up @@ -1594,7 +1598,7 @@
"area": 300,
"cioc": "MDV",
"cca2": "MV",
"capital": u"Mal\u00e9",
"capital": "Male",
"lat": 3.25,
"lng": 73,
"cca3": "MDV"
Expand All @@ -1620,7 +1624,7 @@
"cca3": "SPM"
},
{
"name": u"Cura\u00e7ao",
"name": "Curacao",
"area": 444,
"cioc": "",
"cca2": "CW",
Expand Down Expand Up @@ -1704,7 +1708,7 @@
"area": 1393,
"cioc": "",
"cca2": "FO",
"capital": u"T\u00f3rshavn",
"capital": "Torshavn",
"lat": 62,
"lng": -7,
"cca3": "FRO"
Expand Down Expand Up @@ -1860,7 +1864,7 @@
"cca3": "TUV"
},
{
"name": u"\u00c5land Islands",
"name": "Aland Islands",
"area": 1580,
"cioc": "",
"cca2": "AX",
Expand Down Expand Up @@ -1914,7 +1918,7 @@
"area": 8515767,
"cioc": "BRA",
"cca2": "BR",
"capital": u"Bras\u00edlia",
"capital": "Brasilia",
"lat": -10,
"lng": -55,
"cca3": "BRA"
Expand Down Expand Up @@ -2334,7 +2338,7 @@
"area": 266000,
"cioc": "",
"cca2": "EH",
"capital": u"El Aai\u00fan",
"capital": "El Aaiun",
"lat": 24.5,
"lng": -13,
"cca3": "ESH"
Expand Down Expand Up @@ -2394,7 +2398,7 @@
"area": 18575,
"cioc": "",
"cca2": "NC",
"capital": u"Noum\u00e9a",
"capital": "Noumea",
"lat": -21.5,
"lng": 165.5,
"cca3": "NCL"
Expand Down