1 # Copyright (c) 2024 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """Initialize Flask app.
20 from flask import Flask
21 from flask_assets import Environment, Bundle
23 from .utils.constants import Constants as C
24 from .data.data import Data
28 """Construct core Flask application with embedded Dash app.
33 datefmt=C.LOG_DATE_FORMAT,
37 app = Flask(__name__, instance_relative_config=False)
38 app.logger.info("Application started.")
39 app.config.from_object("config.Config")
41 with app.app_context():
42 # Import parts of our core Flask app.
45 assets = Environment()
48 # Compile static assets.
52 output="dist/css/bootstrap.css",
58 assets.register("sass_all", sass_bundle)
61 if C.TIME_PERIOD is None or C.TIME_PERIOD > C.MAX_TIME_PERIOD:
62 time_period = C.MAX_TIME_PERIOD
64 time_period = C.TIME_PERIOD
67 data_spec_file=C.DATA_SPEC_FILE,
68 ).read_all_data(days=time_period)
70 # Import Dash applications.
71 err_msg = "Application not loaded, no data available."
72 logging.info("\n\nStarting the applications:\n" + "-" * 26 + "\n")
75 logging.info(C.NEWS_TITLE)
76 if data["statistics"].empty or data["trending"].empty:
77 logging.error(err_msg)
79 from .news.news import init_news
80 app = init_news(app, data["statistics"], data["trending"])
81 if C.START_STATISTICS:
82 logging.info(C.STATS_TITLE)
83 if data["statistics"].empty or data["trending"].empty:
84 logging.error(err_msg)
86 from .stats.stats import init_stats
87 app = init_stats(app, data["statistics"], data["trending"])
89 logging.info(C.TREND_TITLE)
90 if data["trending"].empty:
91 logging.error(err_msg)
93 from .trending.trending import init_trending
94 app = init_trending(app, data["trending"])
96 logging.info(C.REPORT_TITLE)
97 if data["iterative"].empty:
98 logging.error(err_msg)
100 from .report.report import init_report
101 app = init_report(app, data["iterative"])
102 if C.START_COMPARISONS:
103 logging.info(C.COMP_TITLE)
104 if data["iterative"].empty:
105 logging.error(err_msg)
107 from .comparisons.comparisons import init_comparisons
108 app = init_comparisons(app, data["iterative"])
110 logging.info(C.COVERAGE_TITLE)
111 if data["coverage"].empty:
112 logging.error(err_msg)
114 from .coverage.coverage import init_coverage
115 app = init_coverage(app, data["coverage"])
117 logging.info(C.SEARCH_TITLE)
118 if all((data["trending"].empty, data["iterative"].empty,
119 data["coverage"].empty)):
120 logging.error(err_msg)
122 from .search.search import init_search
123 app = init_search(app, data)