mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
More docstrings
This commit is contained in:
parent
ebf55bf20d
commit
1c9c154f0f
@ -8,8 +8,11 @@ autodetect: yes
|
|||||||
pylint:
|
pylint:
|
||||||
disable:
|
disable:
|
||||||
- cyclic-import
|
- cyclic-import
|
||||||
|
- invalid-name
|
||||||
options:
|
options:
|
||||||
docstring-min-length: 10
|
docstring-min-length: 10
|
||||||
|
pep8:
|
||||||
|
full: true
|
||||||
ignore-paths:
|
ignore-paths:
|
||||||
- docs
|
- docs
|
||||||
- panoramix/migrations/env.py
|
- panoramix/migrations/env.py
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
"""Package's main module!"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from flask import Flask, redirect
|
from flask import Flask, redirect
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
"""Loads datasets, dashboards and slices in a new panoramix instance"""
|
||||||
|
|
||||||
import gzip
|
import gzip
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
@ -46,6 +48,7 @@ def get_slice_json(defaults, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
def load_world_bank_health_n_pop():
|
def load_world_bank_health_n_pop():
|
||||||
|
"""Loads the world bank health dataset, slices and a dashboard"""
|
||||||
tbl_name = 'wb_health_population'
|
tbl_name = 'wb_health_population'
|
||||||
with gzip.open(os.path.join(DATA_FOLDER, 'countries.json.gz')) as f:
|
with gzip.open(os.path.join(DATA_FOLDER, 'countries.json.gz')) as f:
|
||||||
pdf = pd.read_json(f)
|
pdf = pd.read_json(f)
|
||||||
@ -282,6 +285,7 @@ def load_world_bank_health_n_pop():
|
|||||||
|
|
||||||
|
|
||||||
def load_css_templates():
|
def load_css_templates():
|
||||||
|
"""Loads 2 css templates to demonstrate the feature"""
|
||||||
print('Creating default CSS templates')
|
print('Creating default CSS templates')
|
||||||
CSS = models.CssTemplate
|
CSS = models.CssTemplate
|
||||||
|
|
||||||
|
@ -493,6 +493,7 @@ class FormFactory(object):
|
|||||||
return [("{}".format(obj), "{}".format(obj)) for obj in l]
|
return [("{}".format(obj), "{}".format(obj)) for obj in l]
|
||||||
|
|
||||||
def get_form(self):
|
def get_form(self):
|
||||||
|
"""Returns a form object based on the viz/datasource/context"""
|
||||||
viz = self.viz
|
viz = self.viz
|
||||||
field_css_classes = {}
|
field_css_classes = {}
|
||||||
for name, obj in self.field_dict.items():
|
for name, obj in self.field_dict.items():
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
"""
|
||||||
|
A collection of ORM sqlalchemy models for Panoramix
|
||||||
|
"""
|
||||||
|
|
||||||
from copy import deepcopy, copy
|
from copy import deepcopy, copy
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from datetime import timedelta, datetime
|
from datetime import timedelta, datetime
|
||||||
@ -37,8 +41,10 @@ QueryResult = namedtuple('namedtuple', ['df', 'query', 'duration'])
|
|||||||
|
|
||||||
class AuditMixinNullable(AuditMixin):
|
class AuditMixinNullable(AuditMixin):
|
||||||
|
|
||||||
"""Altering the AuditMixin to use nullable fields, allows creating
|
"""Altering the AuditMixin to use nullable fields
|
||||||
objects programmatically outside of CRUD"""
|
|
||||||
|
Allows creating objects programmatically outside of CRUD
|
||||||
|
"""
|
||||||
|
|
||||||
created_on = Column(DateTime, default=datetime.now, nullable=True)
|
created_on = Column(DateTime, default=datetime.now, nullable=True)
|
||||||
changed_on = Column(
|
changed_on = Column(
|
||||||
@ -223,6 +229,7 @@ class Dashboard(Model, AuditMixinNullable):
|
|||||||
|
|
||||||
|
|
||||||
class Queryable(object):
|
class Queryable(object):
|
||||||
|
"""A common interface to objects that are queryable (tables and datasources)"""
|
||||||
@property
|
@property
|
||||||
def column_names(self):
|
def column_names(self):
|
||||||
return sorted([c.column_name for c in self.columns])
|
return sorted([c.column_name for c in self.columns])
|
||||||
@ -837,8 +844,7 @@ class DruidDatasource(Model, AuditMixinNullable, Queryable):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def sync_to_db(cls, name, cluster):
|
def sync_to_db(cls, name, cluster):
|
||||||
"""Fetches the metadata for that datasource and merges it into
|
"""Fetches metadata for that datasource and merges the Panoramix db"""
|
||||||
the Panoramix database"""
|
|
||||||
print("Syncing Druid datasource [{}]".format(name))
|
print("Syncing Druid datasource [{}]".format(name))
|
||||||
session = get_session()
|
session = get_session()
|
||||||
datasource = session.query(cls).filter_by(datasource_name=name).first()
|
datasource = session.query(cls).filter_by(datasource_name=name).first()
|
||||||
@ -884,7 +890,9 @@ class DruidDatasource(Model, AuditMixinNullable, Queryable):
|
|||||||
extras=None, # noqa
|
extras=None, # noqa
|
||||||
select=None):
|
select=None):
|
||||||
"""Runs a query against Druid and returns a dataframe.
|
"""Runs a query against Druid and returns a dataframe.
|
||||||
This query interface is common to SqlAlchemy and Druid"""
|
|
||||||
|
This query interface is common to SqlAlchemy and Druid
|
||||||
|
"""
|
||||||
# TODO refactor into using a TBD Query object
|
# TODO refactor into using a TBD Query object
|
||||||
qry_start_dttm = datetime.now()
|
qry_start_dttm = datetime.now()
|
||||||
|
|
||||||
|
@ -365,6 +365,7 @@ appbuilder.add_view_no_menu(R)
|
|||||||
|
|
||||||
|
|
||||||
class Panoramix(BaseView):
|
class Panoramix(BaseView):
|
||||||
|
|
||||||
"""The base views for Panoramix!"""
|
"""The base views for Panoramix!"""
|
||||||
|
|
||||||
@has_access
|
@has_access
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
"""
|
||||||
|
This module contains the "Viz" objects that represent the backend of all
|
||||||
|
the visualizations that Panoramix can render
|
||||||
|
"""
|
||||||
|
|
||||||
from collections import OrderedDict, defaultdict
|
from collections import OrderedDict, defaultdict
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import json
|
import json
|
||||||
@ -19,6 +24,9 @@ config = app.config
|
|||||||
|
|
||||||
|
|
||||||
class BaseViz(object):
|
class BaseViz(object):
|
||||||
|
|
||||||
|
"""All visualizations derive this base class"""
|
||||||
|
|
||||||
viz_type = None
|
viz_type = None
|
||||||
verbose_name = "Base Viz"
|
verbose_name = "Base Viz"
|
||||||
is_timeseries = False
|
is_timeseries = False
|
||||||
@ -110,12 +118,14 @@ class BaseViz(object):
|
|||||||
return href(d)
|
return href(d)
|
||||||
|
|
||||||
def get_df(self, query_obj=None):
|
def get_df(self, query_obj=None):
|
||||||
|
"""Returns a pandas dataframe based on the query object"""
|
||||||
if not query_obj:
|
if not query_obj:
|
||||||
query_obj = self.query_obj()
|
query_obj = self.query_obj()
|
||||||
|
|
||||||
self.error_msg = ""
|
self.error_msg = ""
|
||||||
self.results = None
|
self.results = None
|
||||||
|
|
||||||
|
# The datasource here can be different backend but the interface is common
|
||||||
self.results = self.datasource.query(**query_obj)
|
self.results = self.datasource.query(**query_obj)
|
||||||
self.query = self.results.query
|
self.query = self.results.query
|
||||||
df = self.results.df
|
df = self.results.df
|
||||||
@ -138,6 +148,7 @@ class BaseViz(object):
|
|||||||
return FormFactory(self).get_form()
|
return FormFactory(self).get_form()
|
||||||
|
|
||||||
def query_filters(self):
|
def query_filters(self):
|
||||||
|
"""Processes the filters for the query"""
|
||||||
form_data = self.form_data
|
form_data = self.form_data
|
||||||
# Building filters
|
# Building filters
|
||||||
filters = []
|
filters = []
|
||||||
@ -159,9 +170,7 @@ class BaseViz(object):
|
|||||||
return filters
|
return filters
|
||||||
|
|
||||||
def query_obj(self):
|
def query_obj(self):
|
||||||
"""
|
"""Building a query object"""
|
||||||
Building a query object
|
|
||||||
"""
|
|
||||||
form_data = self.form_data
|
form_data = self.form_data
|
||||||
groupby = form_data.get("groupby") or []
|
groupby = form_data.get("groupby") or []
|
||||||
metrics = form_data.get("metrics") or ['count']
|
metrics = form_data.get("metrics") or ['count']
|
||||||
@ -387,10 +396,12 @@ class MarkupViz(BaseViz):
|
|||||||
|
|
||||||
|
|
||||||
class WordCloudViz(BaseViz):
|
class WordCloudViz(BaseViz):
|
||||||
"""
|
|
||||||
Integration with the nice library at:
|
"""Integration with the nice library at:
|
||||||
|
|
||||||
https://github.com/jasondavies/d3-cloud
|
https://github.com/jasondavies/d3-cloud
|
||||||
"""
|
"""
|
||||||
|
|
||||||
viz_type = "word_cloud"
|
viz_type = "word_cloud"
|
||||||
verbose_name = "Word Cloud"
|
verbose_name = "Word Cloud"
|
||||||
is_timeseries = False
|
is_timeseries = False
|
||||||
@ -421,12 +432,18 @@ class WordCloudViz(BaseViz):
|
|||||||
|
|
||||||
|
|
||||||
class NVD3Viz(BaseViz):
|
class NVD3Viz(BaseViz):
|
||||||
|
|
||||||
|
"""Base class for all nvd3 vizs"""
|
||||||
|
|
||||||
viz_type = None
|
viz_type = None
|
||||||
verbose_name = "Base NVD3 Viz"
|
verbose_name = "Base NVD3 Viz"
|
||||||
is_timeseries = False
|
is_timeseries = False
|
||||||
|
|
||||||
|
|
||||||
class BubbleViz(NVD3Viz):
|
class BubbleViz(NVD3Viz):
|
||||||
|
|
||||||
|
"""Based on the NVD3 bubble chart"""
|
||||||
|
|
||||||
viz_type = "bubble"
|
viz_type = "bubble"
|
||||||
verbose_name = "Bubble Chart"
|
verbose_name = "Bubble Chart"
|
||||||
is_timeseries = False
|
is_timeseries = False
|
||||||
|
Loading…
Reference in New Issue
Block a user