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.
32 datefmt=C.LOG_DATE_FORMAT,
36 app = Flask(__name__, instance_relative_config=False)
37 app.logger.info("Application started.")
38 app.config.from_object("config.Config")
40 with app.app_context():
41 # Import parts of our core Flask app.
44 assets = Environment()
47 # Compile static assets.
51 output="dist/css/bootstrap.css",
57 assets.register("sass_all", sass_bundle)
60 if C.TIME_PERIOD is None or C.TIME_PERIOD > C.MAX_TIME_PERIOD:
61 time_period = C.MAX_TIME_PERIOD
63 time_period = C.TIME_PERIOD
66 data_spec_file=C.DATA_SPEC_FILE,
67 ).read_all_data(days=time_period)
69 # Import Dash applications.
70 logging.info("\n\nStarting the applications:\n" + "-" * 26 + "\n")
71 if data["statistics"].empty or data["trending"].empty:
73 f'"{C.NEWS_TITLE}" application not loaded, no data available.'
76 f'"{C.STATS_TITLE}" application not loaded, no data available.'
79 logging.info(C.NEWS_TITLE)
80 from .news.news import init_news
83 data_stats=data["statistics"],
84 data_trending=data["trending"]
87 logging.info(C.STATS_TITLE)
88 from .stats.stats import init_stats
91 data_stats=data["statistics"],
92 data_trending=data["trending"]
95 if data["trending"].empty:
97 f'"{C.TREND_TITLE}" application not loaded, no data available.'
100 logging.info(C.TREND_TITLE)
101 from .trending.trending import init_trending
102 app = init_trending(app, data_trending=data["trending"])
104 if data["iterative"].empty:
106 f'"{C.REPORT_TITLE}" application not loaded, no data available.'
109 f'"{C.COMP_TITLE}" application not loaded, no data available.'
112 logging.info(C.REPORT_TITLE)
113 from .report.report import init_report
114 app = init_report(app, data_iterative=data["iterative"])
116 logging.info(C.COMP_TITLE)
117 from .comparisons.comparisons import init_comparisons
118 app = init_comparisons(app, data_iterative=data["iterative"])
120 if data["coverage"].empty:
122 f'"{C.COVERAGE_TITLE}" application not loaded, '
126 logging.info(C.COVERAGE_TITLE)
127 from .coverage.coverage import init_coverage
128 app = init_coverage(app, data_coverage=data["coverage"])
130 if all((data["trending"].empty, data["iterative"].empty,
131 data["coverage"].empty)):
133 f'"{C.SEARCH_TITLE}" application not loaded, '
137 logging.info(C.SEARCH_TITLE)
138 from .search.search import init_search
139 app = init_search(app, data)