1. 程式人生 > >kylin 開源視覺化工具 superset使用

kylin 開源視覺化工具 superset使用

superset + kylin

1.superset 和kylin 連線問題
使用kylinpy
pip install kylinpy

在kylin.py 增加解決下拉列表問題

@compact_response()
    def list_schemas(self):
        table_schemas = [t['table_SCHEM'] for t in self.tables_and_columns()['data']]
        table_schemas = list(set(table_schemas))
        return
table_schemas

在sqla_dialect 中增加

    def get_schema_names(self, connection, schema=None, **kw):
        conn = connection.connect()
        return conn.connection.connection.list_schemas().get('data')

2.匯出字元編碼問題

CSV_EXPORT = {
    'encoding': 'utf-8-sig',
}

vim views/core.py

response = Response(csv.encode('utf-8-sig'
), mimetype='text/csv')

3.測試連線是報錯可以是編碼問題
修改 kylin.py 中

dumps = json.loads(fd.read().decode("utf-8"))

4.superset 中中文地圖問題

./static/assets/visualizations/countries/china.geojson

修改 NAME_1 為中文省名
修改 ISO 對應與sql中的省名稱標示

4 superset 0.25.6

NVD3DualLineViz
unhashable type: ‘dict’

vim viz.py

 def to_series
(self, df, classed=''):
cols = [] for col in df.columns: if col == '': cols.append('N/A') elif col is None: cols.append('NULL') else: cols.append(col) df.columns = cols series = df.to_dict('series') chart_data = [] metric = self.form_data.get('metric') metric_2 = self.form_data.get('metric_2') if isinstance(metric, dict): metric = str(metric['label']) else: metric = metric metrics = [ metric, metric_2, ]
def get_data(self, df):
    fd = self.form_data
    df = df.fillna(0)

    if self.form_data.get('granularity') == 'all':
        raise Exception(_('Pick a time granularity for your time series'))

    metric = fd.get('metric')

    if isinstance(metric, dict):
        metric = str(metric['label'])
    else:
        metric = metric

    metric_2 = fd.get('metric_2')
    df = df.pivot_table(
        index=DTTM_ALIAS,
        values=[metric, metric_2])

    chart_data = self.to_series(df)
    return chart_data
    ```

[1] : http://kylin.apache.org/
[2] : http://superset.apache.org/