move plot declarations to app config

This commit is contained in:
crflynn
2018-08-13 22:06:47 -04:00
parent 7fcf0e361e
commit 75808d6d20
2 changed files with 12 additions and 11 deletions

View File

@@ -2,6 +2,7 @@
import os
from celery.schedules import crontab
from flask import json
def get_db_uri(env):
@@ -34,6 +35,15 @@ class Config(object):
SECRET_KEY = os.environ.get("PYPISTATS_SECRET", "secret-key")
SQLALCHEMY_TRACK_MODIFICATIONS = False
# Plotly chart definitions
PLOT_BASE = json.load(
open(os.path.join(os.path.dirname(__file__), "plots", "plot_base.json"))
)
DATA_BASE = json.load(
open(os.path.join(os.path.dirname(__file__), "plots", "data_base.json"))
)
class ProdConfig(Config):
"""Production configuration."""

View File

@@ -33,15 +33,6 @@ MODELS = [
]
# Plotly chart definitions
PLOT_BASE = json.load(
open(os.path.join(current_app.root_path, 'plots', 'plot_base.json'))
)
DATA_BASE = json.load(
open(os.path.join(current_app.root_path, 'plots', 'data_base.json'))
)
class MyForm(FlaskForm):
"""Search form."""
@@ -128,10 +119,10 @@ def package(package):
# Build the plots
plots = []
for model in model_data:
plot = deepcopy(PLOT_BASE)
plot = deepcopy(current_app.config["PLOT_BASE"])
data = []
for category, values in model["data"].items():
base = deepcopy(DATA_BASE["data"][0])
base = deepcopy(current_app.config["DATA_BASE"]["data"][0])
base["x"] = values["x"]
base["y"] = values["y"]
base["name"] = category.title()