2015-12-22 18:35:06 -05:00
|
|
|
import gzip
|
2015-12-22 23:24:33 -05:00
|
|
|
import json
|
2015-12-22 18:35:06 -05:00
|
|
|
import os
|
2015-12-22 23:24:33 -05:00
|
|
|
|
|
|
|
import pandas as pd
|
2016-01-11 23:53:20 -05:00
|
|
|
from sqlalchemy import String, DateTime
|
2015-12-22 23:24:33 -05:00
|
|
|
|
2016-01-11 23:53:20 -05:00
|
|
|
from panoramix import app, db, models, utils
|
2015-12-22 18:35:06 -05:00
|
|
|
|
2016-01-13 20:05:11 -05:00
|
|
|
# Shortcuts
|
|
|
|
DB = models.Database
|
|
|
|
Slice = models.Slice
|
|
|
|
TBL = models.SqlaTable
|
|
|
|
Dash = models.Dashboard
|
|
|
|
|
2015-12-22 18:35:06 -05:00
|
|
|
config = app.config
|
|
|
|
|
|
|
|
DATA_FOLDER = os.path.join(config.get("BASE_DIR"), 'data')
|
|
|
|
|
|
|
|
|
2015-12-23 01:43:42 -05:00
|
|
|
def get_or_create_db(session):
|
|
|
|
print("Creating database reference")
|
|
|
|
dbobj = session.query(DB).filter_by(database_name='main').first()
|
|
|
|
if not dbobj:
|
|
|
|
dbobj = DB(database_name="main")
|
|
|
|
print(config.get("SQLALCHEMY_DATABASE_URI"))
|
|
|
|
dbobj.sqlalchemy_uri = config.get("SQLALCHEMY_DATABASE_URI")
|
|
|
|
session.add(dbobj)
|
|
|
|
session.commit()
|
|
|
|
return dbobj
|
|
|
|
|
|
|
|
|
2016-01-13 20:05:11 -05:00
|
|
|
def merge_slice(slc):
|
|
|
|
o = db.session.query(Slice).filter_by(slice_name=slc.slice_name).first()
|
|
|
|
if o:
|
|
|
|
db.session.delete(o)
|
|
|
|
db.session.add(slc)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
def get_slice_json(defaults, **kwargs):
|
|
|
|
d = defaults.copy()
|
|
|
|
d.update(kwargs)
|
|
|
|
return json.dumps(d, indent=4, sort_keys=True)
|
|
|
|
|
|
|
|
|
2015-12-22 18:35:06 -05:00
|
|
|
def load_world_bank_health_n_pop():
|
2016-01-13 21:16:01 -05:00
|
|
|
tbl_name = 'wb_health_population'
|
2015-12-22 18:35:06 -05:00
|
|
|
with gzip.open(os.path.join(DATA_FOLDER, 'countries.json.gz')) as f:
|
|
|
|
pdf = pd.read_json(f)
|
2016-01-13 21:16:01 -05:00
|
|
|
pdf.columns = [col.replace('.', '_') for col in pdf.columns]
|
2015-12-22 23:24:33 -05:00
|
|
|
pdf.year = pd.to_datetime(pdf.year)
|
2015-12-22 18:35:06 -05:00
|
|
|
pdf.to_sql(
|
2016-01-13 21:16:01 -05:00
|
|
|
tbl_name,
|
2015-12-22 18:35:06 -05:00
|
|
|
db.engine,
|
|
|
|
if_exists='replace',
|
|
|
|
chunksize=500,
|
|
|
|
dtype={
|
|
|
|
'year': DateTime(),
|
|
|
|
'country_code': String(3),
|
|
|
|
'country_name': String(255),
|
|
|
|
'region': String(255),
|
|
|
|
},
|
|
|
|
index=False)
|
2016-01-13 20:05:11 -05:00
|
|
|
|
|
|
|
print("Creating table [wb_health_population] reference")
|
2016-01-13 21:16:01 -05:00
|
|
|
tbl = db.session.query(TBL).filter_by(table_name=tbl_name).first()
|
2016-01-13 20:05:11 -05:00
|
|
|
if not tbl:
|
2016-01-13 21:16:01 -05:00
|
|
|
tbl = TBL(table_name=tbl_name)
|
2016-01-13 20:05:11 -05:00
|
|
|
tbl.description = utils.readfile(os.path.join(DATA_FOLDER, 'countries.md'))
|
|
|
|
tbl.main_dttm_col = 'year'
|
|
|
|
tbl.database = get_or_create_db(db.session)
|
|
|
|
db.session.merge(tbl)
|
|
|
|
db.session.commit()
|
2016-01-13 20:19:12 -05:00
|
|
|
tbl.fetch_metadata()
|
2016-01-13 20:05:11 -05:00
|
|
|
|
|
|
|
defaults = {
|
|
|
|
"compare_lag": "10",
|
|
|
|
"compare_suffix": "o10Y",
|
|
|
|
"datasource_id": "1",
|
|
|
|
"datasource_name": "birth_names",
|
|
|
|
"datasource_type": "table",
|
|
|
|
"limit": "25",
|
|
|
|
"granularity": "year",
|
|
|
|
"groupby": [],
|
2016-01-13 21:16:01 -05:00
|
|
|
"metric": 'sum__SP_POP_TOTL',
|
|
|
|
"metrics": ["sum__SP_POP_TOTL"],
|
2016-01-13 20:05:11 -05:00
|
|
|
"row_limit": config.get("ROW_LIMIT"),
|
|
|
|
"since": "2014-01-01",
|
|
|
|
"until": "2014-01-01",
|
|
|
|
"where": "",
|
|
|
|
"markup_type": "markdown",
|
|
|
|
"country_fieldtype": "cca3",
|
2016-01-13 21:16:01 -05:00
|
|
|
"secondary_metric": "sum__SP_POP_TOTL",
|
2016-01-13 20:05:11 -05:00
|
|
|
"entity": "country_code",
|
|
|
|
"show_bubbles": "y",
|
|
|
|
}
|
|
|
|
|
|
|
|
print("Creating slices")
|
|
|
|
slices = [
|
|
|
|
Slice(
|
|
|
|
slice_name="Region Filter",
|
|
|
|
viz_type='filter_box',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
|
|
|
defaults,
|
|
|
|
viz_type='filter_box',
|
|
|
|
groupby=['region'],
|
|
|
|
)),
|
|
|
|
Slice(
|
|
|
|
slice_name="World's Population",
|
|
|
|
viz_type='big_number',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
|
|
|
defaults,
|
|
|
|
since='2000',
|
|
|
|
viz_type='big_number',
|
|
|
|
compare_lag="10",
|
2016-01-13 21:16:01 -05:00
|
|
|
metric='sum__SP_POP_TOTL',
|
2016-01-13 20:05:11 -05:00
|
|
|
compare_suffix="over 10Y")),
|
|
|
|
Slice(
|
|
|
|
slice_name="Most Populated Countries",
|
|
|
|
viz_type='table',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
|
|
|
defaults,
|
|
|
|
viz_type='table',
|
2016-01-13 21:16:01 -05:00
|
|
|
metrics=["sum__SP_POP_TOTL"],
|
2016-01-13 20:05:11 -05:00
|
|
|
groupby=['country_name'])),
|
|
|
|
Slice(
|
|
|
|
slice_name="Growth Rate",
|
|
|
|
viz_type='line',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
|
|
|
defaults,
|
|
|
|
viz_type='line',
|
|
|
|
since="1960-01-01",
|
2016-01-13 21:16:01 -05:00
|
|
|
metrics=["sum__SP_POP_TOTL"],
|
2016-01-13 20:05:11 -05:00
|
|
|
num_period_compare="10",
|
|
|
|
groupby=['country_name'])),
|
|
|
|
Slice(
|
|
|
|
slice_name="% Rural",
|
|
|
|
viz_type='world_map',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
|
|
|
defaults,
|
|
|
|
viz_type='world_map',
|
2016-01-13 21:16:01 -05:00
|
|
|
metric= "sum__SP_RUR_TOTL_ZS",
|
2016-01-13 20:05:11 -05:00
|
|
|
num_period_compare="10",)),
|
|
|
|
Slice(
|
|
|
|
slice_name="Life Expexctancy VS Rural %",
|
|
|
|
viz_type='bubble',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
|
|
|
defaults,
|
|
|
|
viz_type='bubble',
|
|
|
|
since= "2011-01-01",
|
|
|
|
until= "2011-01-01",
|
|
|
|
series="region",
|
|
|
|
limit="0",
|
|
|
|
entity="country_name",
|
2016-01-13 21:16:01 -05:00
|
|
|
x="sum__SP_RUR_TOTL_ZS",
|
|
|
|
y="sum__SP_DYN_LE00_IN",
|
|
|
|
size="sum__SP_POP_TOTL",
|
2016-01-13 20:05:11 -05:00
|
|
|
max_bubble_size="50",
|
|
|
|
flt_col_1="country_code",
|
|
|
|
flt_op_1= "not in",
|
|
|
|
flt_eq_1="TCA,MNP,DMA,MHL,MCO,SXM,CYM,TUV,IMY,KNA,ASM,ADO,AMA,PLW",
|
|
|
|
num_period_compare="10",)),
|
|
|
|
Slice(
|
|
|
|
slice_name="Rural Breakdown",
|
|
|
|
viz_type='sunburst',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
|
|
|
defaults,
|
|
|
|
viz_type='sunburst',
|
|
|
|
groupby=["region", "country_name"],
|
2016-01-13 21:16:01 -05:00
|
|
|
secondary_metric="sum__SP_RUR_TOTL",
|
2016-01-13 20:05:11 -05:00
|
|
|
since= "2011-01-01",
|
|
|
|
until= "2011-01-01",)),
|
|
|
|
Slice(
|
|
|
|
slice_name="World's Pop Growth",
|
|
|
|
viz_type='area',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
|
|
|
defaults,
|
|
|
|
since="1960-01-01",
|
|
|
|
until="now",
|
|
|
|
viz_type='area',
|
|
|
|
groupby=["region"],)),
|
|
|
|
]
|
|
|
|
for slc in slices:
|
|
|
|
merge_slice(slc)
|
|
|
|
|
|
|
|
print("Creating a World's Health Bank dashboard")
|
|
|
|
dash_name = "World's Health Bank Dashboard"
|
|
|
|
dash = db.session.query(Dash).filter_by(dashboard_title=dash_name).first()
|
|
|
|
|
|
|
|
if dash:
|
|
|
|
db.session.delete(dash)
|
|
|
|
js = """\
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"size_y": 1,
|
|
|
|
"size_x": 3,
|
|
|
|
"col": 1,
|
|
|
|
"slice_id": "269",
|
|
|
|
"row": 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"size_y": 3,
|
|
|
|
"size_x": 3,
|
|
|
|
"col": 1,
|
|
|
|
"slice_id": "270",
|
|
|
|
"row": 2
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"size_y": 7,
|
|
|
|
"size_x": 3,
|
|
|
|
"col": 10,
|
|
|
|
"slice_id": "271",
|
|
|
|
"row": 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"size_y": 3,
|
|
|
|
"size_x": 6,
|
|
|
|
"col": 1,
|
|
|
|
"slice_id": "272",
|
|
|
|
"row": 5
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"size_y": 4,
|
|
|
|
"size_x": 6,
|
|
|
|
"col": 4,
|
|
|
|
"slice_id": "273",
|
|
|
|
"row": 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"size_y": 4,
|
|
|
|
"size_x": 6,
|
|
|
|
"col": 7,
|
|
|
|
"slice_id": "274",
|
|
|
|
"row": 8
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"size_y": 3,
|
|
|
|
"size_x": 3,
|
|
|
|
"col": 7,
|
|
|
|
"slice_id": "275",
|
|
|
|
"row": 5
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"size_y": 4,
|
|
|
|
"size_x": 6,
|
|
|
|
"col": 1,
|
|
|
|
"slice_id": "276",
|
|
|
|
"row": 8
|
|
|
|
}
|
|
|
|
]
|
|
|
|
"""
|
|
|
|
l = json.loads(js)
|
|
|
|
for i, pos in enumerate(l):
|
|
|
|
pos['slice_id'] = str(slices[i].id)
|
|
|
|
dash = Dash(
|
|
|
|
dashboard_title=dash_name,
|
|
|
|
position_json=json.dumps(l, indent=4),
|
|
|
|
)
|
|
|
|
for s in slices:
|
|
|
|
dash.slices.append(s)
|
2015-12-23 01:43:42 -05:00
|
|
|
db.session.commit()
|
2015-12-22 18:35:06 -05:00
|
|
|
|
|
|
|
|
|
|
|
def load_birth_names():
|
2015-12-23 01:43:42 -05:00
|
|
|
session = db.session
|
|
|
|
with gzip.open(os.path.join(DATA_FOLDER, 'birth_names.json.gz')) as f:
|
|
|
|
pdf = pd.read_json(f)
|
2015-12-24 11:39:33 -05:00
|
|
|
pdf.ds = pd.to_datetime(pdf.ds, unit='ms')
|
2015-12-23 01:43:42 -05:00
|
|
|
pdf.to_sql(
|
|
|
|
'birth_names',
|
|
|
|
db.engine,
|
|
|
|
if_exists='replace',
|
|
|
|
chunksize=500,
|
|
|
|
dtype={
|
2015-12-24 11:39:33 -05:00
|
|
|
'ds': DateTime,
|
2015-12-23 01:43:42 -05:00
|
|
|
'gender': String(16),
|
|
|
|
'state': String(10),
|
|
|
|
'name': String(255),
|
|
|
|
},
|
|
|
|
index=False)
|
|
|
|
l = []
|
2015-12-22 18:35:06 -05:00
|
|
|
print("Done loading table!")
|
|
|
|
print("-" * 80)
|
|
|
|
|
|
|
|
print("Creating table reference")
|
2015-12-23 01:43:42 -05:00
|
|
|
obj = db.session.query(TBL).filter_by(table_name='birth_names').first()
|
2015-12-22 18:35:06 -05:00
|
|
|
if not obj:
|
|
|
|
obj = TBL(table_name = 'birth_names')
|
|
|
|
obj.main_dttm_col = 'ds'
|
2015-12-23 01:43:42 -05:00
|
|
|
obj.database = get_or_create_db(db.session)
|
2016-01-11 23:53:20 -05:00
|
|
|
db.session.merge(obj)
|
2015-12-23 01:43:42 -05:00
|
|
|
db.session.commit()
|
2015-12-22 18:35:06 -05:00
|
|
|
obj.fetch_metadata()
|
|
|
|
tbl = obj
|
|
|
|
|
2016-01-13 20:05:11 -05:00
|
|
|
defaults = {
|
|
|
|
"compare_lag": "10",
|
|
|
|
"compare_suffix": "o10Y",
|
|
|
|
"datasource_id": "1",
|
|
|
|
"datasource_name": "birth_names",
|
|
|
|
"datasource_type": "table",
|
|
|
|
"limit": "25",
|
|
|
|
"granularity": "ds",
|
|
|
|
"groupby": [],
|
|
|
|
"metric": 'sum__num',
|
|
|
|
"metrics": ["sum__num"],
|
|
|
|
"row_limit": config.get("ROW_LIMIT"),
|
|
|
|
"since": "100 years",
|
|
|
|
"until": "now",
|
|
|
|
"viz_type": "table",
|
|
|
|
"where": "",
|
|
|
|
"markup_type": "markdown",
|
|
|
|
}
|
|
|
|
|
2015-12-22 18:35:06 -05:00
|
|
|
print("Creating some slices")
|
2016-01-13 20:05:11 -05:00
|
|
|
slices = [
|
2016-01-11 23:53:20 -05:00
|
|
|
Slice(
|
|
|
|
slice_name="Girls",
|
2015-12-22 18:35:06 -05:00
|
|
|
viz_type='table',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
2016-01-13 20:05:11 -05:00
|
|
|
defaults,
|
|
|
|
groupby=['name'], flt_eq_1="girl", row_limit=50)),
|
2016-01-11 23:53:20 -05:00
|
|
|
Slice(
|
|
|
|
slice_name="Boys",
|
2015-12-22 18:35:06 -05:00
|
|
|
viz_type='table',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
2016-01-13 20:05:11 -05:00
|
|
|
defaults,
|
|
|
|
groupby=['name'], flt_eq_1="boy", row_limit=50)),
|
2016-01-11 23:53:20 -05:00
|
|
|
Slice(
|
|
|
|
slice_name="Participants",
|
2015-12-22 18:35:06 -05:00
|
|
|
viz_type='big_number',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
2016-01-13 20:05:11 -05:00
|
|
|
defaults,
|
2016-01-11 23:53:20 -05:00
|
|
|
viz_type="big_number", granularity="ds",
|
2016-01-13 20:05:11 -05:00
|
|
|
compare_lag="5", compare_suffix="over 5Y")),
|
2016-01-11 23:53:20 -05:00
|
|
|
Slice(
|
|
|
|
slice_name="Genders",
|
2015-12-22 18:35:06 -05:00
|
|
|
viz_type='pie',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
2016-01-13 20:05:11 -05:00
|
|
|
defaults,
|
|
|
|
viz_type="pie", groupby=['gender'])),
|
2016-01-11 23:53:20 -05:00
|
|
|
Slice(
|
|
|
|
slice_name="Genders by State",
|
2015-12-22 18:35:06 -05:00
|
|
|
viz_type='dist_bar',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
2016-01-13 20:05:11 -05:00
|
|
|
defaults,
|
2016-01-11 23:53:20 -05:00
|
|
|
flt_eq_1="other", viz_type="dist_bar",
|
2015-12-22 18:35:06 -05:00
|
|
|
metrics=['sum__sum_girls', 'sum__sum_boys'],
|
2016-01-13 20:05:11 -05:00
|
|
|
groupby=['state'], flt_op_1='not in', flt_col_1='state')),
|
2016-01-11 23:53:20 -05:00
|
|
|
Slice(
|
|
|
|
slice_name="Trends",
|
2015-12-22 18:35:06 -05:00
|
|
|
viz_type='line',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
2016-01-13 20:05:11 -05:00
|
|
|
defaults,
|
2016-01-11 23:53:20 -05:00
|
|
|
viz_type="line", groupby=['name'],
|
2016-01-13 20:05:11 -05:00
|
|
|
granularity='ds', rich_tooltip='y', show_legend='y')),
|
2016-01-11 23:53:20 -05:00
|
|
|
Slice(
|
|
|
|
slice_name="Title",
|
2015-12-22 18:35:06 -05:00
|
|
|
viz_type='markup',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
2016-01-13 20:05:11 -05:00
|
|
|
defaults,
|
2016-01-11 23:53:20 -05:00
|
|
|
viz_type="markup", markup_type="html",
|
2016-01-13 20:05:11 -05:00
|
|
|
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>
|
|
|
|
"""
|
|
|
|
)),
|
2016-01-11 23:53:20 -05:00
|
|
|
Slice(
|
|
|
|
slice_name="Name Cloud",
|
2015-12-22 18:35:06 -05:00
|
|
|
viz_type='word_cloud',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
2016-01-13 20:05:11 -05:00
|
|
|
defaults,
|
2016-01-11 23:53:20 -05:00
|
|
|
viz_type="word_cloud", size_from="10",
|
2016-01-11 18:27:00 -05:00
|
|
|
series='name', size_to="70", rotation="square",
|
2016-01-13 20:05:11 -05:00
|
|
|
limit='100')),
|
2016-01-11 23:53:20 -05:00
|
|
|
Slice(
|
|
|
|
slice_name="Pivot Table",
|
2015-12-22 18:35:06 -05:00
|
|
|
viz_type='pivot_table',
|
|
|
|
datasource_type='table',
|
|
|
|
table=tbl,
|
|
|
|
params=get_slice_json(
|
2016-01-13 20:05:11 -05:00
|
|
|
defaults,
|
2016-01-11 23:53:20 -05:00
|
|
|
viz_type="pivot_table", metrics=['sum__num'],
|
2016-01-13 20:05:11 -05:00
|
|
|
groupby=['name'], columns=['state'])),
|
|
|
|
]
|
|
|
|
for slc in slices:
|
|
|
|
merge_slice(slc)
|
2015-12-22 18:35:06 -05:00
|
|
|
|
|
|
|
print("Creating a dashboard")
|
|
|
|
dash = session.query(Dash).filter_by(dashboard_title="Births").first()
|
2016-01-11 23:53:20 -05:00
|
|
|
|
|
|
|
if dash:
|
|
|
|
db.session.delete(dash)
|
|
|
|
js = """
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"size_y": 4,
|
|
|
|
"size_x": 2,
|
|
|
|
"col": 8,
|
|
|
|
"slice_id": "85",
|
|
|
|
"row": 7
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"size_y": 4,
|
|
|
|
"size_x": 2,
|
|
|
|
"col": 10,
|
|
|
|
"slice_id": "86",
|
|
|
|
"row": 7
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"size_y": 2,
|
|
|
|
"size_x": 2,
|
|
|
|
"col": 1,
|
|
|
|
"slice_id": "87",
|
|
|
|
"row": 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"size_y": 2,
|
|
|
|
"size_x": 2,
|
|
|
|
"col": 3,
|
|
|
|
"slice_id": "88",
|
|
|
|
"row": 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"size_y": 3,
|
|
|
|
"size_x": 7,
|
|
|
|
"col": 5,
|
|
|
|
"slice_id": "89",
|
|
|
|
"row": 4
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"size_y": 4,
|
|
|
|
"size_x": 7,
|
|
|
|
"col": 1,
|
|
|
|
"slice_id": "90",
|
|
|
|
"row": 7
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"size_y": 3,
|
|
|
|
"size_x": 3,
|
|
|
|
"col": 9,
|
|
|
|
"slice_id": "91",
|
|
|
|
"row": 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"size_y": 3,
|
|
|
|
"size_x": 4,
|
|
|
|
"col": 5,
|
|
|
|
"slice_id": "92",
|
|
|
|
"row": 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"size_y": 4,
|
|
|
|
"size_x": 4,
|
|
|
|
"col": 1,
|
|
|
|
"slice_id": "93",
|
|
|
|
"row": 3
|
|
|
|
}
|
|
|
|
]
|
|
|
|
"""
|
|
|
|
l = json.loads(js)
|
|
|
|
for i, pos in enumerate(l):
|
|
|
|
pos['slice_id'] = str(slices[i].id)
|
|
|
|
dash = Dash(
|
|
|
|
dashboard_title="Births",
|
|
|
|
position_json=json.dumps(l, indent=4),
|
|
|
|
)
|
2015-12-22 18:35:06 -05:00
|
|
|
for s in slices:
|
|
|
|
dash.slices.append(s)
|
|
|
|
session.commit()
|