17#include <nlohmann/json.hpp>
28nlohmann::json
get(
const nlohmann::json &j,
const std::string &key);
36template <
class T>
bool get_to(
const nlohmann::json &j,
const std::string &key, T &out)
noexcept {
38 out = j.at(key).get<T>();
40 }
catch (
const nlohmann::json::out_of_range &) {
41 fmt::print(fg(fmt::color::red),
"Missing key \"{}\"\n", key);
43 }
catch (
const nlohmann::json::type_error &) {
44 fmt::print(fg(fmt::color::red),
"Key \"{}\" is of wrong type\n", key);
57bool get_to(
const nlohmann::json &j,
const std::string &key, T &out,
bool &success)
noexcept {
58 const bool ret =
get_to(j, key, out);
69void rebase_valid_path(std::filesystem::path &path,
const std::filesystem::path &base_dir);
78 std::filesystem::path &out,
79 const std::filesystem::path &base_dir)
noexcept;
88 std::filesystem::path &out,
const std::filesystem::path &base_dir,
89 bool &success)
noexcept;
96FileInfo
get_file_info(
const nlohmann::json &node,
const std::filesystem::path &base_dir);
109BaselineInfo
get_baseline_info(
const nlohmann::json &j,
const std::filesystem::path &base_dir);
119 if (!opt.contains(
"project_requirements")) {
122 if (opt.contains(
"trend_type") || opt.contains(
"income_categories")) {
124 "Deprecated root-level trend_type and/or income_categories are not allowed when "
125 "project_requirements is present. Use project_requirements.trend and "
126 "project_requirements.income.categories instead."};
131 if (trend_type !=
"null" && trend_type !=
"trend" && trend_type !=
"upf_trend" &&
132 trend_type !=
"UPFTrend" && trend_type !=
"income_trend") {
133 throw ConfigurationError{fmt::format(
"Invalid trend_type: {}. Must be one of: null, trend, "
134 "upf_trend, UPFTrend, income_trend",
141 if (opt.contains(
"trend_type")) {
142 const auto trend_type = opt[
"trend_type"].get<std::string>();
147 if (opt.contains(
"income_categories")) {
148 const auto categories = opt[
"income_categories"].get<std::string>();
156 const auto &d = pr[
"demographics"];
161 if (d.contains(
"max_age_for_linear_models") && !d[
"max_age_for_linear_models"].is_null()) {
164 if (d.contains(
"gender2") && !d[
"gender2"].is_null()) {
167 const auto &inc = pr[
"income"];
169 req.
income.
type = inc[
"type"].get<std::string>();
173 if (inc.contains(
"income_based_csv_output")) {
176 const auto &pa = pr[
"physical_activity"];
181 const auto &rf = pr[
"risk_factors"];
184 const auto &tr = pr[
"trend"];
186 req.
trend.
type = tr[
"type"].get<std::string>();
187 const auto &ts = pr[
"two_stage"];
189 if (ts.contains(
"logistic_file") && !ts[
"logistic_file"].is_null()) {
Main header file for functionality related to loading config files.
IncomeCategoryLayout income_category_layout_from_config(std::string_view categories)
Parse project_requirements.income.categories ("3", "4", or "5").
Definition income_category_layout.cpp:19